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 na...@apache.org on 2006/11/09 22:01:06 UTC
svn commit: r473071 - in /webservices/axis2/trunk/java/modules:
integration/test/org/apache/axis2/async/
kernel/src/org/apache/axis2/context/ kernel/src/org/apache/axis2/engine/
kernel/src/org/apache/axis2/util/
Author: nagy
Date: Thu Nov 9 13:01:04 2006
New Revision: 473071
URL: http://svn.apache.org/viewvc?view=rev&rev=473071
Log:
AXIS2-1649
Fixed problem with a requester that utilized an async callback for req/rsp hanging if transmission of the request failed. The AxisEngine will now invoke the registered Callback's onError(...) method unless a property is set on the MessageContext to stop that from occurring. (The property allows RM to disable this behavior, as it's really not desirable in that case.)
Added:
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/async/AsyncServiceWithTransportFailureTest.java
Modified:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisEngine.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/CallbackReceiver.java
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/async/AsyncServiceWithTransportFailureTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/async/AsyncServiceWithTransportFailureTest.java?view=auto&rev=473071
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/async/AsyncServiceWithTransportFailureTest.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/async/AsyncServiceWithTransportFailureTest.java Thu Nov 9 13:01:04 2006
@@ -0,0 +1,155 @@
+package org.apache.axis2.async;
+
+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.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.client.async.AsyncResult;
+import org.apache.axis2.client.async.Callback;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.engine.Echo;
+import org.apache.axis2.engine.util.TestConstants;
+import org.apache.axis2.integration.TestingUtils;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.integration.UtilServerBasedTestCase;
+import org.apache.axis2.util.Utils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/*
+ * 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.
+ *
+ *
+ */
+
+public class AsyncServiceWithTransportFailureTest extends
+ UtilServerBasedTestCase implements TestConstants
+{
+ private static final Log log = LogFactory.getLog(AsyncServiceWithTransportFailureTest.class);
+ EndpointReference targetEPR = new EndpointReference("http://127.0.0.1:0"
+ + "/axis2/services/EchoXMLService/echoOMElement");
+
+ protected AxisConfiguration engineRegistry;
+ protected MessageContext mc;
+ protected ServiceContext serviceContext;
+ protected AxisService service;
+ private boolean finish = false;
+ private boolean wasError = false;
+
+ public static Test suite()
+ {
+ return getTestSetup(new TestSuite(
+ AsyncServiceWithTransportFailureTest.class));
+ }
+
+ protected void setUp() throws Exception
+ {
+ service = Utils.createSimpleService(serviceName,
+ new AsyncMessageReceiver(),
+ Echo.class.getName(), operationName);
+ UtilServer.deployService(service);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ UtilServer.unDeployService(serviceName);
+ UtilServer.unDeployClientService();
+ }
+
+ public void testEchoXMLCompleteASyncWithTransportFailure() throws Exception
+ {
+ System.out.println("Starting testEchoXMLCompleteASyncWithTransportFailure");
+ AxisService service = Utils.createSimpleServiceforClient(
+ serviceName,
+ Echo.class.getName(),
+ operationName);
+
+ ConfigurationContext configcontext = UtilServer.createClientConfigurationContext();
+
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+
+ OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
+ OMElement method = fac.createOMElement("echoOMElement", omNs);
+ OMElement value = fac.createOMElement("myValue", omNs);
+ value.setText("Isaac Asimov, The Foundation Trilogy");
+ method.addChild(value);
+ ServiceClient sender = null;
+
+ try
+ {
+ Options options = new Options();
+ options.setTo(targetEPR);
+ options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+ options.setUseSeparateListener(true);
+ options.setAction(operationName.getLocalPart());
+
+ Callback callback = new Callback()
+ {
+ public void onComplete(AsyncResult result)
+ {
+ TestingUtils.campareWithCreatedOMElement(result.getResponseEnvelope().getBody().getFirstElement());
+ System.out.println("result = "
+ + result.getResponseEnvelope().getBody().getFirstElement());
+ finish = true;
+ }
+
+ public void onError(Exception e)
+ {
+ log.info(e.getMessage());
+ wasError = true;
+ finish = true;
+ }
+ };
+
+ sender = new ServiceClient(configcontext, service);
+ sender.setOptions(options);
+
+ sender.sendReceiveNonBlocking(operationName, method, callback);
+ System.out.println("send the request");
+ log.info("send the request");
+ int index = 0;
+ while (!finish)
+ {
+ Thread.sleep(1000);
+ index++;
+ if (index > 45)
+ {
+ throw new AxisFault("Server was shutdown, as the async response took too long to complete");
+ }
+ if (!wasError)
+ {
+ fail("An error occurred during the transmission of the async request but the callback was not notified");
+ }
+ }
+ }
+ finally
+ {
+ if (sender != null)
+ sender.cleanup();
+ }
+ }
+}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java?view=diff&rev=473071&r1=473070&r2=473071
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java Thu Nov 9 13:01:04 2006
@@ -110,6 +110,14 @@
public static final String TRANSPORT_NON_BLOCKING = "transportNonBlocking";
/**
+ * This property allows someone (e.g. RM) to disable an async callback from
+ * being invoked if a fault occurs during message transmission. If this is
+ * not set, it can be assumed that the fault will be delivered via
+ * Callback.onError(...).
+ */
+ public static final String DISABLE_ASYNC_CALLBACK_ON_TRANSPORT_ERROR = "disableTransmissionErrorCallback";
+
+ /**
* Field processingFault
*/
private boolean processingFault;
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisEngine.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisEngine.java?view=diff&rev=473071&r1=473070&r2=473071
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisEngine.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisEngine.java Thu Nov 9 13:01:04 2006
@@ -27,6 +27,7 @@
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPHeaderBlock;
import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.async.Callback;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.OperationContext;
@@ -35,6 +36,7 @@
import org.apache.axis2.engine.Handler.InvocationResponse;
import org.apache.axis2.i18n.Messages;
import org.apache.axis2.transport.TransportSender;
+import org.apache.axis2.util.CallbackReceiver;
import org.apache.axis2.util.MessageContextBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -612,6 +614,22 @@
}
} catch (Exception e) {
log.info(e.getMessage());
+ if (msgctx.getProperty(MessageContext.DISABLE_ASYNC_CALLBACK_ON_TRANSPORT_ERROR) == null)
+ {
+ AxisOperation axisOperation = msgctx.getAxisOperation();
+ if (axisOperation != null)
+ {
+ MessageReceiver msgReceiver = axisOperation.getMessageReceiver();
+ if ((msgReceiver != null) && (msgReceiver instanceof CallbackReceiver))
+ {
+ Callback callback = ((CallbackReceiver)msgReceiver).lookupCallback(msgctx.getMessageID());
+ if (callback != null)
+ {
+ callback.onError(e);
+ }
+ }
+ }
+ }
}
}
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/CallbackReceiver.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/CallbackReceiver.java?view=diff&rev=473071&r1=473070&r2=473071
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/CallbackReceiver.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/CallbackReceiver.java Thu Nov 9 13:01:04 2006
@@ -44,6 +44,11 @@
callbackStore.put(MsgID, callback);
}
+ public Callback lookupCallback(String msgID)
+ {
+ return (Callback)callbackStore.get(msgID);
+ }
+
public void receive(MessageContext messageCtx) throws AxisFault {
RelatesTo relatesTO = messageCtx.getOptions().getRelatesTo();
if(relatesTO == null){
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org