Results 1 to 3 of 3

Thread: ws outbound has a bad webserviceTemplate

  1. #1
    Join Date
    Apr 2010
    Posts
    11

    Default ws outbound has a bad webserviceTemplate

    In the ws outbound gateway ,the AbstractWebServiceOutboundGateway use a WebServiceTemplate to send and receive soapmessages.
    But i find a problem ,When using WebServiceTemplate to send soapmessage to a same uri,every time it creates a new WebServiceConnection .
    So if i send 10000 times soap message to a same uri 'http://localhost:8080/echo/echoService',the method createConnection() is invoked 10000 times.
    But i want it just invokes the method createConnection() one time ,not 10000 times.
    Is this the WebServiceTemplate bug ?

    the WebServiceTemplate code is :
    connection = createConnection(URI.create(uriString));

    Code:
    public Object sendAndReceive(String uriString, WebServiceMessageCallback requestCallback,
    			WebServiceMessageExtractor responseExtractor) {
    		Assert.notNull(responseExtractor, "'responseExtractor' must not be null");
    		Assert.hasLength(uriString, "'uri' must not be empty");
    		TransportContext previousTransportContext = TransportContextHolder.getTransportContext();
    		WebServiceConnection connection = null;
    		try {
    			connection = createConnection(URI.create(uriString));//<--- this is here
    			TransportContextHolder.setTransportContext(new DefaultTransportContext(connection));
    			MessageContext messageContext = new DefaultMessageContext(getMessageFactory());
    			
    			return doSendAndReceive(messageContext, connection, requestCallback, responseExtractor);
    		} catch (TransportException ex) {
    			throw new WebServiceTransportException("Could not use transport: " + ex.getMessage(), ex);
    		} catch (IOException ex) {
    			throw new WebServiceIOException("I/O error: " + ex.getMessage(), ex);
    		} finally {
    			TransportUtils.closeConnection(connection);
    			TransportContextHolder.setTransportContext(previousTransportContext);
    		}
    	}

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,631

    Default

    Please don't repost/post duplicates.

    No it isn't a bug it is by design. WebServicesTemplate is threadsafe (you could use 1 instance through out your whole application) if the connection would remain open/cached it wouldn't be threadsafe anymore.

    Nor are HttpConnection meant to keep open, they will (eventually) time-out.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Apr 2010
    Posts
    11

    Default

    Thanks,Marten.

Tags for this Thread

Posting Permissions

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