Results 1 to 7 of 7

Thread: How can I wire the array messageSenders of a WebServiceTemplate? Do I have to?

  1. #1
    Join Date
    Apr 2008
    Posts
    19

    Question How can I wire the array messageSenders of a WebServiceTemplate? Do I have to?

    Hello everybody,

    I am trying to create a WebServiceTemplate with multiple messageSenders. I understand that some things have changed in the recent past and that (for example) the methodology suggested in the SpringInAction2 Manning book is no longer applicable.

    So I start going through the Javadoc. I see that a WebServiceTemplate inherits an array messageSenders from WebServiceAccessor, with its setter. I see that a MessageSender does no longer have a property "url", but it does have a method supports(Uri uri). I cannot see in which way the MessageSender is told which uri to communicate with, so I don't understand how supports() can give a meaningful boolean answer.

    Maybe a MessageSender can now communicate with any Uri in the world, provided it is reachable at the moment of the invocation through createConnection() or through supports(), but then why do we need an array of MessageSenders in the Accessor?

    Could anybody explain to me how the things are arranged now? Is there an example of how a MessageSender gets told which uri to speak to, or how to wire the array messageSenders of a WebServiceTemplate?

    Thanks in advance
    Marco Faustinelli - Italy

  2. #2
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    37

    Default

    I think you might be confused as to what the MessageSender is. It provides an implementation that can send the message over a particular transport. The default is the HttpUrlConnectionMessageSender which can send the message over HTTP using basic JDK methods. An alternative HTTP messageSender is CommonsHttpMessageSender which uses Jakarta Commons HTTPClient. A message sender for the JMS transport is JmsMessageSender. And so on.

    None of these have any bearing on which URI is used to access the service.

    This should be set with either the "defaultUri" property of WebServiceTemplate, or directly in the method call to one of the send methods, e.g. sendSourceAndReceiveToResult:

    Code:
    receivedResult = getWebServiceTemplate().sendSourceAndReceiveToResult(recipientNode.getUrl(), requestSource, messageCallback, result);
    More info:
    http://static.springframework.org/sp...rvice-template

  3. #3
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    37

    Default

    Seems like a misunderstood the question a bit.

    New try:

    If I look at the source for Spring WS it seems like the supports() methods for the MessageSenders simply check if the URI corresponds to a URI scheme that the sender in question knows how to connect to, for example in AbstractHttpWebServiceMessageSender:

    Code:
    public boolean supports(URI uri) {
            return uri.getScheme().equals(HttpTransportConstants.HTTP_URI_SCHEME) ||
                    uri.getScheme().equals(HttpTransportConstants.HTTPS_URI_SCHEME);
        }
    According to the Javadoc of WebServiceAccessor, the createConnection() method will iterate over the array of configured MessageSenders, calling supports() on each of them, until one returns true. It will then use that one to send the message:

    Code:
     /**
         * Creates a connection to the given URI, or throws an exception when it cannot be resolved.
         * <p/>
         * Default implementation iterates over all configured {@link WebServiceMessageSender} objects, and calls {@link
         * WebServiceMessageSender#supports(URI)} for each of them. If the sender supports the parameter URI, it creates a
         * connection using {@link WebServiceMessageSender#createConnection(URI)} .
         *
         * @param uri the URI to open a connection to
         * @return the created connection
         * @throws IllegalArgumentException when the uri cannot be resolved
         * @throws IOException              when an I/O error occurs
         */
        protected WebServiceConnection createConnection(URI uri) throws IOException {

  4. #4
    Join Date
    Apr 2008
    Posts
    19

    Default

    Thanks for thinking along once more, erimag.

    A consequence of your analysis could be that a WSTemplate could have different MessageSenders with different URI schemas (one for http, one for mailto, etc.), but I still have to understand properly what it is meant here with URI schema... I need to use different hostnames (all with http) and I cannot see exactly how these map to different uri schemas. I am checking http://en.wikipedia.org/wiki/URI_scheme

    By the way, I still don't see how to wire an uri schema into a MessageSender.

    Have a nice day,
    Marco
    Last edited by muzietto; Jun 5th, 2008 at 09:14 AM.

  5. #5
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    37

    Default

    As I understand it, a URI scheme is simply the format of the URI string, i.e. the HTTP URI scheme is simply a URI that starts with "http:", the JMS URI scheme is a URI that starts with "jms:", e-mail "mailto:" etc.

    In your case I don't think you should use more than one messagesender, since you only require http.

    And I don't think you can wire the uri scheme into a sender, it is defined in the implementation of the sender itself (more specifically, in the implementation of the supports() method as in the example above).

    If you need to connect to several different hostnames (but all through http), I think you simply need to call one of WSTemplate's send() methods several times, passing in different values for the "uri" parameter.

    Something like this:

    Code:
    for (String recipientHostname : myRecipients) {
    
      getWebServiceTemplate().sendSourceAndReceiveToResult(recipientHostname, requestSource, requestResult);
    
    }

  6. #6
    Join Date
    Apr 2008
    Posts
    19

    Default

    Thank you once more... the matter is now pretty much clear to me. With all possibilities (and limitations!).

    Marco

  7. #7
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    37

    Default

    you're welcome

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •