I am stuck in this problem don't know what I am doing wrong. I am consuming the SOAPWS & when I call that webservice it gives exception & i checked that WebServiceTemplate object is null but once it got initialized in the constructor. At the moment it enters into the sendNpsReminder operation it sets to null. don't know why. Can someone please help.
Pom.Xml
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
JavaClass:
public class ManageCustomerService extends WebServiceGatewaySupport {
private static final CDLoggerInterface logger = CDLogger
.getLogger(ManageCustomerService.class);
private WebServiceTemplate manageContactsWSTemplate;
public ManageCustomerService()
{
}
public ManageCustomerService(WebServiceTemplate manageContactsWSTemplateObj) {
this.manageContactsWSTemplate = manageContactsWSTemplateObj;
logger.debug("Constructor Setting the WebServieTemplte "+manageContactsWSTemplate);
}
public SendNPSReminderResponseType sendNpsReminder() {
logger.debug("Calling now with new JOB="+manageContactsWSTemplate);
SendNPSReminderRequestType sendNPSReminderRequest = new SendNPSReminderRequestType();
Contact Contact = new Contact();
Contact.setPhone(new BigInteger("XYZ"));
sendNPSReminderRequest.setCountryCode(ABC);
sendNPSReminderRequest.setContact(Contact);
sendNPSReminderRequest.setCustomerNumber("23239220");
if(manageContactsWSTemplate != null)
{
SendNPSReminderResponseType response = (SendNPSReminderResponseType)manageContactsWSTemplate.marshalSendAndReceive("http://tsi-vip-osbdev.canaldigital.com:7111//GSD_ManageCustomer_v2/ProxyService/Proxy/GSD_ManageCustomer_PS?wsdl", sendNPSReminderRequest, new SoapActionCallback("http://canaldigital.com/tsi/Schema/GSD/GSD_ManageCustomer/v2/GSD_ManageCustomer_SendNPSReminder"));
logger.info("Response for SendNpsReminder is : "+response.getResponseCode());
}
else{
logger.debug("manageContactsWSTemplate is null");
}
return xyz;
}
ApplicationContext.xml
<oxm:jaxb2-marshaller id="manageContactMarshaller"
contextPath="packagename" />
<oxm:jaxb2-marshaller id="manageContactUnmarshaller"
contextPath="packagename" />
<bean name="manageContactsWSTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<constructor-arg ref="messageFactory" />
<property name="defaultUri" value="http://tsi.com:7111/GSD_ManageCustomer_v1?WSDL" />
<property name="marshaller" ref="manageContactMarshaller" />
<property name="unmarshaller" ref="manageContactUnmarshaller" />
</bean>
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
</bean>
<bean id="manageContactService" class="com.canaldigital.tsi.managecontacts.serviceprovider.ManageCustomerService">
<constructor-arg ref="manageContactsWSTemplate" />
</bean>
<bean id="CDCommonTasksJob"
class="com.canaldigital.tsi.managecontacts.serviceprovider.ManageCustomerService">
</bean>
<!-- Scheduler -->
<task:scheduled-tasks>
<task:scheduled ref="CDCommonTasksJob" method="sendNpsReminder"
cron="0 0/2 * * * *" />
</task:scheduled-tasks>
From your spring-context .xml it looks like you are requesting 2 beans of the same class :ManageCustomerService , the first one will be called through the constructor and will have the a valid spring bean as the WebServiceTemplate , but the second one (CDCommonTasksJob) will be called with the default constructor , thus the reference to WebServiceTemplate will be null. So in your task scheduler , you autowire the bean which do not have a webServiceTemplate instance
So the question is , why you want to create two beans of the same class ?
In case you still need two beans just replace the line
<bean id="CDCommonTasksJob"
class="com.canaldigital.tsi.managecontacts.serviceprovider.ManageCustomerService">
</bean>
With :
<bean id="CDCommonTasksJob" class="com.canaldigital.tsi.managecontacts.serviceprovider.ManageCustomerService">
<constructor-arg ref="manageContactsWSTemplate" />
</bean>