xml-soap-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steven J. McDowall" <sjmcdow...@uswest.net>
Subject RE: Decoupling of Call
Date Tue, 01 Aug 2000 23:07:04 GMT

Wouter,

You have a valid point, and your ideas are probably a much
better overall plan in general, as well an Sanjiva's idea
of some "messaging" abstraction (which seems sort of vague.. )

However, the reason I made the changes and suggested them is because
even within the aspect of an RPC situation, there was too little
flexibility .. For example, not being able to modify or even submit
my own built SOAP envelope to the send() routine, etc. Everything
was "automagic" ..

So, I figured a little decomposition which allowed flexibility in the
short run was a good thing.. I also figured that there wasn't going to
be ANY sort of changes that you opined about anytime soon and that
flexibility in the short-term was worth more than purity (or hoped for
purity) months from now.. :-)

So, I agree that my decomposition of Call is hardly the optimal solution
we want long term, but it may be more useful than nothing..

-Steve

P.S. As for a use case where you may just want to listen? How about
having some sort of async. server that, after sending a message, needs
to wait on multiple events.. and if the socket gets it (with the response)
wants to receive() that message..


-----Original Message-----
From: Wouter Cloetens [mailto:wcloeten@raleigh.ibm.com]
Sent: Tuesday, August 01, 2000 6:27 AM
To: soap-dev@xml.apache.org
Subject: Decoupling of Call


On Thu, 27 Jul 2000 16:51:44 -0500, Steven J. McDowall wrote:

>3) The current encapsulation is horrid in that it your are very much
>locked into the "invoke" logic with very little (basically none) ability
>to change its style.. / methodology, etc.
>5) The code changes are DONE fer-gods-sakes.. And tested against all the
>demo's and some other hand-rolled stuff..

I'm not sure I agree completely with the implementation of those changes.
It's still very
much stuck on the RPC paradigm, rather than messaging. For example, you've
put
everything in Call, even receive(), generating a Response object. I can't
map the case
where I simply want to listen for a message into that. That's not just an
issue with the
design of the rpc package; SOAPTransport lacks support too.

To clarify... This can be for the existing RPC situation inside rpcrouter.
Why would *it*
have to build the whole Call object? Why not extend the HTTP transport type
(SOAPHTTPConnection, or maybe a new SOAPHTTPServer class) to which the
servlet/jsp can pass the request and response objects, or maybe the headers,
the
InputStream and OutputStream?

Or, when using a transport type that allows for a unidirectional message to
be sent (mail
or messaging middleware) which doesn't necessarily fit either the "Call" or
"Response"
model (maybe that should be supported by "RPCMessage" or a new "Datagram"
class
or something). That type of message may not always be received by an HTTP
bridge
program. The target may just want the message directly - no RPC routing
required. The
design of SOAPTransport (and therefore Call) assumes that send() will be
invoked first,
and that will do all the work. receive() is just there to actually get the
response if you want
it. You can't get it to, for instance, receive a message from a servlet
request, a queue, a
mail server, a publish/subscribe topic...
Fortunately, you did implement a responseFromReader() and
responseFromString()
which at least takes some of the effort out of it.

A JMS implementation of SOAP sounds better every day. :-)

Oh just ignore my rant. We'll fix it in a future version. I support your
change for the current
release. Here's a patch that's identical to your version, with the addition
of being able to call
send() without a call envelope and/or without headers.

bfn, Wouter

