This is what I have:
Code:
<bean id="alertService" class="au.com.woolworths.pwrm.ws.PwrmPortProxyFactoryBean">
<property name="serviceFactoryClass" value="org.apache.axis.client.ServiceFactory" />
<property name="wsdlDocumentUrl" value="${ws.sharedWsdlUrl}" />
<property name="namespaceUri" value="urn:icc:shared:service:wsdl" />
<property name="username" value="${ws.sharedUsername}" />
<property name="password" value="${ws.sharedPasswd}" />
<property name="serviceInterface" value="au.com.woolworths.pwrm.ws.AlertService" />
<property name="serviceName" value="AlertService" />
<property name="portName" value="AlertPort" />
<property name="stub" ref="alertBindingStub" />
</bean>
<bean id="alertBindingStub" class="au.com.woolworths.pwrm.ws.axis.alert.AlertBindingStub">
<constructor-arg>
<bean class="java.net.URL">
<constructor-arg type="java.lang.String" value="${ws.sharedBindingStubUrl}" />
</bean>
</constructor-arg>
<constructor-arg>
<bean class="org.apache.axis.client.Service" />
</constructor-arg>
</bean>
Code:
import java.rmi.Remote;
import javax.xml.rpc.Stub;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.remoting.jaxrpc.JaxRpcPortProxyFactoryBean;
public class PwrmPortProxyFactoryBean extends JaxRpcPortProxyFactoryBean {
private Stub stub;
@Required
public void setStub(Stub stub) {
this.stub = stub;
}
@Override
protected Remote getPortStub() {
try {
stub._setProperty(Stub.USERNAME_PROPERTY, getUsername());
stub._setProperty(Stub.PASSWORD_PROPERTY, getPassword());
return (Remote) stub;
} catch (Exception e) {
return null;
}
}
}
The service interface which refers to Axis-generated classes is:
Code:
import au.com.woolworths.pwrm.ws.axis.alert.AlertRequestType;
import au.com.woolworths.pwrm.ws.axis.alert.AlertResponseType;
public interface AlertService {
AlertResponseType alert(AlertRequestType alertRequestType) throws Exception;
}
To test it I created a unit test, injected the AlertService (called alertService)
Code:
@Test
public void testSendEmail() throws Exception {
AlertRequestType alertRequestType = new AlertRequestType();
alertRequestType.setTo(new String[] { "astewart@woolworths.com.au" });
alertRequestType.setFrom("astewart@woolworths.com.au");
alertRequestType.setMessage("Naim Audio. World class sound... with vision");
alertRequestType.setSubject("Message sent from PWRM SOA Module with attachments");
alertRequestType.setNotifyBy(NotificationMethodType.EMAIL);
AlertResponseType alertResponseType = alertService.alert(alertRequestType);
assertNotNull(alertResponseType);
assertNull(alertResponseType.getErrorString());
assertEquals("Mail was sent successfully.", alertResponseType.getStatus());
}
That's it!
Alan