001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.geronimo.axis2; 019 020 import java.io.IOException; 021 import java.net.HttpURLConnection; 022 import java.util.concurrent.CountDownLatch; 023 024 import org.apache.axis2.AxisFault; 025 import org.apache.axis2.context.MessageContext; 026 import org.apache.axis2.transport.RequestResponseTransport; 027 import org.apache.commons.logging.Log; 028 import org.apache.commons.logging.LogFactory; 029 import org.apache.geronimo.webservices.WebServiceContainer.Response; 030 031 public class Axis2RequestResponseTransport implements RequestResponseTransport { 032 033 private static final Log LOG = LogFactory.getLog(Axis2RequestResponseTransport.class); 034 035 private Response response; 036 037 private CountDownLatch responseReadySignal = new CountDownLatch(1); 038 039 private RequestResponseTransportStatus status = RequestResponseTransportStatus.INITIAL; 040 041 private AxisFault faultToBeThrownOut = null; 042 043 private boolean responseWritten; 044 045 Axis2RequestResponseTransport(Response response) { 046 this.response = response; 047 } 048 049 public void acknowledgeMessage(MessageContext msgContext) throws AxisFault { 050 LOG.debug("acknowledgeMessage"); 051 LOG.debug("Acking one-way request"); 052 053 response.setContentType("text/xml; charset=" 054 + msgContext.getProperty("message.character-set-encoding")); 055 056 response.setStatusCode(HttpURLConnection.HTTP_ACCEPTED); 057 try { 058 response.flushBuffer(); 059 } catch (IOException e) { 060 throw new AxisFault("Error sending acknowledgement", e); 061 } 062 063 signalResponseReady(); 064 } 065 066 public void awaitResponse() throws InterruptedException, AxisFault { 067 LOG.debug("Blocking servlet thread -- awaiting response"); 068 status = RequestResponseTransportStatus.WAITING; 069 responseReadySignal.await(); 070 if (faultToBeThrownOut != null) { 071 throw faultToBeThrownOut; 072 } 073 } 074 075 public void signalFaultReady(AxisFault fault) { 076 faultToBeThrownOut = fault; 077 signalResponseReady(); 078 } 079 080 public void signalResponseReady() { 081 LOG.debug("Signalling response available"); 082 status = RequestResponseTransportStatus.SIGNALLED; 083 responseReadySignal.countDown(); 084 } 085 086 public RequestResponseTransportStatus getStatus() { 087 return status; 088 } 089 090 public boolean isResponseWritten() { 091 return responseWritten; 092 } 093 094 public void setResponseWritten(boolean responseWritten) { 095 this.responseWritten = responseWritten; 096 } 097 }