1 Reply Latest reply on Jul 17, 2006 4:18 PM by Heiko Braun

    can not get user and password from header

    Patrick Kostka Newbie

      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)
       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)
       return true;

      And I put this to webservices.xml (in port-component tag):

      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);
       String result = (String) call.invoke(new Object[] {"String1","String2"});
       System.out.println("output:" + result);
       catch( IOException ioe )

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