1 Reply Latest reply on Oct 18, 2012 10:36 AM by Michael Vengerovich

    JBoss 5.1 for SOA, SOAPHandlers configuration

    Michael Vengerovich Newbie

      Hi All,

       

      I have a handler in my project that implements javax.xml.ws.handler.soap.SOAPHandler<javax.xml.ws.handler.soap.SOAPMessageContext>

      Do you know how to configure JBoss to enable my handler to trap the actions?

       

      As I see there are 2 configurations that looks like that I find:

      C:\jboss-soa-p-5\jboss-as\server\default\deployers\jbossws.deployer\META-INF\standard-jaxws-client-config.xml

      C:\jboss-soa-p-5\jboss-as\server\default\deployers\jbossws.deployer\META-INF\standard-jaxws-endpoint-config.xml

      They point to org.jboss.ws.extensions.addressing.jaxws.WSAddressingClientHandler class that implements the same iterface.

       

      Thank you.

        • 1. Re: JBoss 5.1 for SOA, SOAPHandlers configuration
          Michael Vengerovich Newbie

          I found 2 ways:

          1. use AOP like this:

          [code]

           

           

          import java.io.InputStream;

          import java.net.MalformedURLException;

          import java.net.URL;

           

           

          import org.jboss.aop.joinpoint.Invocation;

          import org.jboss.ws.WSException;

          import org.jboss.ws.metadata.umdm.EndpointMetaData;

          import org.jboss.ws.metadata.umdm.HandlerMetaDataJAXWS;

          import org.jboss.ws.metadata.umdm.ServerEndpointMetaData;

          import org.jboss.ws.metadata.umdm.ServiceMetaData;

          import org.jboss.wsf.spi.metadata.j2ee.serviceref.HandlerChainsObjectFactory;

          import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerChainMetaData;

          import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerChainsMetaData;

          import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData;

          import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData.HandlerType;

          import org.jboss.xb.binding.ObjectModelFactory;

          import org.jboss.xb.binding.Unmarshaller;

          import org.jboss.xb.binding.UnmarshallerFactory;

           

           

          public class HandlerAOP {

           

                    // expected point to AOP: in jbossws-native-core.jar

                    //package org.jboss.ws.metadata.builder.jaxws;

                    //public class JAXWSClientMetaDataBuilder extends JAXWSMetaDataBuilder

                    //   public ServiceMetaData buildMetaData(..)

                    public Object handleClientServiceMetaData(Invocation invocation) throws Throwable {

                              long time = System.currentTimeMillis();

                              try {

                                        Object res = invocation.invokeNext();

                                        if (res instanceof ServiceMetaData) {

                                                  String filename = System.getProperty("ITCAM4SOA_CLIENT_HANDLERS_FILENAME");

                                                  if (filename == null) {

                                                            System.out.println("ITCAM4SOA_CLIENT_HANDLERS_FILENAME system property is not found");

                                                  } else {

                                                            ServiceMetaData smd = (ServiceMetaData) res;

                                                            for (EndpointMetaData emd : smd.getEndpoints()) {

                                                                      ProcessHandlers(emd, filename);

                                                            }

                                                  }

                                        }

                                        return res;

                              } catch (Exception e) {

                                        e.printStackTrace();

                                        throw e;

                              } finally {

                                        System.out.println("invocation " + invocation.toString() + " time: " + (System.currentTimeMillis() - time) + "ms");

                              }

                    }

           

           

                    // expected point to AOP: in jbossws-native-core.jar

                    //package org.jboss.ws.metadata.builder.jaxws;

                    //public class JAXWSWebServiceMetaDataBuilder extends JAXWSServerMetaDataBuilder

                    //   public ServerEndpointMetaData buildWebServiceMetaData(..)

                    public Object handleServerServiceMetaData(Invocation invocation) throws Throwable {

                              long time = System.currentTimeMillis();

                              try {

                                        Object res = invocation.invokeNext();

                                        if (res instanceof ServerEndpointMetaData) {

                                                  String filename = System.getProperty("ITCAM4SOA_SERVER_HANDLERS_FILENAME");

                                                  if (filename == null) {

                                                            System.out.println("ITCAM4SOA_SERVER_HANDLERS_FILENAME system property is not found");

                                                  } else {

                                                            ServerEndpointMetaData semd = (ServerEndpointMetaData) res;

                                                            ProcessHandlers(semd, filename);

                                                  }

                                        }

                                        return res;

                              } catch (Exception e) {

                                        e.printStackTrace();

                                        throw e;

                              } finally {

                                        System.out.println("invocation " + invocation.toString() + " time: " + (System.currentTimeMillis() - time) + "ms");

                              }

                    }

           

           

                    // just helper

                    private static void ProcessHandlers(EndpointMetaData emd, String filename) {

                              UnifiedHandlerChainsMetaData handlerChainsMetaData = null;

                              try {

                                        URL fileURL = null;

                                        try {

                                                  fileURL = new URL(filename);

                                        } catch (MalformedURLException ex) {

                                                  // ignore

                                        }

                                        if (fileURL == null)

                                                  throw new WSException("Cannot resolve handler file " + filename);

                                        InputStream is = fileURL.openStream();

                                        try {

                                                  Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();

                                                  unmarshaller.setValidation(true);

                                                  unmarshaller.setSchemaValidation(true);

                                                  ObjectModelFactory factory = new HandlerChainsObjectFactory();

                                                  handlerChainsMetaData = (UnifiedHandlerChainsMetaData)unmarshaller.unmarshal(is, factory, null);

                                        } finally {

                                                  is.close();

                                        }

                              } catch (RuntimeException rte) {

                                        throw rte;

                              } catch (Exception ex) {

                                        throw new WSException("Cannot process handler chain: " + filename, ex);

                              }

            for (UnifiedHandlerChainMetaData UnifiedHandlerChainMetaData : handlerChainsMetaData.getHandlerChains()) {

                                        for (UnifiedHandlerMetaData uhmd : UnifiedHandlerChainMetaData.getHandlers()) {

                                                  HandlerMetaDataJAXWS hmd = HandlerMetaDataJAXWS.newInstance(uhmd, HandlerType.ENDPOINT);

                                                  emd.addHandler(hmd);

                                        }

                              }

                              System.out.println("EndpointMetaData: "          + emd.toString());

                    }

          }

          [/code]

          2. In case it is possible to use annotations (change service impl. class) just fight with @EndpointConfig and/or @HandlerChain