01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.axis2;
17:
18: import java.io.IOException;
19: import java.net.HttpURLConnection;
20: import java.util.concurrent.CountDownLatch;
21:
22: import org.apache.axis2.AxisFault;
23: import org.apache.axis2.context.MessageContext;
24: import org.apache.axis2.transport.RequestResponseTransport;
25: import org.apache.commons.logging.Log;
26: import org.apache.commons.logging.LogFactory;
27: import org.apache.geronimo.webservices.WebServiceContainer.Response;
28:
29: public class Axis2RequestResponseTransport implements
30: RequestResponseTransport {
31:
32: private static final Log LOG = LogFactory
33: .getLog(Axis2RequestResponseTransport.class);
34:
35: private Response response;
36:
37: private CountDownLatch responseReadySignal = new CountDownLatch(1);
38:
39: private RequestResponseTransportStatus status = RequestResponseTransportStatus.INITIAL;
40:
41: private AxisFault faultToBeThrownOut = null;
42:
43: private boolean responseWritten;
44:
45: Axis2RequestResponseTransport(Response response) {
46: this .response = response;
47: }
48:
49: public void acknowledgeMessage(MessageContext msgContext)
50: throws AxisFault {
51: LOG.debug("acknowledgeMessage");
52: LOG.debug("Acking one-way request");
53:
54: response.setContentType("text/xml; charset="
55: + msgContext
56: .getProperty("message.character-set-encoding"));
57:
58: response.setStatusCode(HttpURLConnection.HTTP_ACCEPTED);
59: try {
60: response.flushBuffer();
61: } catch (IOException e) {
62: throw new AxisFault("Error sending acknowledgement", e);
63: }
64:
65: signalResponseReady();
66: }
67:
68: public void awaitResponse() throws InterruptedException, AxisFault {
69: LOG.debug("Blocking servlet thread -- awaiting response");
70: status = RequestResponseTransportStatus.WAITING;
71: responseReadySignal.await();
72: if (faultToBeThrownOut != null) {
73: throw faultToBeThrownOut;
74: }
75: }
76:
77: public void signalFaultReady(AxisFault fault) {
78: faultToBeThrownOut = fault;
79: signalResponseReady();
80: }
81:
82: public void signalResponseReady() {
83: LOG.debug("Signalling response available");
84: status = RequestResponseTransportStatus.SIGNALLED;
85: responseReadySignal.countDown();
86: }
87:
88: public RequestResponseTransportStatus getStatus() {
89: return status;
90: }
91:
92: public boolean isResponseWritten() {
93: return responseWritten;
94: }
95:
96: public void setResponseWritten(boolean responseWritten) {
97: this.responseWritten = responseWritten;
98: }
99: }
|