You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2006/11/30 16:31:15 UTC
svn commit: r480966 - in /webservices/axis2/branches/java/1_1/modules:
kernel/src/org/apache/axis2/engine/ kernel/src/org/apache/axis2/transport/
kernel/src/org/apache/axis2/transport/http/
samples/quickstartaxiom/src/samples/quickstart/clients/
Author: dims
Date: Thu Nov 30 07:31:14 2006
New Revision: 480966
URL: http://svn.apache.org/viewvc?view=rev&rev=480966
Log:
Fix for AXIS2-1795 - Wrong HTTP response code when async call made under WAR version (Porting changes in HEAD revisions 480660 and 480901)
Added:
webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/RequestResponseTransport.java
Modified:
webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/engine/DispatchPhase.java
webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java
webservices/axis2/branches/java/1_1/modules/samples/quickstartaxiom/src/samples/quickstart/clients/AXIOMClient.java
Modified: webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/engine/DispatchPhase.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/engine/DispatchPhase.java?view=diff&rev=480966&r1=480965&r2=480966
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/engine/DispatchPhase.java (original)
+++ webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/engine/DispatchPhase.java Thu Nov 30 07:31:14 2006
@@ -1,96 +1,122 @@
-package org.apache.axis2.engine;
-
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.i18n.Messages;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/*
-* Copyright 2004,2005 The Apache Software Foundation.
-*
-* Licensed 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, softwar
-* 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.
-*
-*/
-
-public class DispatchPhase extends Phase {
-
- private static final long serialVersionUID = -6596799621473224363L;
-
- public DispatchPhase() {
- }
-
- public DispatchPhase(String phaseName) {
- super(phaseName);
- }
-
- public void checkPostConditions(MessageContext msgContext) throws AxisFault {
- EndpointReference toEPR = msgContext.getTo();
-
- if (msgContext.getAxisService() == null) {
- throw new AxisFault(Messages.getMessage("servicenotfoundforepr",
- ((toEPR != null) ? toEPR.getAddress() : "")));
- } else if (msgContext.getAxisOperation() == null) {
- throw new AxisFault(Messages.getMessage("operationnotfoundforepr",
- ((toEPR != null) ? toEPR.getAddress()
- : ""), msgContext.getWSAAction()));
- }
-
- validateTransport(msgContext);
- if (msgContext.getOperationContext() == null) {
- throw new AxisFault(Messages.getMessage("cannotBeNullOperationContext"));
- }
-
- if (msgContext.getServiceContext() == null) {
- throw new AxisFault(Messages.getMessage("cannotBeNullServiceContext"));
- }
-
- if ((msgContext.getAxisOperation() == null) && (msgContext.getOperationContext() != null)) {
- msgContext.setAxisOperation(msgContext.getOperationContext().getAxisOperation());
- }
-
- if ((msgContext.getAxisService() == null) && (msgContext.getServiceContext() != null)) {
- msgContext.setAxisService(msgContext.getServiceContext().getAxisService());
- }
- ArrayList operationChain = msgContext.getAxisOperation().getRemainingPhasesInFlow();
- msgContext.setExecutionChain((ArrayList) operationChain.clone());
- }
-
- /**
- * To check wether the incoming request has come in valid transport , simpley the transports
- * that service author wants to expose
- *
- * @param msgctx
- */
- private void validateTransport(MessageContext msgctx) throws AxisFault {
- AxisService service = msgctx.getAxisService();
- if (service.isEnableAllTransports()) {
- return;
- } else {
- List trs = service.getExposedTransports();
- String incommingTrs = msgctx.getIncomingTransportName();
- for (int i = 0; i < trs.size(); i++) {
- String tr = (String) trs.get(i);
- if (incommingTrs != null && incommingTrs.equals(tr)) {
- return;
- }
- }
- }
- EndpointReference toEPR = msgctx.getTo();
- throw new AxisFault(Messages.getMessage("servicenotfoundforepr",
- ((toEPR != null) ? toEPR.getAddress() : "")));
- }
-}
+package org.apache.axis2.engine;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.addressing.AddressingHelper;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.i18n.Messages;
+import org.apache.axis2.transport.RequestResponseTransport;
+import org.apache.axis2.wsdl.WSDLConstants.WSDL20_2004Constants;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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, softwar
+* 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.
+*
+*/
+
+public class DispatchPhase extends Phase {
+
+ private static final long serialVersionUID = -6596799621473224363L;
+
+ public DispatchPhase() {
+ }
+
+ public DispatchPhase(String phaseName) {
+ super(phaseName);
+ }
+
+ public void checkPostConditions(MessageContext msgContext) throws AxisFault {
+ EndpointReference toEPR = msgContext.getTo();
+
+ if (msgContext.getAxisService() == null) {
+ throw new AxisFault(Messages.getMessage("servicenotfoundforepr",
+ ((toEPR != null) ? toEPR.getAddress() : "")));
+ } else if (msgContext.getAxisOperation() == null) {
+ throw new AxisFault(Messages.getMessage("operationnotfoundforepr",
+ ((toEPR != null) ? toEPR.getAddress()
+ : ""), msgContext.getWSAAction()));
+ }
+
+ validateTransport(msgContext);
+ if (msgContext.getOperationContext() == null) {
+ throw new AxisFault(Messages.getMessage("cannotBeNullOperationContext"));
+ }
+
+ if (msgContext.getServiceContext() == null) {
+ throw new AxisFault(Messages.getMessage("cannotBeNullServiceContext"));
+ }
+
+ if ((msgContext.getAxisOperation() == null) && (msgContext.getOperationContext() != null)) {
+ msgContext.setAxisOperation(msgContext.getOperationContext().getAxisOperation());
+ }
+
+ if ((msgContext.getAxisService() == null) && (msgContext.getServiceContext() != null)) {
+ msgContext.setAxisService(msgContext.getServiceContext().getAxisService());
+ }
+
+ //TODO: The same thing should probably happen for a IN-OUT if addressing is enabled and the replyTo/faultTo are not anonymous
+ if (msgContext.getAxisOperation().getMessageExchangePattern().equals(WSDL20_2004Constants.MEP_URI_IN_ONLY))
+ {
+ Object requestResponseTransport = msgContext.getProperty(RequestResponseTransport.TRANSPORT_CONTROL);
+ if (requestResponseTransport != null)
+ {
+ ((RequestResponseTransport)requestResponseTransport).acknowledgeMessage(msgContext);
+ }
+ }else if (msgContext.getAxisOperation().getMessageExchangePattern().equals(WSDL20_2004Constants.MEP_URI_IN_OUT))
+ { // OR, if 2 way operation but the response is intended to not use the response channel of a 2-way transport
+ // then we don't need to keep the transport waiting.
+ Object requestResponseTransport = msgContext.getProperty(RequestResponseTransport.TRANSPORT_CONTROL);
+ if (requestResponseTransport != null)
+ {
+ if(AddressingHelper.isReplyRedirected(msgContext) && AddressingHelper.isFaultRedirected(msgContext)){
+ ((RequestResponseTransport)requestResponseTransport).acknowledgeMessage(msgContext);
+ }
+ }
+ }
+
+
+ ArrayList operationChain = msgContext.getAxisOperation().getRemainingPhasesInFlow();
+ msgContext.setExecutionChain((ArrayList) operationChain.clone());
+ }
+
+ /**
+ * To check wether the incoming request has come in valid transport , simpley the transports
+ * that service author wants to expose
+ *
+ * @param msgctx
+ */
+ private void validateTransport(MessageContext msgctx) throws AxisFault {
+ AxisService service = msgctx.getAxisService();
+ if (service.isEnableAllTransports()) {
+ return;
+ } else {
+ List trs = service.getExposedTransports();
+ String incommingTrs = msgctx.getIncomingTransportName();
+ for (int i = 0; i < trs.size(); i++) {
+ String tr = (String) trs.get(i);
+ if (incommingTrs != null && incommingTrs.equals(tr)) {
+ return;
+ }
+ }
+ }
+ EndpointReference toEPR = msgctx.getTo();
+ throw new AxisFault(Messages.getMessage("servicenotfoundforepr",
+ ((toEPR != null) ? toEPR.getAddress() : "")));
+ }
+}
Added: webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/RequestResponseTransport.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/RequestResponseTransport.java?view=auto&rev=480966
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/RequestResponseTransport.java (added)
+++ webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/RequestResponseTransport.java Thu Nov 30 07:31:14 2006
@@ -0,0 +1,42 @@
+/*
+* Copyright 2006 The Apache Software Foundation.
+*
+* Licensed 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;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+
+/**
+ * This interface represents a control object for a Request/Response transport.
+ * The normal flow of Axis2 is rooted at the transport -- this does not
+ * allow for an acknowledgement to be transmitted before processing has
+ * completed, nor does it allow for processing to be paused and resumed
+ * on a separate thread without having a response be sent back. This interface
+ * enables both of those scenarios by allowing the transport to expose
+ * controls to the rest of the engine via a callback.
+ */
+public interface RequestResponseTransport
+{
+ /*This is the name of the property that is to be stored on the
+ MessageContext*/
+ public static final String TRANSPORT_CONTROL
+ = "RequestResponseTransportControl";
+
+ public void acknowledgeMessage(MessageContext msgContext) throws AxisFault;
+
+ //public void suspendOnReturn(MessageContext msgContext);
+ //public void processResponse(MessageContext msgContext);
+}
Modified: webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java?view=diff&rev=480966&r1=480965&r2=480966
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java (original)
+++ webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java Thu Nov 30 07:31:14 2006
@@ -32,6 +32,7 @@
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.engine.AxisEngine;
import org.apache.axis2.engine.ListenerManager;
+import org.apache.axis2.transport.RequestResponseTransport;
import org.apache.axis2.transport.TransportListener;
import org.apache.axis2.transport.http.server.HttpUtils;
import org.apache.axis2.transport.http.util.RESTUtil;
@@ -97,6 +98,8 @@
msgContext.setProperty(Constants.OUT_TRANSPORT_INFO,
new ServletBasedOutTransportInfo(resp));
+ msgContext.setProperty(RequestResponseTransport.TRANSPORT_CONTROL,
+ new ServletRequestResponseTransport(resp));
msgContext.setProperty(MessageContext.REMOTE_ADDR, req.getRemoteAddr());
msgContext.setFrom(new EndpointReference(req.getRemoteAddr()));
msgContext.setProperty(MessageContext.TRANSPORT_HEADERS,
@@ -538,5 +541,31 @@
return ((soapActionHeader == null) ||
(contentType != null && contentType.indexOf(HTTPConstants.MEDIA_TYPE_X_WWW_FORM) > -1));
+ }
+
+ class ServletRequestResponseTransport implements RequestResponseTransport
+ {
+ private HttpServletResponse response;
+
+ ServletRequestResponseTransport(HttpServletResponse response)
+ {
+ this.response = response;
+ }
+
+ public void acknowledgeMessage(MessageContext msgContext) throws AxisFault
+ {
+ response.setContentType("text/xml; charset="
+ + msgContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING));
+
+ response.setStatus(HttpServletResponse.SC_ACCEPTED);
+ try
+ {
+ response.flushBuffer();
+ }
+ catch (IOException e)
+ {
+ throw new AxisFault("Error sending acknowledgement", e);
+ }
+ }
}
}
Modified: webservices/axis2/branches/java/1_1/modules/samples/quickstartaxiom/src/samples/quickstart/clients/AXIOMClient.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/samples/quickstartaxiom/src/samples/quickstart/clients/AXIOMClient.java?view=diff&rev=480966&r1=480965&r2=480966
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/samples/quickstartaxiom/src/samples/quickstart/clients/AXIOMClient.java (original)
+++ webservices/axis2/branches/java/1_1/modules/samples/quickstartaxiom/src/samples/quickstart/clients/AXIOMClient.java Thu Nov 30 07:31:14 2006
@@ -1,71 +1,72 @@
-package samples.quickstart.clients;
-
-import org.apache.axiom.om.OMAbstractFactory;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axis2.Constants;
-import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.client.Options;
-import org.apache.axis2.client.ServiceClient;
-
-public class AXIOMClient {
-
- private static EndpointReference targetEPR =
- new EndpointReference(
- "http://localhost:8080/axis2/services/StockQuoteService");
-
- public static OMElement getPricePayload(String symbol) {
- OMFactory fac = OMAbstractFactory.getOMFactory();
- OMNamespace omNs = fac.createOMNamespace(
- "http://quickstart.samples/xsd", "tns");
-
- OMElement method = fac.createOMElement("getPrice", omNs);
- OMElement value = fac.createOMElement("symbol", omNs);
- value.addChild(fac.createOMText(value, symbol));
- method.addChild(value);
- return method;
- }
-
- public static OMElement updatePayload(String symbol, double price) {
- OMFactory fac = OMAbstractFactory.getOMFactory();
- OMNamespace omNs = fac.createOMNamespace(
- "http://quickstart.samples/xsd", "tns");
-
- OMElement method = fac.createOMElement("update", omNs);
-
- OMElement value1 = fac.createOMElement("symbol", omNs);
- value1.addChild(fac.createOMText(value1, symbol));
- method.addChild(value1);
-
- OMElement value2 = fac.createOMElement("price", omNs);
- value2.addChild(fac.createOMText(value2,
- Double.toString(price)));
- method.addChild(value2);
- return method;
- }
-
- public static void main(String[] args) {
- try {
- OMElement getPricePayload = getPricePayload("WSO");
- OMElement updatePayload = updatePayload("WSO", 123.42);
- Options options = new Options();
- options.setTo(targetEPR);
- options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
-
- ServiceClient sender = new ServiceClient();
- sender.setOptions(options);
-
- sender.fireAndForget(updatePayload);
- System.err.println("done");
- OMElement result = sender.sendReceive(getPricePayload);
-
- String response = result.getFirstElement().getText();
- System.err.println("Current price of WSO: " + response);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
-}
+package samples.quickstart.clients;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+
+public class AXIOMClient {
+
+ private static EndpointReference targetEPR =
+ new EndpointReference(
+ "http://localhost:8080/axis2/services/StockQuoteService");
+
+ public static OMElement getPricePayload(String symbol) {
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ OMNamespace omNs = fac.createOMNamespace(
+ "http://quickstart.samples/xsd", "tns");
+
+ OMElement method = fac.createOMElement("getPrice", omNs);
+ OMElement value = fac.createOMElement("symbol", omNs);
+ value.addChild(fac.createOMText(value, symbol));
+ method.addChild(value);
+ return method;
+ }
+
+ public static OMElement updatePayload(String symbol, double price) {
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ OMNamespace omNs = fac.createOMNamespace(
+ "http://quickstart.samples/xsd", "tns");
+
+ OMElement method = fac.createOMElement("update", omNs);
+
+ OMElement value1 = fac.createOMElement("symbol", omNs);
+ value1.addChild(fac.createOMText(value1, symbol));
+ method.addChild(value1);
+
+ OMElement value2 = fac.createOMElement("price", omNs);
+ value2.addChild(fac.createOMText(value2,
+ Double.toString(price)));
+ method.addChild(value2);
+ return method;
+ }
+
+ public static void main(String[] args) {
+ try {
+ OMElement getPricePayload = getPricePayload("WSO");
+ OMElement updatePayload = updatePayload("WSO", 123.42);
+ Options options = new Options();
+ options.setTo(targetEPR);
+ options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+
+ ServiceClient sender = new ServiceClient();
+ sender.setOptions(options);
+
+ sender.fireAndForget(updatePayload);
+ System.err.println("done");
+ Thread.sleep(3000);
+ OMElement result = sender.sendReceive(getPricePayload);
+
+ String response = result.getFirstElement().getText();
+ System.err.println("Current price of WSO: " + response);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org