You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by "Merritt, Norris" <no...@hp.com> on 2007/09/26 20:35:00 UTC

Reusing an Axis2 OperationClient -- how, exactly?? Does anyone have a non-trivial OperationClient sample?

I have been trying without success to reuse an OperationClient to send
multiple messages without having to reconstruct the OperationClient,
ServiceClient, and related objects for each message transmission.  I am
pursuing this as part of an effort to get my client to reuse the same
HTTPS connection for multiple message exchanges, since I don't want the
overhead of SSL handshake on every exchange, and I can't see how I could
possibly accomplish this if I am building the OperationClient from
scratch for each message exchange. 

 

My OperationClient is patterned after the "scenario6Client.java" sample
I found here:
http://today.java.net/today/2006/12/13/invoking-web-services-using-apach
e-axis2.zip

 

The sample works for multiple sends only if I execute all of the code
(recreate the entire client) for each SOAP message I send. But if I try
to send a second message with the same client, when I call execute( )  I
get an exception with the message "The message exchange pattern (MEP) is
already complete. Use the reset method before re-running."  

 

The OperationClient.reset() method Javadoc says:

 

OperationClient.reset
<http://ws.apache.org/axis2/1_1/api/org/apache/axis2/client/OperationCli
ent.html#reset()> () 
          Reset the operation client to a clean status after the MEP has
completed.

 

 

OK, sounds reasonable, but if I call the reset() method on the
OperationClient immediately following a successful message exchange, the
next time I try to do a send, I get a java.lang.NullPointerException at
org.apache.axis2.description.OutInAxisOperationClient.getMessageContext(
OutInAxisOperation.java:136) when I try to retrieve the MessageContext
to set the soap envelope in it for the next outgoing request:

 

      MessageContext msgCtx = operationClient.getMessageContext("Out");
<==== blows up here with NPE on second request if reset() was done

      

That line of code executed fine for the first send, so I assume that
reset() blows away the message context and I need to add a new one. So I
add a couple lines of code to create a new MessageContext and add it to
the OperationClient, exactly as I did before the first call, immediately
following the reset():

 

      operationClient.reset();

      

      MessageContext msgCtxNew = new MessageContext();

      operationClient.addMessageContext(msgCtxNew);          <==   Now
it blows up here with NPE

 

But this causes it to blow up on the operationClient.addMessageContext(
) call:

 

java.lang.NullPointerException

            at
org.apache.axis2.context.ConfigurationContext.registerOperationContext(C
onfigurationContext.java:229)

            at
org.apache.axis2.description.AxisOperation.registerOperationContext(Axis
Operation.java:396)

            at
org.apache.axis2.description.OutInAxisOperationClient.addMessageContext(
OutInAxisOperation.java:122)

 

My guess is registerOperationContext is failing because of a null
OperationContext in mepContext:

 

    public boolean registerOperationContext(String messageID,

                                            OperationContext mepContext)
{

        boolean alreadyInMap;

        mepContext.setKey(messageID);   

 

So does the reset() operation blow away the OperationContext too?  Do I
have to construct one of these with some factory now, just because I
want to send a second message, when I didn't even have to know this
object existed to send the first message?  I really don't get this
api....