--- xml-soap/java/src/org/apache/soap/rpc/Call.java.orig	Tue May 30 05:24:00
2000
+++ xml-soap/java/src/org/apache/soap/rpc/Call.java	Tue Aug  1 17:20:22 2000
@@ -80,82 +80,61 @@
  */
 public class Call extends RPCMessage
 {
-  private XMLParserLiaison    xpl = new XercesParserLiaison();
-  private SOAPMappingRegistry smr = new SOAPMappingRegistry();
-  private SOAPTransport       st  = new SOAPHTTPConnection();
+  private XMLParserLiaison    xpl = new XercesParserLiaison ();
+  private SOAPMappingRegistry smr = new SOAPMappingRegistry ();
+  private SOAPTransport       st  = new SOAPHTTPConnection ();

-  public Call()
+  public Call ()
   {
-    this(null, null, null, null, null);
+    this (null, null, null, null, null);
   }

-  public Call(String targetObjectURI, String methodName, Vector params,
-              Header header, String encodingStyleURI)
+  public Call (String targetObjectURI, String methodName, Vector params,
+               Header header, String encodingStyleURI)
   {
-    super(targetObjectURI, methodName, params, header, encodingStyleURI);
+    super (targetObjectURI, methodName, params, header, encodingStyleURI);
   }

-  public void setSOAPMappingRegistry(SOAPMappingRegistry smr)
+  public void setSOAPMappingRegistry (SOAPMappingRegistry smr)
   {
     this.smr = smr;
   }

-  public SOAPMappingRegistry getSOAPMappingRegistry()
+  public SOAPMappingRegistry getSOAPMappingRegistry ()
   {
     return smr;
   }

-  public void setSOAPTransport(SOAPTransport st)
+  public void setSOAPTransport (SOAPTransport st)
   {
     this.st = st;
   }

-  public SOAPTransport getSOAPTransport()
+  public SOAPTransport getSOAPTransport ()
   {
     return st;
   }

-  public Envelope buildEnvelope()
+  public Envelope buildEnvelope ()
   {
-    return super.buildEnvelope(false);
+    return super.buildEnvelope (false);
   }

-  public static Call extractFromEnvelope(Envelope env, ServiceManager
svcMgr)
+  public static Call extractFromEnvelope (Envelope env, ServiceManager
svcMgr)
     throws IllegalArgumentException
   {
-    return (Call)RPCMessage.extractFromEnvelope(env, svcMgr, false, null);
+    return (Call)RPCMessage.extractFromEnvelope (env, svcMgr, false, null);
   }

   /**
-   * Invoke this call at the specified URL. Valid only on the client side.
+   * Return the main element (unmarshalled) given the payload
    */
-  public Response invoke(URL url, String SOAPActionURI) throws
SOAPException
+  public Element getElementFromString (String payloadStr)
+      throws SOAPException
   {
-    if (SOAPActionURI == null)
-    {
-      SOAPActionURI = "";
-    }
-
-    try
-    {
-      // Build an envelope containing the call.
-      Envelope callEnv = buildEnvelope();
-
-      // Post the call envelope.
-      st.send(url, SOAPActionURI, null, callEnv, smr);
-
-      // Get the input stream to read the response envelope from.
-      BufferedReader in = st.receive();
-
-      /*
-        Must pre-read the incoming stream to avoid the parser drying up
-        the stream in case a parsing error occurs.
-      */
-      String payloadStr = IOUtils.getStringFromReader(in);
-
       // Parse the incoming response stream.
-      Document respDoc = xpl.read("- SOAP HTTP RPC Response Envelope -",
-                                  new StringReader(payloadStr));
+      Document respDoc = xpl.read ("- SOAP HTTP RPC Response Envelope -",
+                                   new StringReader(payloadStr));
       Element payload = null;

       if (respDoc != null)
@@ -164,26 +143,152 @@
       }
       else
       {
-        throw new SOAPException(Constants.FAULT_CODE_PROTOCOL,
-                                payloadStr);
+        throw new SOAPException (Constants.FAULT_CODE_PROTOCOL,
+                                 payloadStr);
       }

+      return payload;
+  }
+
+  /**
+   * Parse a response given a streaming reader..
+   */
+  public String getPayloadFromReader (BufferedReader in)
+      throws SOAPException
+  {
+      /*
+       Must pre-read the incoming stream to avoid the parser drying up
+       the stream in case a parsing error occurs.
+      */
+      String payloadStr;
+      try
+      {
+          payloadStr = IOUtils.getStringFromReader (in);
+      }
+      catch (IOException e)
+      {
+          throw new SOAPException (Constants.FAULT_CODE_PROTOCOL,
+                                   e.getMessage (), e);
+      }
+
+      return payloadStr;
+  }
+
+  /**
+   * Parse a response given a streaming reader.
+   */
+  public Response responseFromReader (BufferedReader in)
+      throws SOAPException
+  {
+      /*
+       Must pre-read the incoming stream to avoid the parser drying up
+       the stream in case a parsing error occurs.
+       */
+      String payloadStr = getPayloadFromReader (in);
+
+      Response resp = responseFromString (payloadStr);
+
+      return resp;
+  }
+
+  /**
+   * Parse a response given a payload string of the whole thing.
+   */
+  public Response responseFromString (String payloadStr)
+      throws SOAPException
+  {
+      // Extract the main body element (which should be the SOAP Envelope)
+      // from the response payload
+      Element payload = getElementFromString (payloadStr);
+
       // Unmarshall the response envelope.
-      Envelope respEnv = Envelope.unmarshall(payload);
+      Envelope respEnv = Envelope.unmarshall (payload);

       // Extract the response from the response envelope.
-      Response resp = Response.extractFromEnvelope(respEnv, smr);
+      Response resp = Response.extractFromEnvelope (respEnv, smr);
+
+      return resp;
+  }
+
+  /**
+   * Create a SOAP request and send it down the pipe.
+   */
+  public void send (URL url, String SOAPActionURI, Hashtable headers,
+                    Envelope callEnv) throws SOAPException
+  {
+      if (SOAPActionURI == null)
+      {
+          SOAPActionURI = "";
+      }
+      try
+      {
+          // Post the call envelope.
+          st.send (url, SOAPActionURI, headers, callEnv, smr);
+      }
+      catch (IllegalArgumentException e)
+      {
+          throw new SOAPException(Constants.FAULT_CODE_CLIENT,
e.getMessage(),
+                                  e);
+      }
+  }
+
+  /**
+   * Build envelope and send message.
+   */
+  public void send (URL url, String SOAPActionURI, Hashtable headers)
+      throws SOAPException
+  {
+      // Build an envelope containing the call.
+      Envelope callEnv = buildEnvelope();
+
+      send (url, SOAPActionURI, headers, callEnv);
+  }
+
+  /**
+   * Build envelope and send message. This version requires no headers.
+   */
+  public void send (URL url, String SOAPActionURI)
+      throws SOAPException
+  {
+      send (url, SOAPActionURI, null);
+  }
+
+  /**
+   * Receive response.
+   */
+  public Response receive() throws SOAPException
+  {
+      // Get the input stream to read the response envelope from.
+      BufferedReader in = st.receive();
+
+      // Parse the response and send the result back
+      Response resp = responseFromReader(in);
+      return resp;
+  }
+
+  /**
+   * Invoke this call at the specified URL. Valid only on the client side.
+   * This version allows the optional headers to be specified.
+   */
+  public Response invoke(URL url, String SOAPActionURI, Hashtable headers)
+      throws SOAPException
+  {
+      // Build an envelope containing the call.
+      Envelope callEnv = buildEnvelope();
+
+      send(url, SOAPActionURI, headers, callEnv);
+
+      Response resp = receive();

       return resp;
-    }
-    catch (IllegalArgumentException e)
-    {
-      throw new SOAPException(Constants.FAULT_CODE_CLIENT, e.getMessage(),
e);
-    }
-    catch (IOException e)
-    {
-      throw new SOAPException(Constants.FAULT_CODE_PROTOCOL,
-                              e.getMessage(), e);
-    }
+  }
+
+  /**
+   * Invoke this call at the specified URL. Valid only on the client side.
+   */
+  public Response invoke(URL url, String SOAPActionURI)
+      throws SOAPException
+  {
+      return invoke (url, SOAPActionURI, null);
   }
 }





Mime
View raw message