<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Invoking a web service from JBoss AS as a client
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/pschor">Peter Schilling</a> in <i>JBoss Web Services</i> - <a href="http://community.jboss.org/message/564010#564010">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>I've been trying to figure this out for several days, any help will be appreciated.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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 <span style="text-decoration: underline;">same </span>method called from a plain Java object and invoked from a command line (using JDK's WS jars instead of JBoss') <span style="color: #333333; text-decoration: underline; ">works perfectly</span>.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Three things that are different from the case when the method is invoked successfully from the command line:</p><ul><ul><li>In the request STDOUT the XML version header was removed (probably by SaveMessage).</li><li>In the request STDOUT quotes were converted to apostrophes.</li><li>Even thought the content type is set as text/xml, the error says content type is text/html</li></ul></ul><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Thanks for your help</p><p>Peter</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The method and the output/error:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>try {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            // Create the SOAP connection</p><p>            SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();</p><p>            SOAPConnection connection = soapConnFactory.createConnection();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>             String soapText =  </p><p>                 "<?xml version=\"1.0\"?>" +</p><p><span>                "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"</span><a class="jive-link-external-small" href="http://schemas.xmlsoap.org/soap/envelope/" target="_blank">http://schemas.xmlsoap.org/soap/envelope/</a><span>\"" +  </span></p><p><span>                 " SOAP-ENV:encodingStyle=\"</span><a class="jive-link-external-small" href="http://schemas.xmlsoap.org/soap/encoding/" target="_blank">http://schemas.xmlsoap.org/soap/encoding/</a><span>\">" +  </span></p><p>                 "<SOAP-ENV:Header/>" +</p><p>                 "<SOAP-ENV:Body>" +</p><p>                 "<Discover xmlns=\"urn:schemas-microsoft-com:xml-analysis\">" +</p><p>                 "<RequestType>DISCOVER_DATASOURCES</RequestType>" +</p><p>                 "<Restrictions><RestrictionList/></Restrictions>"  +</p><p>                 "<Properties><PropertyList><Format>Tabular</Format></PropertyList></Properties>"  +</p><p>                 "</Discover>"  +</p><p>                 "</SOAP-ENV:Body>" +</p><p>                 "</SOAP-ENV:Envelope>";</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>             // Create SoapMessage  </p><p>             MessageFactory msgFactory     = MessageFactory.newInstance();  </p><p>             SOAPMessage message           = msgFactory.createMessage();  </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>             // Load the SOAP text into a stream source  </p><p>             ByteArrayInputStream stream   = new ByteArrayInputStream(soapText.getBytes());  </p><p>             StreamSource source           = new StreamSource(stream);  </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>             // Set contents of message   </p><p>             message.getSOAPPart().setContent(source);  </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>             MimeHeaders mh = message.getMimeHeaders();</p><p>             mh.setHeader("Content-Type", "text/xml");</p><p>             mh.setHeader("SOAPAction", "\"urn:schemas-microsoft-com:xml-analysis:Discover\"");</p><p>             //Save the message</p><p>             message.saveChanges();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            //Check the input</p><p>            System.out.println("HEADERS:\n" );</p><p>            Iterator<MimeHeader> i = message.getMimeHeaders().getAllHeaders();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            while ( i.hasNext() ) {</p><p>                MimeHeader header = i.next();</p><p>                String name = header.getName();</p><p>                String value = header.getValue();</p><p>                System.out.println ( name + ": " + value);</p><p>            }</p><p>            System.out.println("END HEADERS:\n" );</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            System.out.println("REQUEST:\n");</p><p>            message.writeTo(System.out);</p><p>            System.out.println("END REQUEST:\n");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            //Send the message and get a reply   </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            //Set the destination</p><p><span>            String destination = "</span><a class="jive-link-external-small" href="http://localhost:7070/mondrian/xmla" target="_blank">http://localhost:7070/mondrian/xmla</a><span>";</span></p><p>            //Send the message</p><p>            SOAPMessage reply = connection.call(message, destination);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            //Check the reply</p><p>            System.out.println("\nREPLY:\n");</p><p>            reply.writeTo(System.out);</p><p>            System.out.println("\nEND REPLY:\n");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            // Close the SOAP connection            </p><p>            connection.close();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        } catch(Exception e) {</p><p>            System.out.println(e.getMessage());</p><p>        }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>20:50:45,855 INFO  [STDOUT] HEADERS:<br/>20:50:45,855 INFO  [STDOUT] Content-Type: text/xml; charset=UTF-8<br/>20:50:45,855 INFO  [STDOUT] SOAPAction: "urn:schemas-microsoft-com:xml-analysis:Discover"<br/>20:50:45,855 INFO  [STDOUT] END HEADERS:<br/>20:50:45,855 INFO  [STDOUT] REQUEST:<br/><span>20:50:45,855 INFO  [STDOUT] <SOAP-ENV:Envelope xmlns:SOAP-ENV='</span><a class="jive-link-external-small" href="http://schemas.xmlsoap.org/soap/envelope/" target="_blank">http://schemas.xmlsoap.org/soap/envelope/</a><span>' SOAP-ENV:encodingStyle='</span><a class="jive-link-external-small" href="http://schemas.xmlsoap.org/soap/encoding/" target="_blank">http://schemas.xmlsoap.org/soap/encoding/</a><span>'><SOAP-ENV:Header></SOAP-ENV:Header><SOAP-ENV:Body></span><br/><Discover xmlns='urn:schemas-microsoft-com:xml-analysis'><RequestType>DISCOVER_DATASOURCES<br/>20:50:45,855 INFO  [STDOUT] </RequestType><br/>20:50:45,855 INFO  [STDOUT] <Restrictions><RestrictionList/><br/>20:50:45,855 INFO  [STDOUT] </Restrictions><br/>20:50:45,855 INFO  [STDOUT] <Properties><PropertyList><Format>Tabular<br/>20:50:45,855 INFO  [STDOUT] </Format><br/>20:50:45,855 INFO  [STDOUT] </PropertyList><br/>20:50:45,855 INFO  [STDOUT] </Properties><br/>20:50:45,855 INFO  [STDOUT] </Discover><br/>20:50:45,855 INFO  [STDOUT] </SOAP-ENV:Body></SOAP-ENV:Envelope><br/>20:50:45,855 INFO  [STDOUT] END REQUEST:<br/>20:50:59,865 ERROR [SOAPMessageUnMarshallerHTTP] Cannot unmarshall SOAPMessage<br/>javax.xml.soap.SOAPException: Unsupported content type: text/html; charset=utf-8<br/>    at org.jboss.ws.core.soap.MessageFactoryImpl.createMessage(MessageFactoryImpl.java:272)<br/>    at org.jboss.ws.core.soap.SOAPMessageUnMarshallerHTTP.read(SOAPMessageUnMarshallerHTTP.java:82)<br/>    at org.jboss.remoting.transport.http.HTTPClientInvoker.readResponse(HTTPClientInvoker.java:570)<br/>    at org.jboss.remoting.transport.http.HTTPClientInvoker.useHttpURLConnection(HTTPClientInvoker.java:369)<br/>    at org.jboss.remoting.transport.http.HTTPClientInvoker.makeInvocation(HTTPClientInvoker.java:231)<br/>    at org.jboss.remoting.transport.http.HTTPClientInvoker.transport(HTTPClientInvoker.java:161)<br/>    at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:165)<br/>    at org.jboss.remoting.Client.invoke(Client.java:1724)<br/>    at org.jboss.remoting.Client.invoke(Client.java:629)<br/>    at org.jboss.ws.core.client.HTTPRemotingConnection.invoke(HTTPRemotingConnection.java:243)<br/>    at org.jboss.ws.core.client.SOAPProtocolConnectionHTTP.invoke(SOAPProtocolConnectionHTTP.java:71)<br/>    at org.jboss.ws.core.soap.SOAPConnectionImpl.callInternal(SOAPConnectionImpl.java:143)<br/>    at org.jboss.ws.core.soap.SOAPConnectionImpl.call(SOAPConnectionImpl.java:64)<br/>    at bizlayer.mdxquery.XmlaQuery.invokeXmlaService2(XmlaQuery.java:230)<br/>    at org.apache.jsp.web.admin.testsoaclient_jsp._jspService(testsoaclient_jsp.java:61)<br/>    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)<br/>    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)<br/>    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)<br/>    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)<br/>    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)<br/>    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)<br/>    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)<br/>    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)<br/>    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)<br/>    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)<br/>    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)<br/>    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)<br/>    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)<br/>    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)<br/>    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)<br/>    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)<br/>    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)<br/>    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)<br/>    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)<br/>    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)<br/>    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)<br/>    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)<br/>    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)<br/>    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)<br/>    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)<br/>    at java.lang.Thread.run(Unknown Source)<br/>20:50:59,881 INFO  [STDOUT] java.io.IOException: Could not transmit message</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/564010#564010">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss Web Services at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2044">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>