1 Reply Latest reply on Feb 29, 2012 4:00 AM by Richard Opalka

    Dynamic webservices on AS 7.1

    Alex Vb Newbie

      I need dynamic webservices without POJO's to back them up. This means that:

      - I need to generate my own WSDLs (@ runtime would be preferable but if I have to save them to file to reference them, this is also possible)

      - I need to intercept the XML content before it is unmarshalled

      - I need a single method that is called for all webservice services which will then dispatch the request as it sees fit

       

      I've been looking at the provider interface which seems to do what I want but I'm running into a few issues:

      1) how do I access the "context" in a Provider? I need to know things like "which service was called" etc so the dispatching can work correctly

       

      2) in an attempt to have non-hardcoded wsdl locations, I turned to the "webservices.xml" file which resides in my WEB-INF folder (it's a war file). It currently contains:

       

      <?xml version="1.0" encoding="UTF-8"?>

      <webservices xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2">

        <webservice-description>

        <!-- just a label, can be anything you want -->

        <webservice-description-name>MyServiceName</webservice-description-name>

        <port-component>

          <!-- just a label, can be anything you want -->

          <port-component-name>MyServicePort</port-component-name>

              <!-- Target namespace from wsdl -->

              <wsdl-port xmlns:ex="http://example.com/ws/testWs">ex:testWs</wsdl-port>

              <!-- Fully qualified class name of the ejb interface/bean providing the service -->

              <service-endpoint-interface>com.example.test.DynamicWebserviceProvider</service-endpoint-interface>

              <service-impl-bean>

              <!-- The class name of the bean providing the service -->

                <ejb-link>DynamicWebserviceProvider</ejb-link>

              </service-impl-bean>

          </port-component>

        </webservice-description>

      </webservices>

       

      I've tried some permutations of values (it's very hard to find decent documentation on this) and while jboss will error out on an invalid webservices.xml, it seems to ignore every setting in it. Am I doing something wrong?

       

      3) I want configurable security and as such have been looking into "jboss-webservices.xml" but it seems to have the same problem as the webservices.xml file: jboss complains if it's incorrect but it is ignored when correct (or so it seems). It contains the following:

       

      <webservices xmlns="http://www.jboss.com/xml/ns/javaee"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        version="1.1"

        xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss_webservices_1_0.xsd">

        <context-root>myroot</context-root>

      <!--   <config-name>Standard WSSecurity Endpoint</config-name>

        <config-file>META-INF/custom.xml</config-file> -->

        <port-component>

          <ejb-name>testJbossWebservice</ejb-name>

          <port-component-name>DynamicWebserviceProviderPort</port-component-name>

          <port-component-uri>/*</port-component-uri>

          <auth-method>BASIC</auth-method>

          <transport-guarantee>NONE</transport-guarantee>

          <secure-wsdl-access>true</secure-wsdl-access>

        </port-component>

        <webservice-description>

          <webservice-description-name>TestService</webservice-description-name>

          <wsdl-publish-location>file:///home/alex/workspace/test-webservice-provider/src/main/webapp/WEB-INF/test.wsdl</wsdl-publish-location>

        </webservice-description>

      </webservices>

       

      Again tried some permutations but this too seems to be poorly documented (or my google skills are just lacking).

       

      Additionally i've been looking into the whole Endpoint thing to Endpoint.create() one and then publish() it but it basically does nothing, no errors but no webservice either. Additionally fun fact: I can only register an object that has @WebServiceProvider or @Webservice or jboss complains when it tries to publish(), but once I set the annotation, jboss automatically deploys the webservice. So I'm not sure how the Endpoint.create() is supposed to work?

       

      In short: does anyone have any good examples of a dynamic webservice provider that dispatches requests based on metadata parameters like wsdl service invoked etc, that works with jboss security and can preferably serve WSDLs on the fly? Also if at all possible, controlling the endpoint the webservice resides on would be swell. Oh, and a pony please

        • 1. Re: Dynamic webservices on AS 7.1
          Richard Opalka Master

          Alex Vb wrote:

           

          I've been looking at the provider interface which seems to do what I want but I'm running into a few issues:

          1) how do I access the "context" in a Provider? I need to know things like "which service was called" etc so the dispatching can work correctly

           

          import javax.xml.ws.*;

          import javax.xml.ws.handler.*;

          import javax.annotation.*;

           

          @WebServiceProvider

          public class YourProvider implements Provider<SOAPMessage> {

           

             @Resource

             private WebServiceContext wsc;

           

             SOAPMessage invoke(SOAPMessage msg) throws WebServiceException {

                MessageContext context = wsc.getMessageContext();

                // find necessary info in context - see: http://docs.oracle.com/javaee/5/api/javax/xml/ws/handler/MessageContext.html

                ...

             }

          }

           

           

          Alex Vb wrote:

           

          2) in an attempt to have non-hardcoded wsdl locations, I turned to the "webservices.xml" file which resides in my WEB-INF folder (it's a war file). It currently contains:

           

          webservices.xml is intended for JAX-RPC endpoints.

          WebServiceProvider is part of JAX-WS specification.

          I suggest you to use

          @javax.xml.ws.WebServiceProvider(wsdlLocation="WEB-INF/wsdl/your.wsdl") instead

           

           

          Alex Vb wrote:

           

          I've tried some permutations of values (it's very hard to find decent documentation on this) and while jboss will error out on an invalid webservices.xml, it seems to ignore every setting in it. Am I doing something wrong?

           

          3) I want configurable security and as such have been looking into "jboss-webservices.xml" but it seems to have the same problem as the webservices.xml file: jboss complains if it's incorrect but it is ignored when correct (or so it seems). It contains the following:

           

           

          jboss-webservices.xml is again mainly for JAX-RPC endpoints.

          To configure security on JAX-WS endpoints, use the following approach:

           

          import javax.annotation.security.RolesAllowed;

          import javax.jws.WebMethod;

          import javax.jws.WebService;

          ...

          import org.jboss.ws.api.annotation.AuthMethod;

          import org.jboss.ws.api.annotation.TransportGuarantee;

          import org.jboss.ws.api.annotation.WebContext;

           

          @WebContext

          (

             contextRoot="/jaxws-securityDomain",.

             urlPattern="/*",

             authMethod = AuthMethod.BASIC,

             transportGuarantee = TransportGuarantee.NONE,

             secureWSDLAccess = false

          )

          @RolesAllowed("friend")

          @WebServiceProvider

          public class YourProvider implements Provider<SOAPMessage> {

             ...

          }

           

          There are many examples distributed with our JBossWS releases.