0 Replies Latest reply on Jul 31, 2006 2:38 PM by shadens

    HandlerRegistry... why not ?

    shadens

      Ok, I understand that JBossWs Staff loves J2EE client.
      But, I remember that J2SE client also exists in this world. Unfortunately, I have to work with last kind of client.

      In your opinion, if I would to create a client standalone (example, with Swing style) that connect to a "pinco-pallino" web service (in a security way), which Saint I must call?
      Do I have to send also AS within client?!! O_o

      Ok, sorry about my outlet, but I'm going mad. Now, my question:

      I try to add a handler to a DII client. I obtain this error:

      Exception in thread "main" java.lang.UnsupportedOperationException: Components should not use the getHandlerRegistry() method.
      at org.jboss.ws.jaxrpc.ServiceImpl.getHandlerRegistry(ServiceImpl.java:253)
      at src.client.ClientTime.main(ClientTime.java:46)


      So, what could I use?
      My DII client:

      package src.client;
      
      import src.client.MyHandler;
      
      
      import java.rmi.RemoteException;
      import java.util.List;
      
      import javax.xml.rpc.Service;
      import javax.xml.rpc.ServiceException;
      import javax.xml.rpc.ServiceFactory;
      import javax.xml.rpc.Call;
      
      import javax.xml.namespace.QName;
      import javax.xml.rpc.ParameterMode;
      
      
      import javax.xml.rpc.handler.HandlerInfo;
      import javax.xml.rpc.handler.HandlerRegistry;
      
      import javax.xml.rpc.soap.SOAPFaultException;
      
      
      
      /** This is a DII Client
       * 28-07-2006
       * **/
      
      public class ClientTime {
      
       private static String endpoint = "http://pc3000:8080/July-EjbWs-181/TimeBean";
       private static String qnameService = "WhatTime";
       private static String qnamePort = "EndpointInterface";
       private static String BODY_NAMESPACE_VALUE = "http://is.time.it/";
       private static String ENCODING_STYLE_PROPERTY = "javax.xml.rpc.encodingstyle.namespace.uri";
       private static String NS_XSD = "http://www.w3.org/2001/XMLSchema";
       private static String URI_ENCODING = "http://schemas.xmlsoap.org/soap/encoding/";
      
      
      
       public static void main(String[] args) {
       try {
       ServiceFactory factory = ServiceFactory.newInstance();
       Service service = factory.createService(new QName(qnameService));
      
       HandlerRegistry registry = service.getHandlerRegistry();
      
       QName port = new QName(qnamePort);
      
       List handlerChain = registry.getHandlerChain(port);
       HandlerInfo handlerInfo = new HandlerInfo();
       handlerInfo.setHandlerClass(MyHandler.class);
       handlerChain.add(handlerInfo);
      
       //create JAX-RPC Call using JAX-RPC Service's createCall() method.
       Call call = service.createCall(port);
      
       // Configure your Call instance with its setter methods
       call.setTargetEndpointAddress(endpoint);
       call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
       call.setProperty(Call.SOAPACTION_URI_PROPERTY, "");
       call.setProperty(ENCODING_STYLE_PROPERTY, URI_ENCODING);
       QName QNAME_TYPE_STRING = new QName(NS_XSD, "string");
       call.setOperationName(new QName(BODY_NAMESPACE_VALUE, "whatTimeIsIt"));
       call.setReturnType(QNAME_TYPE_STRING);
      
       call.addParameter("String_1", QNAME_TYPE_STRING, ParameterMode.IN);
       String[] params = { "Dr. Emmet Brown " };
      
       // Invoke the WS operation using the JAX-RPC Call's invoke method
       String result = (String) call.invoke(params);
      
       System.out.println(result);
      
       } catch (SOAPFaultException ex) {
       System.out.println("Error about Soap messages.");
       ex.printStackTrace();
       } catch (RemoteException e) {
       System.out.println("Errore sulla call.invoke");
       e.printStackTrace();
       } catch (ServiceException e) {
       System.out.println("Errore sulla Service o createService");
       e.printStackTrace();
       }
       }
      
      
      
      }
      


      My Handler class:

      package src.client;
      
      import javax.xml.namespace.QName;
      import javax.xml.rpc.handler.GenericHandler;
      import javax.xml.rpc.handler.MessageContext;
      import javax.xml.rpc.handler.soap.SOAPMessageContext;
      import javax.xml.soap.SOAPEnvelope;
      import javax.xml.soap.SOAPHeader;
      import javax.xml.soap.SOAPMessage;
      import javax.xml.soap.SOAPPart;
      
      public class MyHandler extends GenericHandler{
       public boolean handleRequest(MessageContext ctx) {
       try {
       SOAPMessage msg =((SOAPMessageContext)ctx).getMessage();
       SOAPPart sp = msg.getSOAPPart();
       SOAPEnvelope se = sp.getEnvelope();
       SOAPHeader header = se.getHeader();
      
       header.getFirstChild();
       // Now you can process
       // the header
       System.out.println("Passo dentro MyHandler!");
      
       } catch(Exception ex) {
       // if you throw a
       // RuntimeException
       // here then a SOAPFault
       // will be generated
       }
      
       return true;
       }
      
       public QName[] getHeaders() {
       // TODO Auto-generated method stub
       return null;
       }
      
      }
      


      Bye!

      :_(

      P.s. I read chapter 6... but the example are hard and they always are about j2ee client, that is deployed O_o