Announcement Announcement Module
Collapse
No announcement yet.
How to set Username/Password - JaxRpcPortProxyFactoryBean Approach ?? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to set Username/Password - JaxRpcPortProxyFactoryBean Approach ??

    Hi,

    I have a webservice which has a simple username/password authentication. I am trying to add the username password based on the suggestion given
    by Mark over here (http://cse-mjmcl.cse.bris.ac.uk/blog...165512463.html)
    but it is throwing me SOAPFault Exception.

    <beans default-autowire="byName">
    <bean id="loginService"
    class="webservices.LoginProxyFactoryBean">

    <property name="serviceFactoryClass">
    <value>org.apache.axis.client.ServiceFactory</value>
    </property>

    <property name="wsdlDocumentUrl">
    <value>
    http://<remoteserver>:30080/WebService.Login.asmx?WSDL
    </value>
    </property>

    <property name="namespaceUri">
    <value>
    WebService.Login
    </value>
    </property>

    <property name="serviceName">
    <value>Login</value>
    </property>

    <property name="portName">
    <value>LoginSoap</value>
    </property>

    <property name="portInterface">
    <value>webservices.login.LoginSoap</value>
    </property>

    <property name="serviceInterface">
    <value>webservices.Login</value>
    </property>

    <property name="username">
    <value>foo</value>
    </property>

    <property name="password">
    <value>bar</value>
    </property>

    </bean>


    Here is the my LoginProxyFactoryBean

    public class LoginProxyFactoryBean extends JaxRpcPortProxyFactoryBean {

    protected void postProcessJaxRpcService(Service service) {
    TypeMappingRegistry registry = service.getTypeMappingRegistry();
    TypeMapping mapping = registry.createTypeMapping();

    // registry.register("", mapping);
    registry.registerDefault(mapping);
    }

    protected void registerBeanMapping(TypeMapping mapping, Class type, String name) {
    QName qName = new QName("WebService.Login", name);
    mapping.register(type, qName,
    new BeanSerializerFactory(type, qName),
    new BeanDeserializerFactory(type, qName));
    }


    Any suggestions as to how do I go about this ?

    Thank you in advance !

  • #2
    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[] { "[email protected]" });
    		alertRequestType.setFrom("[email protected]");
    		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
    Last edited by Alan Stewart; Feb 5th, 2008, 12:54 AM.

    Comment


    • #3
      Hi Alan,

      The webservice I was trying to invoke was using windows digest authentication (so you would be prompted for a username and password even to read the WSDL) and my code was failing at the part where Axis tries to parse the WSDL itself. So, I think Spring tries to parse the wsdl before it even sets the username and password for the actual invocation. So, in order to solve this problem, I just downloaded the wsdl locally and put it in the classpath so that Spring could read it from there instead of going through authentication at the remote. Also overriding the afterPropertiesSet() method would also help in setting the username/password dynamically for the web service invocation instead of setting in the config file.

      public void afterPropertiesSet() {
      this.setUsername("username");
      this.setPassword("password");
      super.afterPropertiesSet();
      }

      Thanks once again for your help !

      -Jilani

      Comment


      • #4
        Originally posted by coolj View Post
        Hi Alan,

        So, I think Spring tries to parse the wsdl before it even sets the username and password for the actual invocation.
        Thanks once again for your help !

        -Jilani
        From memory, this is why I had to override the JaxRpcPortProxyFactoryBean (see above) to set the username and password.
        Alan

        Comment


        • #5
          Overriding the JaxRpcPortProxyFactoryBean won't fix it. I was able to get around this problem only when I had stored the WSDL locally instead of at the remote location (which requires username/password). The approach you mentioned would work once you are able to parse the WSDL and need a username/password for web service invocation.

          Comment

          Working...
          X