[JBoss Web Services] - Invoking a web service from JBoss AS as a client
by Peter Schilling
Peter Schilling [http://community.jboss.org/people/pschor] created the discussion
"Invoking a web service from JBoss AS as a client"
To view the discussion, visit: http://community.jboss.org/message/564010#564010
--------------------------------------------------------------
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/ http://schemas.xmlsoap.org/soap/envelope/\"" +
" SOAP-ENV:encodingStyle=\" http://schemas.xmlsoap.org/soap/encoding/ 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 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/ http://schemas.xmlsoap.org/soap/envelope/' SOAP-ENV:encodingStyle=' http://schemas.xmlsoap.org/soap/encoding/ 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
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/564010#564010]
Start a new discussion in JBoss Web Services at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
14 years, 2 months
[JBoss Tools] - Using the Annotation Properties view to create an ESB 4.9 Action
by Brian Fitzpatrick
Brian Fitzpatrick [http://community.jboss.org/people/bfitzpat] modified the blog post:
"Using the Annotation Properties view to create an ESB 4.9 Action"
To view the blog post, visit: http://community.jboss.org/community/jbosstools/blog/2010/09/30/using-the...
--------------------------------------------------------------
In my http://community.jboss.org/en/jbosstools/blog/2010/09/13/extending-the-ec... last article, I talked about how to extend the Annotation Properties view provided as part of WTP in Eclipse Helios. And that gets into the implementation details of adding your own annotations.
Here, I'd like to focus on how you'd use the view in conjunction with ESB support in JBoss Tools to actually create a new ESB action using the annotations added as part of ESB 4.9. Now instead of extending the AbstractActionPipelinedProcessor class you can create your own POJO and annotate to indicate various configuration options, as documented http://community.jboss.org/docs/DOC-15525 here.
Let's say you want to create a simple PrintMessageAction, similar to the example that extends AbstractActionPipelinedProcessor, but want to see the differences between the two implementations. (You can find the original example implementation in the ESB Programmer's Guide http://docs.redhat.com/docs/en-US/JBoss_Enterprise_SOA_Platform/5/html/ES... here.)
The original example code looks like this (Listing 1):
public class PrintMessage extends AbstractActionPipelineProcessor { private String information; private Integer repeatCount; public PrintMessage(ConfigTree config) { information = config.getAttribute("information"); repeatCount = new Integer(config.getAttribute("repeatCount")); } public Message process(Message message) throws ActionProcessingException { for (int i=0; i < repeatCount; i++) { System.out.println(information); } }}
As you can see, if you already had a PrintMessage class, you'd have to revamp it a bit to get it to work. Let's say you have this class (Listing 2):
import org.jboss.soa.esb.message.Message;public class PrintMessage { private String information; private Integer repeatCount; public void printMessage(Message message) { for (int i=0; i < repeatCount; i++) { System.out.println(information); } }}
If you use the new ESB annotations available in ESB 4.9, this becomes much more straightforward (Listing 3):
import org.jboss.soa.esb.message.Message;public class PrintMessage { @ConfigProperty // this will come from the ESB configuration private String information; @ConfigProperty // this also will come from the ESB configuration private Integer repeatCount; @Process // and this is the actual action that will get invoked public void printMessage(Message message) { for (int i=0; i < repeatCount; i++) { System.out.println(information); } }}
By now you're wondering - so how does the tooling come into this? Well, with the new Annotation Properties view and the ESB annotations we hooked up in the upcoming JBoss Tools 3.2 Beta1 release, you can let the tooling add the annotations for you.
In JBoss Tools, let's say that you have your original PrintMessage class (Listing 2) open in your ESB project and you want to turn it into an ESB action you can configure for the project.
To open and use the Annotation Properties view
1. Go to Window->Show View->Other
2. Type "Annotation" in the search box
3. Select JAX-WS->Annotation Properties
http://community.jboss.org/servlet/JiveServlet/showImage/38-1970-9586/ann... http://community.jboss.org/servlet/JiveServlet/downloadImage/38-1970-9586...
4. Click OK.
By default, all available annotations are enabled in the view. This will most likely cause you to see a message such as "No suitable library can be found on the projects classpath." To get around this since we're just interested in ESB annotations at this point, we simply filter out the other types.
To change the filtered annotation types:
1. In the View Menu for the Annotation Properties view, select "Filters..."
2. When the Selection Needed dialog appears, make sure that all other annotation types are checked except for JBoss ESB http://community.jboss.org/servlet/JiveServlet/showImage/38-1970-9584/ann... http://community.jboss.org/servlet/JiveServlet/downloadImage/38-1970-9584...
3. Click OK
Now, with your PrintMessage class open and the Annotation Properties view open and filtered for ESB annotations, select the "information" class variable. In the Annotations list, you should see org.jboss.soa.esb.configure.ConfigProperty appear, as in the following image:
http://community.jboss.org/servlet/JiveServlet/showImage/38-1970-9541/Inf... http://community.jboss.org/servlet/JiveServlet/downloadImage/38-1970-9541...
If you click the "Values" checkbox beside the ConfigProperty annotation, you'll see @ConfigProperty() appear above the variable. Do it again for the repeatCount variable as well.
http://community.jboss.org/servlet/JiveServlet/showImage/38-1970-9542/rep... http://community.jboss.org/servlet/JiveServlet/downloadImage/38-1970-9542...
The last step is to click on the method line for printMessage(Message message) and check the @Process annotation box.
http://community.jboss.org/servlet/JiveServlet/showImage/38-1970-9543/pri... http://community.jboss.org/servlet/JiveServlet/downloadImage/38-1970-9543...
And that's it for this example. You'll notice if you look closely at the @ConfigProperty annotation in the Annotation Properties view that you can expand it and set different properties on the annotation as well. So there is room for further configuration there.
Once you configure your action in an ESB configuration file and deploy it, you can test it. In this case, I'm using a simple JMS queue to send a message to the service to trigger it. The action gets the configuration from the properties we set in the jboss-esb.xml file, and we can see the output in the console:
http://community.jboss.org/servlet/JiveServlet/showImage/38-1970-9583/esb... http://community.jboss.org/servlet/JiveServlet/downloadImage/38-1970-9583...
So starting with the JBoss Tools 3.2 Beta you'll have some new tools in the ESB toolbox for custom actions!
--------------------------------------------------------------
Comment by going to Community
[http://community.jboss.org/community/jbosstools/blog/2010/09/30/using-the...]
14 years, 2 months