[jboss-user] [JBossWS] - can not get user and password from header

pkroman do-not-reply at jboss.com
Wed Jul 12 09:16:46 EDT 2006


Hallo. I have written a simple WebService called TrivialService
on JBoss 4.0.4:

package org.jboss.test.ws.samples.rpcstyle;
  | import java.rmi.Remote;
  | import java.rmi.RemoteException;
  | public interface TrivialService extends Remote
  | {
  |       String request(String string1, String string2) throws RemoteException;
  | }

package org.jboss.test.ws.samples.rpcstyle;
  | import javax.xml.namespace.QName;
  | public class TrivialEndpoint implements TrivialService
  |   {
  |      public String request(String string1, String string2)
  |      {
  |         return "ok " + string1 + " " + string2;
  |      }
  |   }


Then I have written a handler to have access to the user and password within the header:

package org.jboss.test.ws.samples.rpcstyle;
  | import java.io.File;
  | import java.io.FileInputStream;
  | import java.io.IOException;
  | import java.io.InputStream;
  | import java.util.Iterator;
  | import javax.xml.namespace.QName;
  | import javax.xml.rpc.JAXRPCException;
  | import javax.xml.rpc.handler.*;
  | import javax.xml.rpc.handler.soap.SOAPMessageContext;
  | import javax.xml.soap.*;
  | public class ServerSideHandler extends GenericHandler
  | {
  | 	protected QName[] headers = new QName[]
  | 	  {
  | 	  };
  | 
  | 	  public QName[] getHeaders()
  | 	  {
  | 	     String NAMESPACE = "http://org.jboss.ws/samples/rpcstyle";
  | 	     QName SERVICE_NAME = new QName NAMESPACE,"TrivialService");
  | 	     QName[] qNames = {SERVICE_NAME};
  | 	     return qNames;
  | 	  }
  | 
  | 	   public boolean handleRequest(MessageContext msgContext)
  | 	   {
  | 	      System.out.print("handleRequeste");
  |       	      String user = (String) msgContext.getProperty("USERNAME_PROPERTY");
  | 	    	 String password = (String) msgContext.getProperty("PASSWORD_PROPERTY");
  | 		 System.out.print("user: " + user);
  | 		 System.out.print("password: " + password);
  | 
  | 	        return super.handleRequest(msgContext);
  | 	   }
  | 
  | 	   public boolean handleResponse(MessageContext msgContext)
  | 	   {
  | 	      System.out.print("handleResponse");
  | 	      return true;
  | 	   }
  | }

And I put this to webservices.xml (in port-component tag):
   <handler>
  | 	   <handler-name>ServerSideHandler</handler-name>
  | 	   <handler-class>org.jboss.test.ws.samples.rpcstyle.ServerSideHandler</handler-class>
  |    </handler>

This is my service client for invoking the service.
package org.jboss.test.ws.samples.client;
  | import java.io.IOException;
  | import java.net.URL;
  | import javax.xml.namespace.QName;
  | import javax.xml.rpc.Call;
  | import javax.xml.rpc.ParameterMode;
  | import javax.xml.rpc.Service;
  | import javax.xml.rpc.ServiceFactory;
  | import javax.xml.rpc.Stub;
  | import com.sun.org.apache.bcel.internal.Constants;
  | 
  | public class Client
  | {
  |     public static void main(String[] args) throws Exception
  |     {
  | String urlstr = "http://pc0104-129:8080/TrivialService?wsdl";
  | 		URL url =  new URL(urlstr);
  | 
  | 		String ns        = "http://org.jboss.ws/samples/rpcstyle";		
  | 		QName  qname     = new QName(ns, "TrivialService");				
  | QName  port      = new QName(ns, "TrivialServicePort");	
  | 		QName  operation = new QName(ns, "request");					
  | 
  | 		ServiceFactory factory = ServiceFactory.newInstance();
  | 		Service        service = factory.createService(url, qname);
  | 		Call           call    = service.createCall(port, operation);
  | 		try
  | 		{
  | 			call.setProperty(Call.USERNAME_PROPERTY,"user");
  | 			call.setProperty(Call.PASSWORD_PROPERTY,"password");
  | 			String result = (String) call.invoke(new Object[] {"String1","String2"});
  | 			System.out.println("output:" + result);
  | 		}
  | 	    catch( IOException ioe )
  | 	    {
  | 	         ioe.printStackTrace();
  | 	         System.out.println(ioe.getMessage());
  | 	         System.out.println(ioe.getCause().getMessage());
  | 	         System.out.println(ioe.getCause().getLocalizedMessage());
  | 	    }
  |     }
  | }

After I have invoked the service the handler printed null for the user and password. Could somebody tell me what is wrong?

Greetings,
patrick

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3957353#3957353

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3957353



More information about the jboss-user mailing list