Announcement Announcement Module
Collapse
No announcement yet.
Why is my webservice throwing me null pointer exception? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why is my webservice throwing me null pointer exception?

    Hi!
    Im writing a webservice client with spring-ws
    so in my main Ive:
    Code:
    import java.math.BigInteger;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import org.springframework.ws.client.core.WebServiceTemplate;
    
    import com.wordpress.ankeetmaini.spring_ws2_square.ObjectFactory;
    import com.wordpress.ankeetmaini.spring_ws2_square.SquareServiceRequest;
    import com.wordpress.ankeetmaini.spring_ws2_square.SquareServiceResponse;
    
    public class Main {
    
    	/**
    	 * @param args
    	 */
    
    	@Autowired
    	private static WebServiceTemplate webServiceTemplate;
    
    	private static ClassPathXmlApplicationContext context = null;
    
    	public static void main(String[] args) {
    		context = new ClassPathXmlApplicationContext("/META-INF/application.xml");
    
    		//Creating the SquareServiceResponse object.
    		SquareServiceResponse squareServiceResponse = new ObjectFactory().createSquareServiceResponse();
    		//Sending the request object via WebServiceTemplate and getting back the response from WebService :)
    		SquareServiceRequest squareServiceRequest = new SquareServiceRequest();
    		BigInteger value = new BigInteger("5");
    		squareServiceRequest.setInput(value);
    		squareServiceResponse = (SquareServiceResponse) webServiceTemplate.marshalSendAndReceive(squareServiceRequest);
    		System.out.println("Respuesta: " + squareServiceResponse);
    	}
    
    }
    and in my context Ive:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:sws="http://www.springframework.org/schema/web-services"
    	xmlns:p="http://www.springframework.org/schema/p"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans
    	   		http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    	   		http://www.springframework.org/schema/context
    	   		http://www.springframework.org/schema/context/spring-context-3.0.xsd
    	   		http://www.springframework.org/schema/web-services
    			http://www.springframework.org/schema/web-services/web-services-2.0.xsd">
    
    
    	<!-- Activates various annotations to be detected in bean classes -->
    	<context:annotation-config />
    
    	<!-- Scans the classpath for annotated components that will be auto-registered
    		as Spring beans. For example @Controller and @Service. Make sure to set the
    		correct base-package -->
    	<context:component-scan base-package="ankeet.spring" />
    	<context:component-scan base-package="com.wordpress" />
    
    	<!-- Configures the annotation-driven Spring MVC Controller programming
    		model. Note that, with Spring 3.0, this tag works in Servlet MVC only! -->
    
    	<!-- Declare a view resolver -->
    <!-- 	<bean id="viewResolver"
    		class="org.springframework.web.servlet.view.InternalResourceViewResolver"
    		p:prefix="/WEB-INF/views/" p:suffix=".jsp" /> -->
    
    	 	<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate"
    		p:marshaller-ref="jaxbMarshaller"
    		p:unmarshaller-ref="jaxbMarshaller"
    		p:defaultUri="http://localhost:9080/spring-ws2-exemplary/squareService"
    		p:messageSender-ref="messageSender">
    		<constructor-arg ref="messageFactory"/>
    	</bean>
    	<bean id="messageSender" class="org.springframework.ws.transport.http.CommonsHttpMessageSender"/>
    	<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
    	<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"
    		p:contextPath="com.wordpress.ankeetmaini.spring_ws2_square"/>
    
    </beans>
    So when I run it I get a nullpointerexception in
    Code:
    		squareServiceResponse = (SquareServiceResponse) webServiceTemplate.marshalSendAndReceive(squareServiceRequest);
    my webservice is running since I opened the wsdl with success.

    So why am I getting the nullpointerexception?

    Thanks in advance.
Working...
X