1 Reply Latest reply on Sep 30, 2010 9:55 PM by pschor

    Invoking a web service from JBoss AS as a client

    pschor

      I've been trying to figure this out for several days, any help will be appreciated.

       

      I'm trying to invoke a web service from a java class deployed in JBoss 5.1.0.GA running on JDK1.6.0. I get the exception below. The same method called from a plain Java object and invoked from a command line (using JDK's WS jars instead of JBoss') works perfectly.

       

       

      I copied the jboss-native-* classes to the endorsed directory (initally to resolve the SetProperty problem), but is there anything else that needs to be considered to invoke a service from JBoss as a client?

       

      Three things that are different from the case when the method is invoked successfully from the command line:

        • In the request STDOUT the XML version header was removed (probably by SaveMessage).
        • In the request STDOUT quotes were converted to apostrophes.
        • Even thought the content type is set as text/xml, the error says content type is text/html

       

      Thanks for your help

      Peter

       

       

      The method and the output/error:

       

       

      try {

       

                  // Create the SOAP connection

                  SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();

                  SOAPConnection connection = soapConnFactory.createConnection();

       

       

                   String soapText = 

                       "<?xml version=\"1.0\"?>" +

                      "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"" + 

                       " SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + 

                       "<SOAP-ENV:Header/>" +

                       "<SOAP-ENV:Body>" +

                       "<Discover xmlns=\"urn:schemas-microsoft-com:xml-analysis\">" +

                       "<RequestType>DISCOVER_DATASOURCES</RequestType>" +

                       "<Restrictions><RestrictionList/></Restrictions>"  +

                       "<Properties><PropertyList><Format>Tabular</Format></PropertyList></Properties>"  +

                       "</Discover>"  +

                       "</SOAP-ENV:Body>" +

                       "</SOAP-ENV:Envelope>";

       

                   // Create SoapMessage 

                   MessageFactory msgFactory     = MessageFactory.newInstance(); 

                   SOAPMessage message           = msgFactory.createMessage(); 

       

                   // Load the SOAP text into a stream source 

                   ByteArrayInputStream stream   = new ByteArrayInputStream(soapText.getBytes()); 

                   StreamSource source           = new StreamSource(stream); 

       

                   // Set contents of message  

                   message.getSOAPPart().setContent(source); 

       

                   MimeHeaders mh = message.getMimeHeaders();

                   mh.setHeader("Content-Type", "text/xml");

                   mh.setHeader("SOAPAction", "\"urn:schemas-microsoft-com:xml-analysis:Discover\"");

                   //Save the message

                   message.saveChanges();

       

                  //Check the input

                  System.out.println("HEADERS:\n" );

                  Iterator<MimeHeader> i = message.getMimeHeaders().getAllHeaders();

       

                  while ( i.hasNext() ) {

                      MimeHeader header = i.next();

                      String name = header.getName();

                      String value = header.getValue();

                      System.out.println ( name + ": " + value);

                  }

                  System.out.println("END HEADERS:\n" );

       

       

                  System.out.println("REQUEST:\n");

                  message.writeTo(System.out);

                  System.out.println("END REQUEST:\n");

       

                  //Send the message and get a reply  

       

                  //Set the destination

                  String destination = "http://localhost:7070/mondrian/xmla";

                  //Send the message

                  SOAPMessage reply = connection.call(message, destination);

       

                  //Check the reply

                  System.out.println("\nREPLY:\n");

                  reply.writeTo(System.out);

                  System.out.println("\nEND REPLY:\n");

       

                  // Close the SOAP connection           

                  connection.close();

       

              } catch(Exception e) {

                  System.out.println(e.getMessage());

              }

       

          }

       

       

       

      20:50:45,855 INFO  [STDOUT] HEADERS:
      20:50:45,855 INFO  [STDOUT] Content-Type: text/xml; charset=UTF-8
      20:50:45,855 INFO  [STDOUT] SOAPAction: "urn:schemas-microsoft-com:xml-analysis:Discover"
      20:50:45,855 INFO  [STDOUT] END HEADERS:
      20:50:45,855 INFO  [STDOUT] REQUEST:
      20:50:45,855 INFO  [STDOUT] <SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'><SOAP-ENV:Header></SOAP-ENV:Header><SOAP-ENV:Body>
      <Discover xmlns='urn:schemas-microsoft-com:xml-analysis'><RequestType>DISCOVER_DATASOURCES
      20:50:45,855 INFO  [STDOUT] </RequestType>
      20:50:45,855 INFO  [STDOUT] <Restrictions><RestrictionList/>
      20:50:45,855 INFO  [STDOUT] </Restrictions>
      20:50:45,855 INFO  [STDOUT] <Properties><PropertyList><Format>Tabular
      20:50:45,855 INFO  [STDOUT] </Format>
      20:50:45,855 INFO  [STDOUT] </PropertyList>
      20:50:45,855 INFO  [STDOUT] </Properties>
      20:50:45,855 INFO  [STDOUT] </Discover>
      20:50:45,855 INFO  [STDOUT] </SOAP-ENV:Body></SOAP-ENV:Envelope>
      20:50:45,855 INFO  [STDOUT] END REQUEST:
      20:50:59,865 ERROR [SOAPMessageUnMarshallerHTTP] Cannot unmarshall SOAPMessage
      javax.xml.soap.SOAPException: Unsupported content type: text/html; charset=utf-8
          at org.jboss.ws.core.soap.MessageFactoryImpl.createMessage(MessageFactoryImpl.java:272)
          at org.jboss.ws.core.soap.SOAPMessageUnMarshallerHTTP.read(SOAPMessageUnMarshallerHTTP.java:82)
          at org.jboss.remoting.transport.http.HTTPClientInvoker.readResponse(HTTPClientInvoker.java:570)
          at org.jboss.remoting.transport.http.HTTPClientInvoker.useHttpURLConnection(HTTPClientInvoker.java:369)
          at org.jboss.remoting.transport.http.HTTPClientInvoker.makeInvocation(HTTPClientInvoker.java:231)
          at org.jboss.remoting.transport.http.HTTPClientInvoker.transport(HTTPClientInvoker.java:161)
          at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:165)
          at org.jboss.remoting.Client.invoke(Client.java:1724)
          at org.jboss.remoting.Client.invoke(Client.java:629)
          at org.jboss.ws.core.client.HTTPRemotingConnection.invoke(HTTPRemotingConnection.java:243)
          at org.jboss.ws.core.client.SOAPProtocolConnectionHTTP.invoke(SOAPProtocolConnectionHTTP.java:71)
          at org.jboss.ws.core.soap.SOAPConnectionImpl.callInternal(SOAPConnectionImpl.java:143)
          at org.jboss.ws.core.soap.SOAPConnectionImpl.call(SOAPConnectionImpl.java:64)
          at bizlayer.mdxquery.XmlaQuery.invokeXmlaService2(XmlaQuery.java:230)
          at org.apache.jsp.web.admin.testsoaclient_jsp._jspService(testsoaclient_jsp.java:61)
          at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
          at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
          at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
          at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
          at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
          at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
          at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
          at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
          at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
          at java.lang.Thread.run(Unknown Source)
      20:50:59,881 INFO  [STDOUT] java.io.IOException: Could not transmit message

        • 1. Re: Invoking a web service from JBoss AS as a client
          pschor

          I run the same class on JBoss 6.0 and worked beautifully, with no changes. Didn't have to move the jars to the endorsed directory. Luckily I can wait until a stable/production version of JBoss 6.0 is released. My advice is to NOT spend time with webservices in JBoss 5.0 + JDK6.