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.openejb.server.axis2;
17:
18: import org.apache.axis2.AxisFault;
19: import org.apache.axis2.context.MessageContext;
20: import org.apache.axis2.transport.RequestResponseTransport;
21: import org.apache.openejb.server.httpd.HttpResponse;
22: import org.apache.openejb.util.Logger;
23: import org.apache.openejb.util.LogCategory;
24:
25: import java.io.IOException;
26: import java.net.HttpURLConnection;
27: import java.util.concurrent.CountDownLatch;
28:
29: public class Axis2RequestResponseTransport implements
30: RequestResponseTransport {
31: private static final Logger logger = Logger.getInstance(
32: LogCategory.AXIS2, Axis2RequestResponseTransport.class);
33:
34: private HttpResponse response;
35:
36: private CountDownLatch responseReadySignal = new CountDownLatch(1);
37:
38: private RequestResponseTransportStatus status = RequestResponseTransportStatus.INITIAL;
39:
40: private AxisFault faultToBeThrownOut = null;
41:
42: private boolean responseWritten;
43:
44: Axis2RequestResponseTransport(HttpResponse response) {
45: this .response = response;
46: }
47:
48: public void acknowledgeMessage(MessageContext msgContext)
49: throws AxisFault {
50: logger.debug("acknowledgeMessage");
51: logger.debug("Acking one-way request");
52:
53: response.setContentType("text/xml; charset="
54: + msgContext
55: .getProperty("message.character-set-encoding"));
56:
57: response.setStatusCode(HttpURLConnection.HTTP_ACCEPTED);
58: try {
59: response.flushBuffer();
60: } catch (IOException e) {
61: throw new AxisFault("Error sending acknowledgement", e);
62: }
63:
64: signalResponseReady();
65: }
66:
67: public void awaitResponse() throws InterruptedException, AxisFault {
68: logger.debug("Blocking servlet thread -- awaiting response");
69: status = RequestResponseTransportStatus.WAITING;
70: responseReadySignal.await();
71: if (faultToBeThrownOut != null) {
72: throw faultToBeThrownOut;
73: }
74: }
75:
76: public void signalFaultReady(AxisFault fault) {
77: faultToBeThrownOut = fault;
78: signalResponseReady();
79: }
80:
81: public void signalResponseReady() {
82: logger.debug("Signalling response available");
83: status = RequestResponseTransportStatus.SIGNALLED;
84: responseReadySignal.countDown();
85: }
86:
87: public RequestResponseTransportStatus getStatus() {
88: return status;
89: }
90:
91: public boolean isResponseWritten() {
92: return responseWritten;
93: }
94:
95: public void setResponseWritten(boolean responseWritten) {
96: this.responseWritten = responseWritten;
97: }
98: }
|