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 gd...@apache.org on 2007/07/01 17:48:06 UTC
svn commit: r552328 - in /webservices/axis2/trunk/java/modules:
adb/src/org/apache/axis2/rpc/client/
codegen/src/org/apache/axis2/wsdl/template/java/
integration/test/org/apache/axis2/async/
kernel/src/org/apache/axis2/client/ kernel/src/org/apache/axi...
Author: gdaniels
Date: Sun Jul 1 08:48:04 2007
New Revision: 552328
URL: http://svn.apache.org/viewvc?view=rev&rev=552328
Log:
First part of resolving https://issues.apache.org/jira/browse/AXIS2-2855
* Introduce AxisCallback interface, as discussed on the thread at http://marc.info/?t=117858969600039&r=1&w=2
* Switch codegen template to use the new interface, and clean up the gen'ed code a touch (note - the generated code should really get a full cleanup pass)
* Deprecate uses of the old Callback
* TODO - go through the rest of the usages of Callback and convert to AxisCallback (except for one or two for testing)
Added:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/async/AxisCallback.java
Modified:
webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/rpc/client/RPCServiceClient.java
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/async/AsyncServiceTest.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/OperationClient.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/ServiceClient.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/OutInAxisOperation.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
Modified: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/rpc/client/RPCServiceClient.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/rpc/client/RPCServiceClient.java?view=diff&rev=552328&r1=552327&r2=552328
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/rpc/client/RPCServiceClient.java (original)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/rpc/client/RPCServiceClient.java Sun Jul 1 08:48:04 2007
@@ -22,6 +22,7 @@
import org.apache.axis2.AxisFault;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.client.async.Callback;
+import org.apache.axis2.client.async.AxisCallback;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.databinding.utils.BeanUtil;
import org.apache.axis2.description.AxisService;
@@ -63,6 +64,8 @@
* @param opName Operation QName (to get the body wrapper element)
* @param args Arraylist of objects
* @return Response OMElement
+ * @throws AxisFault in case of a problem - this can either be a processing fault or a received
+ * on-the-wire fault.
*/
public OMElement invokeBlocking(QName opName, Object [] args) throws AxisFault {
OMElement omElement = BeanUtil.getOMElement(opName, args, null, false, null);
@@ -85,10 +88,10 @@
* @return Object array , whic will contains real object , but the object can either be simple
* type object or the JavaBeans, thats what this method can handle right now the return
* array will contains [10, "Axis2Echo", {"foo","baa","11"}]
- * @throws AxisFault
+ * @throws AxisFault a problem occurred, either locally or on the other side of the wire
*/
- public Object[] invokeBlocking(QName opName, Object [] args, Class [] returnTypes)
+ public Object[] invokeBlocking(QName opName, Object [] args, Class [] returnTypes)
throws AxisFault {
OMElement omElement = BeanUtil.getOMElement(opName, args, null, false, null);
OMElement response;
@@ -104,18 +107,39 @@
/**
* Invoke the nonblocking/Asynchronous call
*
- * @param opName
- * @param args - This should be OM Element (payload) invocation behaves accordingly
- * @param callback
- * @throws org.apache.axis2.AxisFault
+ * @param opName Operation QName (to get the body wrapper element)
+ * @param args an array of argument Objects
+ * @param callback object extending Callback which will receive notifications
+ * @throws AxisFault in case of a local processing error
+ * @deprecated Please use the AxisCallback interface rather than Callback, which has been deprecated
*/
-
public void invokeNonBlocking(QName opName,
Object [] args,
Callback callback)
throws AxisFault {
OMElement omElement = BeanUtil.getOMElement(opName, args, null, false, null);
- //call the underline implementation
+ // call the underlying implementation
+ if (notNullService) {
+ super.sendReceiveNonBlocking(opName, omElement, callback);
+ } else {
+ super.sendReceiveNonBlocking(omElement, callback);
+ }
+ }
+
+ /**
+ * Invoke the nonblocking/Asynchronous call
+ *
+ * @param opName Operation QName (to get the body wrapper element)
+ * @param args an array of argument Objects
+ * @param callback object implementing AxisCallback which will receive notifications
+ * @throws AxisFault in case of a local processing error
+ */
+ public void invokeNonBlocking(QName opName,
+ Object [] args,
+ AxisCallback callback)
+ throws AxisFault {
+ OMElement omElement = BeanUtil.getOMElement(opName, args, null, false, null);
+ // call the underlying implementation
if (notNullService) {
super.sendReceiveNonBlocking(opName, omElement, callback);
} else {
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl?view=diff&rev=552328&r1=552327&r2=552328
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl Sun Jul 1 08:48:04 2007
@@ -244,15 +244,15 @@
<xsl:if test="$mep='12'"> <!-- These constants can be found in org.apache.axis2.wsdl.WSDLConstants -->
<xsl:if test="$isSync='1'">
/**
- * Auto generated method signature
- * @see <xsl:value-of select="$package"/>.<xsl:value-of select="$interfaceName"/>#<xsl:value-of select="@name"/>
+ * Auto generated method signature
+ * @see <xsl:value-of select="$package"/>.<xsl:value-of select="$interfaceName"/>#<xsl:value-of select="@name"/>
<xsl:for-each select="input/param[@type!='']">
- * @param <xsl:value-of select="@name"></xsl:value-of><xsl:text>
+ * @param <xsl:value-of select="@name"></xsl:value-of><xsl:text>
</xsl:text></xsl:for-each>
- */
+ */
<xsl:choose>
- <!-- if -b flag is on then we have to unwarp the request and response messages. -->
+ <!-- if -b flag is on then we have to unwrap the request and response messages. -->
<xsl:when test="$isbackcompatible = 'true'">
public <xsl:choose><xsl:when test="$outputtype=''">void</xsl:when>
<xsl:when test="string-length(normalize-space($outputcomplextype)) > 0"><xsl:value-of select="$outputcomplextype"/></xsl:when>
@@ -684,33 +684,29 @@
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
- //adding SOAP soap_headers
+ // adding SOAP soap_headers
_serviceClient.addHeadersToEnvelope(env);
// create message context with that soap envelope
_messageContext.setEnvelope(env);
- // add the message contxt to the operation client
+ // add the message context to the operation client
_operationClient.addMessageContext(_messageContext);
<xsl:choose>
<xsl:when test="$outputtype=''">
- //Nothing to pass as the callback!!!
+ // Nothing to pass as the callback!!!
</xsl:when>
<xsl:otherwise>
- _operationClient.setCallback(new org.apache.axis2.client.async.Callback() {
- public void onComplete(
- org.apache.axis2.client.async.AsyncResult result) {
- try{
- java.lang.Object object = fromOM(result.getResponseEnvelope().getBody().getFirstElement(),
- <xsl:value-of select="$outputtype"/>.class,
- getEnvelopeNamespaces(result.getResponseEnvelope())
- );
- callback.receiveResult<xsl:value-of select="@name"/>(
- <xsl:choose>
- <xsl:when test="$outputtype=''">
- );
- </xsl:when>
+ _operationClient.setCallback(new org.apache.axis2.client.async.AxisCallback() {
+ public void onMessage(org.apache.axis2.context.MessageContext resultContext) {
+ try {
+ org.apache.axiom.soap.SOAPEnvelope resultEnv = resultContext.getEnvelope();
+ java.lang.Object object = fromOM(resultEnv.getBody().getFirstElement(),
+ <xsl:value-of select="$outputtype"/>.class,
+ getEnvelopeNamespaces(resultEnv));
+ callback.receiveResult<xsl:value-of select="@name"/>(<xsl:choose>
+ <xsl:when test="$outputtype=''">);</xsl:when>
<xsl:when test="$outputparamcount=1">
get<xsl:value-of select="$outputparamshorttype"/><xsl:value-of
select="$outputparampartname"/>((<xsl:value-of select="$outputtype"/>)object));
@@ -719,18 +715,26 @@
(<xsl:value-of select="$outputcomplextype"/>)object);
</xsl:when>
<xsl:otherwise>
- (<xsl:value-of select="$outputtype"/>)object);
+ (<xsl:value-of select="$outputtype"/>)object);
</xsl:otherwise>
</xsl:choose>
- } catch(org.apache.axis2.AxisFault e){
- callback.receiveError<xsl:value-of select="@name"/>(e);
- }
-
- }
-
- public void onError(java.lang.Exception e) {
- callback.receiveError<xsl:value-of select="@name"/>(e);
- }
+ } catch (org.apache.axis2.AxisFault e) {
+ callback.receiveError<xsl:value-of select="@name"/>(e);
+ }
+ }
+
+ public void onError(java.lang.Exception e) {
+ callback.receiveError<xsl:value-of select="@name"/>(e);
+ }
+
+ public void onFault(org.apache.axis2.context.MessageContext faultContext) {
+ org.apache.axis2.AxisFault fault = org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(faultContext);
+ onError(fault);
+ }
+
+ public void onComplete() {
+ // Do nothing by default
+ }
});
</xsl:otherwise>
</xsl:choose>
Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/async/AsyncServiceTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/async/AsyncServiceTest.java?view=diff&rev=552328&r1=552327&r2=552328
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/async/AsyncServiceTest.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/async/AsyncServiceTest.java Sun Jul 1 08:48:04 2007
@@ -29,8 +29,7 @@
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.client.async.AxisCallback;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.ServiceContext;
@@ -104,19 +103,41 @@
options.setUseSeparateListener(true);
options.setAction(operationName.getLocalPart());
- Callback callback = new Callback() {
- public void onComplete(AsyncResult result) {
- TestingUtils.compareWithCreatedOMElement(
- result.getResponseEnvelope().getBody()
- .getFirstElement());
- System.out.println("result = " + result.getResponseEnvelope().getBody()
- .getFirstElement());
- finish = true;
+ AxisCallback callback = new AxisCallback() {
+
+ /**
+ * This is called when we receive a message.
+ *
+ * @param msgContext the (response) MessageContext
+ */
+ public void onMessage(MessageContext msgContext) {
+ OMElement result = msgContext.getEnvelope().getBody().getFirstElement();
+ TestingUtils.compareWithCreatedOMElement(result);
+ log.debug("result = " + result);
+ }
+
+ /**
+ * This gets called when a fault message is received.
+ *
+ * @param msgContext the MessageContext containing the fault.
+ */
+ public void onFault(MessageContext msgContext) {
+ fail("Fault received");
}
+
+ /**
+ * This gets called ONLY when an internal processing exception occurs.
+ *
+ * @param e the Exception which caused the problem
+ */
public void onError(Exception e) {
- log.info(e.getMessage());
+ }
+
+ /** This is called at the end of the MEP no matter what happens, quite like a finally block. */
+ public void onComplete() {
finish = true;
+ notify();
}
};
@@ -124,15 +145,14 @@
sender.setOptions(options);
sender.sendReceiveNonBlocking(operationName, method, callback);
- System.out.println("send the reqest");
- log.info("send the reqest");
- int index = 0;
- while (!finish) {
- Thread.sleep(1000);
- index++;
- if (index > 45) {
- throw new AxisFault(
- "Server was shutdown as the async response take too long to complete");
+ log.info("send the request");
+ synchronized (callback) {
+ if (!finish) {
+ callback.wait(45000);
+ if (!finish) {
+ throw new AxisFault(
+ "Server was shutdown as the async response take too long to complete");
+ }
}
}
} finally {
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/OperationClient.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/OperationClient.java?view=diff&rev=552328&r1=552327&r2=552328
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/OperationClient.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/OperationClient.java Sun Jul 1 08:48:04 2007
@@ -24,6 +24,7 @@
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.async.Callback;
+import org.apache.axis2.client.async.AxisCallback;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.OperationContext;
@@ -60,6 +61,8 @@
protected Callback callback;
+ protected AxisCallback axisCallback;
+
/*
* indicates whether the MEP execution has completed (and hence ready for
* resetting)
@@ -126,8 +129,23 @@
*
* @param callback the callback to be used when the client decides its time to
* use it
+ * @deprecated Please use the AxisCallback interface rather than Callback, which has been deprecated
*/
public abstract void setCallback(Callback callback);
+
+ /**
+ * Set the callback to be executed when a message comes into the MEP and the
+ * operation client is executed. This is the way the operation client
+ * provides notification that a message has been received by it. Exactly
+ * when its executed and under what conditions is a function of the specific
+ * operation client.
+ *
+ * @param callback the callback to be used when the client decides its time to
+ * use it
+ */
+ public final void setCallback(AxisCallback callback) {
+ axisCallback = callback;
+ }
/**
* Execute the MEP. This method is final and only serves to set (if appropriate)
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/ServiceClient.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/ServiceClient.java?view=diff&rev=552328&r1=552327&r2=552328
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/ServiceClient.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/ServiceClient.java Sun Jul 1 08:48:04 2007
@@ -30,6 +30,7 @@
import org.apache.axis2.util.Counter;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.async.Callback;
+import org.apache.axis2.client.async.AxisCallback;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.context.MessageContext;
@@ -540,6 +541,7 @@
* @param callback a Callback which will be notified upon completion
* @throws AxisFault in case of error
* @see #createClient(QName)
+ * @deprecated Please use the AxisCallback interface rather than Callback, which has been deprecated
*/
public void sendReceiveNonBlocking(OMElement elem, Callback callback)
throws AxisFault {
@@ -547,6 +549,49 @@
}
/**
+ * Directly invoke an anonymous operation with an In-Out MEP without waiting
+ * for a response. This method sends your supplied XML with response
+ * notification to your callback handler. For more control, you can instead
+ * create a client for the operation and use that client to execute the
+ * exchange.
+ *
+ * @param elem the data to send (becomes the content of SOAP body)
+ * @param callback a Callback which will be notified upon completion
+ * @throws AxisFault in case of error
+ * @see #createClient(QName)
+ */
+ public void sendReceiveNonBlocking(OMElement elem, AxisCallback callback)
+ throws AxisFault {
+ sendReceiveNonBlocking(ANON_OUT_IN_OP, elem, callback);
+ }
+
+ /**
+ * Directly invoke a named operation with an In-Out MEP without waiting for
+ * a response. This method sends your supplied XML with response
+ * notification to your callback handler. For more control, you can instead
+ * create a client for the operation and use that client to execute the
+ * exchange.
+ *
+ * @param operation name of operation to be invoked (non-<code>null</code>)
+ * @param elem the data to send (becomes the content of SOAP body)
+ * @param callback a Callback which will be notified upon completion
+ * @throws AxisFault in case of error
+ * @see #createClient(QName)
+ * @deprecated Please use the AxisCallback interface rather than Callback, which has been deprecated
+ */
+ public void sendReceiveNonBlocking(QName operation, OMElement elem, Callback callback)
+ throws AxisFault {
+ MessageContext mc = new MessageContext();
+ fillSOAPEnvelope(mc, elem);
+ OperationClient mepClient = createClient(operation);
+ // here a blocking invocation happens in a new thread, so the
+ // progamming model is non blocking
+ mepClient.setCallback(callback);
+ mepClient.addMessageContext(mc);
+ mepClient.execute(false);
+ }
+
+ /**
* Directly invoke a named operation with an In-Out MEP without waiting for
* a response. This method sends your supplied XML with response
* notification to your callback handler. For more control, you can instead
@@ -559,8 +604,8 @@
* @throws AxisFault in case of error
* @see #createClient(QName)
*/
- public void sendReceiveNonBlocking(QName operation, OMElement elem,
- Callback callback) throws AxisFault {
+ public void sendReceiveNonBlocking(QName operation, OMElement elem, AxisCallback callback)
+ throws AxisFault {
MessageContext mc = new MessageContext();
fillSOAPEnvelope(mc, elem);
OperationClient mepClient = createClient(operation);
Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/async/AxisCallback.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/async/AxisCallback.java?view=auto&rev=552328
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/async/AxisCallback.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/async/AxisCallback.java Sun Jul 1 08:48:04 2007
@@ -0,0 +1,46 @@
+package org.apache.axis2.client.async;
+
+import org.apache.axis2.context.MessageContext;
+
+/*
+*
+* 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 interface AxisCallback {
+ /**
+ * This is called when we receive a message.
+ *
+ * @param msgContext the (response) MessageContext
+ */
+ void onMessage(MessageContext msgContext);
+
+ /**
+ * This gets called when a fault message is received.
+ *
+ * @param msgContext the MessageContext containing the fault.
+ */
+ void onFault(MessageContext msgContext);
+
+ /**
+ * This gets called ONLY when an internal processing exception occurs.
+ *
+ * @param e the Exception which caused the problem
+ */
+ void onError(Exception e);
+
+ /**
+ * This is called at the end of the MEP no matter what happens, quite like a finally block.
+ */
+ void onComplete();
+}
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=552328&r1=552327&r2=552328
==============================================================================
--- 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 Sun Jul 1 08:48:04 2007
@@ -4279,6 +4279,7 @@
try {
return getEnvelope().getBody().hasFault();
} catch (Exception e) {
+ // TODO: What should we be doing here? No envelope certainly seems bad....
return false;
}
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/OutInAxisOperation.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/OutInAxisOperation.java?view=diff&rev=552328&r1=552327&r2=552328
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/OutInAxisOperation.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/OutInAxisOperation.java Sun Jul 1 08:48:04 2007
@@ -28,6 +28,7 @@
import org.apache.axis2.client.Options;
import org.apache.axis2.client.async.AsyncResult;
import org.apache.axis2.client.async.Callback;
+import org.apache.axis2.client.async.AxisCallback;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.OperationContext;
@@ -109,19 +110,19 @@
}
/**
- * Adds message context to operation context , so that it will handle the
+ * Adds message context to operation context, so that it will handle the
* logic correctly if the OperationContext is null then new one will be
- * created , and Operation Context will become null when some one calls reset().
+ * created, and Operation Context will become null when some one calls reset().
*
- * @param mc
+ * @param msgContext the MessageContext to add
* @throws AxisFault
*/
- public void addMessageContext(MessageContext mc) throws AxisFault {
- mc.setServiceContext(sc);
- if (mc.getMessageID() == null) {
- setMessageID(mc);
+ public void addMessageContext(MessageContext msgContext) throws AxisFault {
+ msgContext.setServiceContext(sc);
+ if (msgContext.getMessageID() == null) {
+ setMessageID(msgContext);
}
- axisOp.registerOperationContext(mc, oc);
+ axisOp.registerOperationContext(msgContext, oc);
}
/**
@@ -142,7 +143,6 @@
this.callback = callback;
}
-
/**
* Executes the MEP. What this does depends on the specific MEP client. The
* basic idea is to have the MEP client execute and do something with the
@@ -236,6 +236,8 @@
SyncCallBack internalCallback = null;
if (callback != null) {
callbackReceiver.addCallback(mc.getMessageID(), callback);
+ } else if (axisCallback != null) {
+ callbackReceiver.addCallback(mc.getMessageID(), axisCallback);
} else {
if (log.isDebugEnabled()) {
log.debug("Creating internal callback");
@@ -275,21 +277,8 @@
mc.getConfigurationContext().registerOperationContext(mc.getMessageID(), oc);
AxisEngine.send(mc);
if (internalCallback != null) {
- long timeout = options.getTimeOutInMilliSeconds();
- synchronized (internalCallback) {
- if (!internalCallback.isComplete() && timeout >= 0) {
- try {
- internalCallback.wait(timeout);
- } catch (InterruptedException e) {
- // We were interrupted for some reason, keep waiting
- // or throw new AxisFault( "Callback was interrupted by someone?" );
- }
- if (!internalCallback.isComplete()) {
- timeOut();
- return;
- }
- }
- }
+ internalCallback.waitForCompletion(options.getTimeOutInMilliSeconds());
+
// process the result of the invocation
if (internalCallback.envelope == null) {
if (internalCallback.error == null) {
@@ -303,17 +292,10 @@
}
/**
- * If there is no response after the specified timeout interval
- * sendAync method will call this method.
- * @throws AxisFault AxisFault saying time out
- */
- protected void timeOut() throws AxisFault{
- throw new AxisFault( Messages.getMessage("responseTimeOut"));
- }
-
- /**
- * When Operation client get the response back after sending the
- * message will call this method to handle the response.
+ * When synchronous send() gets back a response MessageContext, this is the workhorse
+ * method which processes it.
+ *
+ * @param responseMessageContext the active response MessageContext
* @throws AxisFault if something went wrong
*/
protected void handleResponse(MessageContext responseMessageContext) throws AxisFault{
@@ -359,33 +341,36 @@
}
/**
- * @param msgctx
+ * Synchronously send the request and receive a response. This relies on the transport
+ * correctly connecting the response InputStream!
+ *
+ * @param msgContext the request MessageContext to send.
* @return Returns MessageContext.
* @throws AxisFault Sends the message using a two way transport and waits for a response
*/
- protected MessageContext send(MessageContext msgctx) throws AxisFault {
+ protected MessageContext send(MessageContext msgContext) throws AxisFault {
// create the responseMessageContext
MessageContext responseMessageContext =
- msgctx.getConfigurationContext().createMessageContext();
+ msgContext.getConfigurationContext().createMessageContext();
responseMessageContext.setServerSide(false);
- responseMessageContext.setMessageID(msgctx.getMessageID());
+ responseMessageContext.setMessageID(msgContext.getMessageID());
addMessageContext(responseMessageContext);
- responseMessageContext.setServiceContext(msgctx.getServiceContext());
+ responseMessageContext.setServiceContext(msgContext.getServiceContext());
responseMessageContext.setAxisMessage(
axisOp.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE));
//sending the message
- AxisEngine.send(msgctx);
+ AxisEngine.send(msgContext);
- responseMessageContext.setDoingREST(msgctx.isDoingREST());
+ responseMessageContext.setDoingREST(msgContext.isDoingREST());
- responseMessageContext.setProperty(MessageContext.TRANSPORT_IN, msgctx
+ responseMessageContext.setProperty(MessageContext.TRANSPORT_IN, msgContext
.getProperty(MessageContext.TRANSPORT_IN));
- responseMessageContext.setTransportIn(msgctx.getTransportIn());
- responseMessageContext.setTransportOut(msgctx.getTransportOut());
+ responseMessageContext.setTransportIn(msgContext.getTransportIn());
+ responseMessageContext.setTransportOut(msgContext.getTransportOut());
handleResponse(responseMessageContext);
return responseMessageContext;
}
@@ -435,27 +420,64 @@
/**
* This class acts as a callback that allows users to wait on the result.
*/
- private class SyncCallBack extends Callback {
-
- private SOAPEnvelope envelope;
+ private class SyncCallBack implements AxisCallback {
+ boolean complete;
+ boolean receivedFault;
+
+ public boolean waitForCompletion(long timeout) throws AxisFault {
+ synchronized (this) {
+ try {
+ if (complete) return !receivedFault;
+ wait(timeout);
+ if (!complete) {
+ // We timed out!
+ throw new AxisFault( Messages.getMessage("responseTimeOut"));
+ }
+ } catch (InterruptedException e) {
+ // Something interrupted our wait!
+ error = e;
+ }
+ }
- private Exception error;
+ if (error != null) throw AxisFault.makeFault(error);
+ return !receivedFault;
+ }
- public void onComplete(AsyncResult result) {
- if (log.isDebugEnabled()) {
- log.debug("Entry: OutInAxisOperationClient$SyncCallBack::onComplete");
- }
+ /**
+ * This is called when we receive a message.
+ *
+ * @param msgContext the (response) MessageContext
+ */
+ public void onMessage(MessageContext msgContext) {
// Transport input stream gets closed after calling setComplete
// method. Have to build the whole envelope including the
// attachments at this stage. Data might get lost if the input
// stream gets closed before building the whole envelope.
- this.envelope = result.getResponseEnvelope();
+ this.envelope = msgContext.getEnvelope();
this.envelope.buildWithAttachments();
- if (log.isDebugEnabled()) {
- log.debug("Exit: OutInAxisOperationClient$SyncCallBack::onComplete");
- }
}
+
+ /**
+ * This gets called when a fault message is received.
+ *
+ * @param msgContext the MessageContext containing the fault.
+ */
+ public void onFault(MessageContext msgContext) {
+ }
+
+ /**
+ * This is called at the end of the MEP no matter what happens, quite like a
+ * finally block.
+ */
+ public void onComplete() {
+ complete = true;
+ notify();
+ }
+
+ private SOAPEnvelope envelope;
+
+ private Exception error;
public void onError(Exception e) {
if (log.isDebugEnabled()) {
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=552328&r1=552327&r2=552328
==============================================================================
--- 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 Sun Jul 1 08:48:04 2007
@@ -24,6 +24,7 @@
import org.apache.axiom.soap.SOAPHeaderBlock;
import org.apache.axis2.AxisFault;
import org.apache.axis2.client.async.Callback;
+import org.apache.axis2.client.async.AxisCallback;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.OperationContext;
@@ -541,10 +542,14 @@
if (axisOperation != null) {
MessageReceiver msgReceiver = axisOperation.getMessageReceiver();
if ((msgReceiver != null) && (msgReceiver instanceof CallbackReceiver)) {
- Callback callback = ((CallbackReceiver) msgReceiver)
+ Object callback = ((CallbackReceiver) msgReceiver)
.lookupCallback(msgctx.getMessageID());
- if (callback != null) {
- callback.onError(e);
+ if (callback == null) return; // TODO: should we log this??
+
+ if (callback instanceof Callback) {
+ ((Callback)callback).onError(e);
+ } else {
+ ((AxisCallback)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=552328&r1=552327&r2=552328
==============================================================================
--- 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 Sun Jul 1 08:48:04 2007
@@ -20,12 +20,11 @@
package org.apache.axis2.util;
import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.SOAPFault;
-import org.apache.axiom.om.OMException;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.RelatesTo;
import org.apache.axis2.client.async.AsyncResult;
import org.apache.axis2.client.async.Callback;
+import org.apache.axis2.client.async.AxisCallback;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.OperationContext;
import org.apache.axis2.engine.MessageReceiver;
@@ -49,33 +48,58 @@
callbackStore.put(MsgID, callback);
}
- public Callback lookupCallback(String msgID) {
- return (Callback) callbackStore.remove(msgID);
+ public void addCallback(String msgID, AxisCallback callback) {
+ callbackStore.put(msgID, callback);
}
- public void receive(MessageContext messageCtx) throws AxisFault {
- RelatesTo relatesTO = messageCtx.getOptions().getRelatesTo();
+ public Object lookupCallback(String msgID) {
+ return callbackStore.remove(msgID);
+ }
+
+ public void receive(MessageContext msgContext) throws AxisFault {
+ RelatesTo relatesTO = msgContext.getOptions().getRelatesTo();
if (relatesTO == null) {
throw new AxisFault("Cannot identify correct Callback object. RelatesTo is null");
}
String messageID = relatesTO.getValue();
- Callback callback = (Callback) callbackStore.remove(messageID);
- AsyncResult result = new AsyncResult(messageCtx);
- if (callback == null) {
- throw new AxisFault("The Callback realtes to MessageID " + messageID + " is not found");
+ Object callbackObj = callbackStore.remove(messageID);
+
+
+ if (callbackObj == null) {
+ throw new AxisFault("The Callback for MessageID " + messageID + " was not found");
+ }
+
+ if (callbackObj instanceof AxisCallback) {
+ AxisCallback axisCallback = (AxisCallback)callbackObj;
+ if (msgContext.isFault()) {
+ axisCallback.onFault(msgContext);
+ } else {
+ axisCallback.onMessage(msgContext);
+ }
+ // Either way we're done.
+ axisCallback.onComplete();
+ return;
}
-
- // check weather the result is a fault.
+
+ // THIS NEXT PART WILL EVENTUALLY GO AWAY WHEN Callback DOES
+
+ // OK, this must be an old-style Callback
+ Callback callback = (Callback)callbackObj;
+ AsyncResult result = new AsyncResult(msgContext);
+
+ // check whether the result is a fault.
try {
SOAPEnvelope envelope = result.getResponseEnvelope();
- OperationContext opContext = messageCtx.getOperationContext();
+
+ OperationContext opContext = msgContext.getOperationContext();
if (opContext != null && !opContext.isComplete()) {
- opContext.addMessageContext(messageCtx);
+ opContext.addMessageContext(msgContext);
}
+
if (envelope.getBody().hasFault()) {
AxisFault axisFault =
- Utils.getInboundFaultFromMessageContext(messageCtx);
+ Utils.getInboundFaultFromMessageContext(msgContext);
callback.onError(axisFault);
} else {
callback.onComplete(result);
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org