8 Replies Latest reply on Feb 19, 2007 7:21 AM by smichea

    Help: how to consume webservice in ejb3 ?

      For days know i try to consume a webservice in a stateless EJB3... with no success.
      I use jboss4.0.4 with EJB3 RC9 and develop with NetBeans5.5 and SOAPUI plugin

      In an ejb-module I have jaxws2 jsr-181 webservices in stateless EJB3 that should themselve consume webservices.
      I tried to use jaxws2 webservice clients created by netbeans but it seems that this is not supported in jboss4.0.4.
      I tried jbossws clients with no success (got exceptions unsolved in this forum)

      So i'm trying jaxrpc (this should work as I manage to consume the webservices when I create a client in a webapplication)

      Using jwsdp-2.0 wscompile I managed to create the SEI.
      I tried to put the interfaces in JNDI with a service-ref in ejb-jar, with no success (even when i put the service-ref in web.xml) so to obtain the service I use the method ServiceFactoryImpl.newInstance().createService(url,qname)

      I indeed get the service interface then the port but when I call the webmethod I obtain the following exeptions :

      - org.jboss.util.NotImplementedException: HTTP GET not supported (for jbossws bundled with jbosAS4.04)

      - java.io.IOException: Server returned HTTP response code: 405 (for jbossws 1.0.3)

      and with jbossws1.0.4 I cannot deploy one of the application containing the jaxws2.0 webservices I want to consume...

      I'm totally lost (I tried to bundle JAXRPC1.6 with the appli, then JAXWS2.0, I even tried to migrate my application in a war, but got other problems).

      I would be grateful if someone has an idea (I use no proxy, everything is on the same jboss instance)

        • 1. Re: Help: how to consume webservice in ejb3 ?

          Also when I use JNDI to get the service (adding fake a client application with service-ref), I manage to get the port but obtain the exception :

          ERROR [CallImpl] Call invocation failed with unkown Exception
          javax.xml.soap.SOAPException: Could not transmit message
           at org.jboss.ws.soap.SOAPConnectionImpl.call(SOAPConnectionImpl.java:204)
          
          ...
          
          org.jboss.remoting.CannotConnectException: Can not connect http client invoker.
          
          ...
          
          java.lang.IllegalArgumentException: protocol = http host = null
           at sun.net.spi.DefaultProxySelector.select(DefaultProxySelector.java:146)
          


          • 2. Re: Help: how to consume webservice in ejb3 ?

            Finally I tried to install jbossws1.2.0 and use a NB generated jaxws2.0 client and I get the same error :

            06:50:14,060 ERROR [STDERR] org.jboss.remoting.CannotConnectException: Can not connect http client invoker.
            06:50:14,060 ERROR [STDERR] at org.jboss.remoting.transport.http.HTTPClientInvoker.useHttpURLConnection(HTTPClientInvoker.java:201)
            ...
            06:50:19,561 ERROR [STDERR] Caused by: java.lang.IllegalArgumentException: protocol = http host = null
            06:50:19,561 ERROR [STDERR] at sun.net.spi.DefaultProxySelector.select(DefaultProxySelector.java:146
            


            seems like kind of a proxy error... but I have no proxy

            • 3. Re: Help: how to consume webservice in ejb3 ?
              dwin

              hey Michae

              Perhaps, you could try to @WebServiceRef annotation.

              Also, you could post the code too.

              • 4. Re: Help: how to consume webservice in ejb3 ?

                this annotation seems to be available in the next release of EJB3 only (http://jira.jboss.com/jira/browse/EJBTHREE-477)

                Is there a working example somewhere of a stateless EJB3 calling a webservice ?

                • 5. Re: Help: how to consume webservice in ejb3 ?
                  thomas.diesler

                  @WebServiceRef is supported in jbossws-1.2.0

                  With JAXRPC you can always use

                  service = ServiceFactory.create(wsdl, serviceName)
                  port = service.getPort(MySEI.class);
                  port.doStuff()

                  Note, if you have custom types you need to pass in jaxrpc-mapping.xml

                  • 6. Re: Help: how to consume webservice in ejb3 ?

                     

                    "thomas.diesler@jboss.com" wrote:
                    @WebServiceRef is supported in jbossws-1.2.0


                    Doesn't work better with the annotation.

                    Here is the ejb
                    
                    @Stateless()
                    @WebService()
                    public class jbossWebService {
                     @WebServiceRef()
                     org.manaty.mvno.webservice.SimuCRMBeanService simuCRMBeanService;
                    
                     @WebMethod
                     public String identProxy(@WebParam(name = "login") String login, @WebParam(name = "password") String password) {
                     String result="pb";
                     org.manaty.mvno.webservice.SimuCRMBeanLocal _simuCRMBeanPort = simuCRMBeanService.getSimuCRMBeanPort();
                     result = _simuCRMBeanPort.identification(login,password);
                     return result;
                     }
                    


                    the webservice called works perfectly well, it is another EJB endpoint on the same server.

                    I successfully used wscompile ant task to generate the artifacts

                     <wsconsume fork="true" verbose="true" destdir="build/jar" sourcedestdir="src/java"
                     keep="true" debug="true" package="org.manaty.mvno.webservice" wsdl="http://127.0.0.1:8080/simuCRMBilling/simuCRMBean?wsdl" >
                     </wsconsume>
                    


                    and the wsdl is quite simple

                    ?
                     <definitions name="simuCRMBeanService" targetNamespace="http://simu.mvno.manaty.org/">
                    ?
                     <types>
                    ?
                     <xs:schema targetNamespace="http://simu.mvno.manaty.org/" version="1.0">
                    <xs:element name="changePassword" type="tns:changePassword"/>
                    <xs:element name="changePasswordResponse" type="tns:changePasswordResponse"/>
                    <xs:element name="customerInfo" type="tns:customerInfo"/>
                    <xs:element name="customerInfoResponse" type="tns:customerInfoResponse"/>
                    <xs:element name="identification" type="tns:identification"/>
                    <xs:element name="identificationResponse" type="tns:identificationResponse"/>
                    <xs:element name="orderList" type="tns:orderList"/>
                    <xs:element name="orderListResponse" type="tns:orderListResponse"/>
                    <xs:element name="subscriptionInfo" type="tns:subscriptionInfo"/>
                    <xs:element name="subscriptionInfoResponse" type="tns:subscriptionInfoResponse"/>
                    <xs:element name="subscriptionList" type="tns:subscriptionList"/>
                    <xs:element name="subscriptionListResponse" type="tns:subscriptionListResponse"/>
                    ?
                     <xs:complexType name="subscriptionList">
                    ?
                     <xs:sequence>
                    <xs:element minOccurs="0" name="login" type="xs:string"/>
                    </xs:sequence>
                    </xs:complexType>
                    ?
                     <xs:complexType name="subscriptionListResponse">
                    ?
                     <xs:sequence>
                    <xs:element maxOccurs="unbounded" minOccurs="0" name="subscriptions" type="tns:subscriptionListObject"/>
                    </xs:sequence>
                    </xs:complexType>
                    ?
                     <xs:complexType name="subscriptionListObject">
                    ?
                     <xs:sequence>
                    <xs:element minOccurs="0" name="offer" type="xs:string"/>
                    <xs:element minOccurs="0" name="subScriptionNumber" type="xs:string"/>
                    </xs:sequence>
                    </xs:complexType>
                    ?
                     <xs:complexType name="identification">
                    ?
                     <xs:sequence>
                    <xs:element minOccurs="0" name="login" type="xs:string"/>
                    <xs:element minOccurs="0" name="password" type="xs:string"/>
                    </xs:sequence>
                    </xs:complexType>
                    ?
                     <xs:complexType name="identificationResponse">
                    ?
                     <xs:sequence>
                    <xs:element minOccurs="0" name="return" type="xs:string"/>
                    </xs:sequence>
                    </xs:complexType>
                    ?
                     <xs:complexType name="customerInfo">
                    ?
                     <xs:sequence>
                    <xs:element minOccurs="0" name="login" type="xs:string"/>
                    </xs:sequence>
                    </xs:complexType>
                    ?
                     <xs:complexType name="customerInfoResponse">
                    ?
                     <xs:sequence>
                    <xs:element minOccurs="0" name="return" type="tns:customerInfoObject"/>
                    </xs:sequence>
                    </xs:complexType>
                    ?
                     <xs:complexType name="customerInfoObject">
                    ?
                     <xs:sequence>
                    <xs:element minOccurs="0" name="address1" type="xs:string"/>
                    <xs:element minOccurs="0" name="address2" type="xs:string"/>
                    <xs:element minOccurs="0" name="address3" type="xs:string"/>
                    <xs:element minOccurs="0" name="address4" type="xs:string"/>
                    <xs:element minOccurs="0" name="city" type="xs:string"/>
                    <xs:element minOccurs="0" name="customerNumber" type="xs:string"/>
                    <xs:element minOccurs="0" name="firstname" type="xs:string"/>
                    <xs:element minOccurs="0" name="lastname" type="xs:string"/>
                    <xs:element minOccurs="0" name="postalCode" type="xs:string"/>
                    </xs:sequence>
                    </xs:complexType>
                    ?
                     <xs:complexType name="subscriptionInfo">
                    ?
                     <xs:sequence>
                    <xs:element minOccurs="0" name="login" type="xs:string"/>
                    <xs:element minOccurs="0" name="subscriptionNumber" type="xs:string"/>
                    </xs:sequence>
                    </xs:complexType>
                    ?
                     <xs:complexType name="subscriptionInfoResponse">
                    ?
                     <xs:sequence>
                    <xs:element minOccurs="0" name="return" type="tns:subscriptionInfoObject"/>
                    </xs:sequence>
                    </xs:complexType>
                    ?
                     <xs:complexType name="subscriptionInfoObject">
                    ?
                     <xs:sequence>
                    <xs:element minOccurs="0" name="contractDuration" type="xs:string"/>
                    <xs:element minOccurs="0" name="offerType" type="xs:string"/>
                    <xs:element maxOccurs="unbounded" minOccurs="0" name="options" nillable="true" type="tns:option"/>
                    <xs:element maxOccurs="unbounded" minOccurs="0" name="plans" nillable="true" type="tns:plan"/>
                    <xs:element minOccurs="0" name="price" type="xs:string"/>
                    <xs:element maxOccurs="unbounded" minOccurs="0" name="services" nillable="true" type="tns:service"/>
                    <xs:element minOccurs="0" name="totalMonthlyPrice" type="xs:string"/>
                    </xs:sequence>
                    </xs:complexType>
                    ?
                     <xs:complexType name="option">
                    ?
                     <xs:sequence>
                    <xs:element minOccurs="0" name="description" type="xs:string"/>
                    <xs:element minOccurs="0" name="monthlyPrice" type="xs:string"/>
                    </xs:sequence>
                    </xs:complexType>
                    ?
                     <xs:complexType name="plan">
                    ?
                     <xs:sequence>
                    <xs:element minOccurs="0" name="description" type="xs:string"/>
                    <xs:element minOccurs="0" name="monthlyPrice" type="xs:string"/>
                    </xs:sequence>
                    </xs:complexType>
                    ?
                     <xs:complexType name="service">
                    ?
                     <xs:sequence>
                    <xs:element minOccurs="0" name="description" type="xs:string"/>
                    <xs:element minOccurs="0" name="monthlyPrice" type="xs:string"/>
                    </xs:sequence>
                    </xs:complexType>
                    ?
                     <xs:complexType name="orderList">
                    ?
                     <xs:sequence>
                    <xs:element minOccurs="0" name="login" type="xs:string"/>
                    </xs:sequence>
                    </xs:complexType>
                    ?
                     <xs:complexType name="orderListResponse">
                    ?
                     <xs:sequence>
                    <xs:element maxOccurs="unbounded" minOccurs="0" name="return" type="tns:orderObject"/>
                    </xs:sequence>
                    </xs:complexType>
                    ?
                     <xs:complexType name="orderObject">
                    ?
                     <xs:sequence>
                    <xs:element minOccurs="0" name="date" type="xs:string"/>
                    <xs:element minOccurs="0" name="orderDate" type="xs:string"/>
                    <xs:element minOccurs="0" name="orderNumber" type="xs:string"/>
                    <xs:element minOccurs="0" name="status" type="xs:string"/>
                    </xs:sequence>
                    </xs:complexType>
                    ?
                     <xs:complexType name="changePassword">
                    ?
                     <xs:sequence>
                    <xs:element minOccurs="0" name="login" type="xs:string"/>
                    <xs:element minOccurs="0" name="oldPassword" type="xs:string"/>
                    <xs:element minOccurs="0" name="newPassword" type="xs:string"/>
                    </xs:sequence>
                    </xs:complexType>
                    ?
                     <xs:complexType name="changePasswordResponse">
                    ?
                     <xs:sequence>
                    <xs:element minOccurs="0" name="return" type="xs:string"/>
                    </xs:sequence>
                    </xs:complexType>
                    </xs:schema>
                    </types>
                    ?
                     <message name="SimuCRMBeanLocal_identificationResponse">
                    <part element="tns:identificationResponse" name="identificationResponse"/>
                    </message>
                    ?
                     <message name="SimuCRMBeanLocal_customerInfoResponse">
                    <part element="tns:customerInfoResponse" name="customerInfoResponse"/>
                    </message>
                    ?
                     <message name="SimuCRMBeanLocal_subscriptionInfoResponse">
                    <part element="tns:subscriptionInfoResponse" name="subscriptionInfoResponse"/>
                    </message>
                    ?
                     <message name="SimuCRMBeanLocal_subscriptionList">
                    <part element="tns:subscriptionList" name="subscriptionList"/>
                    </message>
                    ?
                     <message name="SimuCRMBeanLocal_changePasswordResponse">
                    <part element="tns:changePasswordResponse" name="changePasswordResponse"/>
                    </message>
                    ?
                     <message name="SimuCRMBeanLocal_changePassword">
                    <part element="tns:changePassword" name="changePassword"/>
                    </message>
                    ?
                     <message name="SimuCRMBeanLocal_subscriptionListResponse">
                    <part element="tns:subscriptionListResponse" name="subscriptionListResponse"/>
                    </message>
                    ?
                     <message name="SimuCRMBeanLocal_identification">
                    <part element="tns:identification" name="identification"/>
                    </message>
                    ?
                     <message name="SimuCRMBeanLocal_orderListResponse">
                    <part element="tns:orderListResponse" name="orderListResponse"/>
                    </message>
                    ?
                     <message name="SimuCRMBeanLocal_orderList">
                    <part element="tns:orderList" name="orderList"/>
                    </message>
                    ?
                     <message name="SimuCRMBeanLocal_customerInfo">
                    <part element="tns:customerInfo" name="customerInfo"/>
                    </message>
                    ?
                     <message name="SimuCRMBeanLocal_subscriptionInfo">
                    <part element="tns:subscriptionInfo" name="subscriptionInfo"/>
                    </message>
                    ?
                     <portType name="SimuCRMBeanLocal">
                    ?
                     <operation name="changePassword" parameterOrder="changePassword">
                    <input message="tns:SimuCRMBeanLocal_changePassword"/>
                    <output message="tns:SimuCRMBeanLocal_changePasswordResponse"/>
                    </operation>
                    ?
                     <operation name="customerInfo" parameterOrder="customerInfo">
                    <input message="tns:SimuCRMBeanLocal_customerInfo"/>
                    <output message="tns:SimuCRMBeanLocal_customerInfoResponse"/>
                    </operation>
                    ?
                     <operation name="identification" parameterOrder="identification">
                    <input message="tns:SimuCRMBeanLocal_identification"/>
                    <output message="tns:SimuCRMBeanLocal_identificationResponse"/>
                    </operation>
                    ?
                     <operation name="orderList" parameterOrder="orderList">
                    <input message="tns:SimuCRMBeanLocal_orderList"/>
                    <output message="tns:SimuCRMBeanLocal_orderListResponse"/>
                    </operation>
                    ?
                     <operation name="subscriptionInfo" parameterOrder="subscriptionInfo">
                    <input message="tns:SimuCRMBeanLocal_subscriptionInfo"/>
                    <output message="tns:SimuCRMBeanLocal_subscriptionInfoResponse"/>
                    </operation>
                    ?
                     <operation name="subscriptionList" parameterOrder="subscriptionList">
                    <input message="tns:SimuCRMBeanLocal_subscriptionList"/>
                    <output message="tns:SimuCRMBeanLocal_subscriptionListResponse"/>
                    </operation>
                    </portType>
                    ?
                     <binding name="SimuCRMBeanLocalBinding" type="tns:SimuCRMBeanLocal">
                    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
                    ?
                     <operation name="changePassword">
                    <soap:operation soapAction=""/>
                    ?
                     <input>
                    <soap:body use="literal"/>
                    </input>
                    ?
                     <output>
                    <soap:body use="literal"/>
                    </output>
                    </operation>
                    ?
                     <operation name="customerInfo">
                    <soap:operation soapAction=""/>
                    ?
                     <input>
                    <soap:body use="literal"/>
                    </input>
                    ?
                     <output>
                    <soap:body use="literal"/>
                    </output>
                    </operation>
                    ?
                     <operation name="identification">
                    <soap:operation soapAction=""/>
                    ?
                     <input>
                    <soap:body use="literal"/>
                    </input>
                    ?
                     <output>
                    <soap:body use="literal"/>
                    </output>
                    </operation>
                    ?
                     <operation name="orderList">
                    <soap:operation soapAction=""/>
                    ?
                     <input>
                    <soap:body use="literal"/>
                    </input>
                    ?
                     <output>
                    <soap:body use="literal"/>
                    </output>
                    </operation>
                    ?
                     <operation name="subscriptionInfo">
                    <soap:operation soapAction=""/>
                    ?
                     <input>
                    <soap:body use="literal"/>
                    </input>
                    ?
                     <output>
                    <soap:body use="literal"/>
                    </output>
                    </operation>
                    ?
                     <operation name="subscriptionList">
                    <soap:operation soapAction=""/>
                    ?
                     <input>
                    <soap:body use="literal"/>
                    </input>
                    ?
                     <output>
                    <soap:body use="literal"/>
                    </output>
                    </operation>
                    </binding>
                    ?
                     <service name="simuCRMBeanService">
                    ?
                     <port binding="tns:SimuCRMBeanLocalBinding" name="simuCRMBeanPort">
                    <soap:address location="http://DIVIOSOFT:8080/simuCRMBilling/simuCRMBean"/>
                    </port>
                    </service>
                    </definitions>
                    


                    As for JAXRPC this is not possible to use it as for other WS in the same application I have a complex binding that require jaxb2.

                    I would be grateful of any hint or example

                    Sebastien

                    • 7. Re: Help: how to consume webservice in ejb3 ?

                      in fact with the annotation, the problem comes from the injection :

                      [SOAPFaultHelperJAXWS] SOAP request exception
                      java.lang.RuntimeException: Non matching type for inject of field: org.manaty.mvno.webservice.SimuCRMBeanService org.jboss.test.jbossWebService.simuCRMBeanService for type: org.jnp.interfaces.NamingContext of jndiName env/org.jboss.test.jbossWebService/simuCRMBeanService
                      intfs: , javax.naming.Context, java.io.Serializable
                       at org.jboss.injection.JndiFieldInjector.inject(JndiFieldInjector.java:135)
                       at org.jboss.injection.JndiFieldInjector.inject(JndiFieldInjector.java:104)
                       at org.jboss.injection.JndiFieldInjector.inject(JndiFieldInjector.java:61)
                       at org.jboss.ejb3.AbstractPool.create(AbstractPool.java:92)
                      


                      ?...

                      • 8. Re: Help: how to consume webservice in ejb3 ?

                        Solved, thanks to rlamie : The port=null problem came from the configuration of jboss server in netbeans.
                        I just had to uncheck "Use IDE Proxy Settings"