Announcement Announcement Module
Collapse
No announcement yet.
Simple WebServiceTemplate unable to do a SOAP call Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple WebServiceTemplate unable to do a SOAP call

    Hi,
    I am trying to use webservicetemplate to do a SOAP call. with a defaulturi specided in the spring-beans.xml.
    SOAPHandler is the client trying to make a SOAP call to the webservice.
    Request.xml is has the SOAP message.
    Webservice is running on weblogic,
    I am using JDK 1.5 and Spring WS 1.5

    Code:
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.StringReader;
    
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.transform.stream.StreamSource;
    
    import org.springframework.ws.client.core.WebServiceTemplate;
    import org.springframework.ws.transport.http.CommonsHttpMessageSender;
    
    public class SOAPHandler {
    	private static final String MESSAGE = //"Hello from BDCAS";
            "<message xmlns=\"http://tempuri.org\">Hello Web Service World</message>";
    	
        private  WebServiceTemplate webServiceTemplate ;// = new WebServiceTemplate();
    
        public void setDefaultUri(String defaultUri) {
            webServiceTemplate.setDefaultUri(defaultUri);
        }
    
        // send to the configured default URI
        public void simpleSendAndReceive() {
    //    	WebServiceMessageFactory msgFactory = webServiceTemplate.getMessageFactory();
    
        	File file = new File("schemas/Request1.xml");
        	FileInputStream in=null;
    		try {
    			in = new FileInputStream(file);
    		} catch (FileNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    
        	StreamSource source = new StreamSource(in );
            StreamResult result = new StreamResult(System.out);
            webServiceTemplate.setMessageSender(new CommonsHttpMessageSender ());
            webServiceTemplate.sendSourceAndReceiveToResult(source,result);
            
        }

    I am getting this exception, I googled for this error, could'nt find much.


    Code:
    Sep 25, 2009 1:23:28 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from file [D:\Projects\SpringUtils\properties\spring-beans.xml]
    Sep 25, 2009 1:23:29 PM org.springframework.ws.soap.saaj.SaajSoapMessageFactory afterPropertiesSet
    INFO: Creating SAAJ 1.1 MessageFactory
    Exception in thread "main" org.springframework.ws.client.WebServiceTransportException: Found [302]
    	at org.springframework.ws.client.core.WebServiceTemplate.handleError(WebServiceTemplate.java:627)
    	at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:551)
    	at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:502)
    	at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:457)
    	at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:403)
    	at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:394)
    	at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:384)
    	at com.spring.soap.SOAPHandler.simpleSendAndReceive(SOAPHandler.java:49)
    	at com.ws.LoadSpringBeans.main(LoadSpringBeans.java:21)
    Does any one know what causing the problem.

    Thanks in Advance for your Help!
    csmallela

  • #2
    The problem is with the defaultUri. Most probably you might have used a URL which redirected to another URL (http to https etc). WebServiceTemplate does not handle redirects internally, so you have to specify the correct endpoint url.

    Comment

    Working...
    X