Author: amilas Date: Tue Feb 22 14:04:31 2011 New Revision: 1073331 URL: http://svn.apache.org/viewvc?rev=1073331&view=rev Log: applying the patch for AXIS2-4944
Added: axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/NonBlockingLocalTransportSender.java Modified: axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/LocalResponder.java axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/LocalTransportReceiver.java axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/LocalTransportSender.java Modified: axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/LocalResponder.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/LocalResponder.java?rev=1073331&r1=1073330&r2=1073331&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/LocalResponder.java (original) +++ axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/LocalResponder.java Tue Feb 22 14:04:31 2011 @@ -20,32 +20,40 @@ package org.apache.axis2.transport.local; +import org.apache.axiom.om.OMXMLParserWrapper; +import org.apache.axiom.soap.SOAPEnvelope; import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.addressing.RelatesTo; +import org.apache.axis2.builder.BuilderUtil; import org.apache.axis2.context.ConfigurationContext; import org.apache.axis2.context.MessageContext; import org.apache.axis2.description.TransportOutDescription; +import org.apache.axis2.description.WSDL2Constants; +import org.apache.axis2.engine.AxisEngine; import org.apache.axis2.handlers.AbstractHandler; import org.apache.axis2.transport.TransportSender; import org.apache.axis2.transport.TransportUtils; +import org.apache.axis2.wsdl.WSDLConstants; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import java.io.ByteArrayOutputStream; -import java.io.OutputStream; +import javax.xml.stream.XMLStreamException; +import java.io.*; +import java.util.Map; /** * LocalResponder */ public class LocalResponder extends AbstractHandler implements TransportSender { protected static final Log log = LogFactory.getLog(LocalResponder.class); - - + // fixed for Executing LocalTransport in MulthThread. private OutputStream out; public LocalResponder(OutputStream response) { - this.out = response; + this.out = response; } public void init(ConfigurationContext confContext, TransportOutDescription transportOut) @@ -87,13 +95,38 @@ public class LocalResponder extends Abst TransportUtils.writeMessage(msgContext, out); } } else { - out = (OutputStream) msgContext.getProperty(MessageContext.TRANSPORT_OUT); + if (/*(msgContext != null) &&*/ (msgContext.getOperationContext() != null) && + (msgContext.getOperationContext().getMessageContexts() != null)) { + MessageContext proxyInMessageContext = msgContext. + getOperationContext().getMessageContext(WSDL2Constants.MESSAGE_LABEL_IN); + + if (proxyInMessageContext != null) { + MessageContext initialMessageContext = (MessageContext) proxyInMessageContext. + getProperty(LocalTransportReceiver.IN_MESSAGE_CONTEXT); + + if (initialMessageContext != null) { + handleResponse(msgContext, initialMessageContext); + } else { + out = (OutputStream) msgContext.getProperty(MessageContext.TRANSPORT_OUT); + + if (out != null) { + TransportUtils.writeMessage(msgContext, out); + } else { + throw new AxisFault( + "Both the TO and Property MessageContext.TRANSPORT_OUT is Null, No where to send"); + } - if (out != null) { - TransportUtils.writeMessage(msgContext, out); + } + } } else { - throw new AxisFault( - "Both the TO and Property MessageContext.TRANSPORT_OUT is Null, No where to send"); + out = (OutputStream) msgContext.getProperty(MessageContext.TRANSPORT_OUT); + + if (out != null) { + TransportUtils.writeMessage(msgContext, out); + } else { + throw new AxisFault( + "Both the TO and Property MessageContext.TRANSPORT_OUT is Null, No where to send"); + } } } } catch (AxisFault axisFault) { @@ -103,7 +136,72 @@ public class LocalResponder extends Abst } TransportUtils.setResponseWritten(msgContext, true); - + return InvocationResponse.CONTINUE; } + + /** + * Retrieves the properties from the proxyOutMessageContext and sets the values to the + * inMessageContext. + * + * @param proxyOutMessageContext the active message context + * @param initialMessageContext the initial message context, which was stored as a property + * in the proxyOutMessageContext + * @throws AxisFault AxisFault + */ + private void handleResponse(MessageContext proxyOutMessageContext, MessageContext initialMessageContext) throws AxisFault { + MessageContext inMessageContext = initialMessageContext.getOperationContext(). + getMessageContext(WSDL2Constants.MESSAGE_LABEL_IN); + + // setting the properties + Map<String, Object> initialPropertyMap = initialMessageContext.getProperties(); + initialMessageContext.setProperties(initialPropertyMap); + + inMessageContext.setEnvelope(getEnvelope(proxyOutMessageContext)); + inMessageContext.setAxisServiceGroup(initialMessageContext.getAxisServiceGroup()); + inMessageContext.setAxisService(initialMessageContext.getAxisService()); + inMessageContext.setAxisOperation(initialMessageContext.getAxisOperation()); + inMessageContext.setAxisMessage(initialMessageContext.getAxisOperation().getMessage( + WSDLConstants.MESSAGE_LABEL_OUT_VALUE)); + inMessageContext.setIncomingTransportName(Constants.TRANSPORT_LOCAL); + inMessageContext.setServiceContext(initialMessageContext.getServiceContext()); + + // set properties on response + inMessageContext.setServerSide(true); + inMessageContext.setProperty(MessageContext.TRANSPORT_OUT, + initialMessageContext.getProperty(MessageContext.TRANSPORT_OUT)); + inMessageContext.setProperty(Constants.OUT_TRANSPORT_INFO, + initialMessageContext.getProperty(Constants.OUT_TRANSPORT_INFO)); + inMessageContext.setTransportIn(initialMessageContext.getTransportIn()); + inMessageContext.setTransportOut(initialMessageContext.getTransportOut()); + + // copy the message type property that is used by the out message to the response message + inMessageContext.setProperty(Constants.Configuration.MESSAGE_TYPE, + initialMessageContext.getProperty(Constants.Configuration.MESSAGE_TYPE)); + + if (initialMessageContext.getMessageID() != null) { + inMessageContext.setRelationships( + new RelatesTo[]{new RelatesTo(initialMessageContext.getMessageID())}); + } + + inMessageContext.setReplyTo(initialMessageContext.getReplyTo()); + inMessageContext.setFaultTo(initialMessageContext.getFaultTo()); + + AxisEngine.receive(inMessageContext); + } + + private SOAPEnvelope getEnvelope(MessageContext messageContext) throws AxisFault { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + TransportUtils.writeMessage(messageContext, out); + + ByteArrayInputStream bs = new ByteArrayInputStream(out.toByteArray()); + OMXMLParserWrapper builder; + try { + builder = BuilderUtil.getBuilder(bs); + } catch (XMLStreamException e) { + throw AxisFault.makeFault(e); + } + + return TransportUtils.createSOAPEnvelope(builder.getDocumentElement()); + } } Modified: axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/LocalTransportReceiver.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/LocalTransportReceiver.java?rev=1073331&r1=1073330&r2=1073331&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/LocalTransportReceiver.java (original) +++ axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/LocalTransportReceiver.java Tue Feb 22 14:04:31 2011 @@ -43,6 +43,10 @@ public class LocalTransportReceiver { public static ConfigurationContext CONFIG_CONTEXT; private ConfigurationContext confContext; private MessageContext inMessageContext; + /** Whether the call is blocking or non-blocking */ + private boolean nonBlocking = false; + /** If the call is non-blocking the in message context will be stored in this property */ + public static final String IN_MESSAGE_CONTEXT = "IN_MESSAGE_CONTEXT"; public LocalTransportReceiver(ConfigurationContext configContext) { confContext = configContext; @@ -52,6 +56,11 @@ public class LocalTransportReceiver { this(CONFIG_CONTEXT); } + public LocalTransportReceiver(LocalTransportSender sender, boolean nonBlocking) { + this(CONFIG_CONTEXT); + this.nonBlocking = nonBlocking; + } + public void processMessage(MessageContext inMessageContext, InputStream in, OutputStream response) throws AxisFault { @@ -79,6 +88,12 @@ public class LocalTransportReceiver { OutputStream response) throws AxisFault { MessageContext msgCtx = confContext.createMessageContext(); + + if (this.nonBlocking) { + // Set the in-message context as a property to the current message context. + msgCtx.setProperty(IN_MESSAGE_CONTEXT, inMessageContext); + } + if (inMessageContext != null) { msgCtx.setProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST, inMessageContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST)); Modified: axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/LocalTransportSender.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/LocalTransportSender.java?rev=1073331&r1=1073330&r2=1073331&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/LocalTransportSender.java (original) +++ axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/LocalTransportSender.java Tue Feb 22 14:04:31 2011 @@ -98,7 +98,7 @@ public class LocalTransportSender extend InputStream in = new ByteArrayInputStream(out.toByteArray()); ByteArrayOutputStream response = new ByteArrayOutputStream(); - LocalTransportReceiver localTransportReceiver = new LocalTransportReceiver(this); + LocalTransportReceiver localTransportReceiver = new LocalTransportReceiver(this, isNonBlocking()); localTransportReceiver.processMessage(msgContext, in, response); in.close(); @@ -111,4 +111,8 @@ public class LocalTransportSender extend throw AxisFault.makeFault(e); } } + + private boolean isNonBlocking() { + return false; + } } Added: axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/NonBlockingLocalTransportSender.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/NonBlockingLocalTransportSender.java?rev=1073331&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/NonBlockingLocalTransportSender.java (added) +++ axis/axis2/java/core/trunk/modules/transport/local/src/org/apache/axis2/transport/local/NonBlockingLocalTransportSender.java Tue Feb 22 14:04:31 2011 @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.transport.local; + +public class NonBlockingLocalTransportSender extends LocalTransportSender { + + private boolean isNonBlocking() { + return true; + } + +}