invoke webservice dynamically using java - java

i want to invoke a web service based on the url and method name,when given the input parament in xml format ,i need to invoke the web service ,but i can't generate the client stub using tools like wsdl2java because the url and method name are given dynamically so these class aren't compiled.
for example,http://localhost:9090:/hello?wsdl there have a method
string sayhello(String []names); the input param likes <arg0>john</arg0> <arg0>lucy</arg0>
it seems that i need to generate soap request in code so is there any library can help me do this?
thank you for giving any recommendation!

That's possible and yes, you will need to generate the SOAP request yourself and also parse the reply yourself.
Some links to help with this including source code etc.:
SoapUI (complete source code of a generic SOAP client including a nice UI)
http://anshu-manymoods.blogspot.com/2009/10/how-to-simple-generic-soap-test-client.html
http://www.java-tips.org/other-api-tips/httpclient/how-to-send-an-xml-document-to-a-remote-web-server-using-http-5.html
http://biomoby.open-bio.org/CVS_CONTENT/moby-live/Java/docs/soapServlet.html
http://www.soapuser.com/ngx_22jul01.html
IF JavaScript is an option you can check this out...

There's SAAJ but it's pretty verbose.
If you can use Spring, Spring-WS has a number of client options.
You can always just build up the XML by hand, too (and parse the returned XML).

Related

Calling Ab-initio web service from java

I have created a web service in Ab-initio, I want to call that web service from java, I have read a lot information from help file. It gives me some information about plugin, but they have not mentioned it specifically that how to call service mentioned in plugin from java. Will anyone please guide me through it.
Thank in advance.
Assuming you are using SOAP as your transport mechanism in RPC Subscribe -> Read XML Transform, the following link gives you a working example of a SOAP client:
Working Soap client example
if you can test your web service using the component Call Ab-Initio RPC, and a record format of:
include "~$AB_HOME/connectors/RPC/rpcheader.dml";
include "~$AB_HOME/connectors/SOAP/SOAPRequest.dml";
metadata type = record
rpcheader hdrs;
SOAPRequest soaphdrs;
utf8 string(big endian integer(4)) body;
end;
then modifying the java code in the link to assign appropriate field name values should work.

Is there a way to get the raw SOAP request from a SOAP based Web Service in a Java application

I am working on an application, that will pass client input to a vendor using web services. As phase I of the project, the vendor provided us with the XSD's and WSDL information. I used apache CXF to build the client jar. Now the issue I am facing is that, as part of the requirement, I need to send them the SOAP Request in an encrypted(I have taken care of the encryption part) XML file, that they will manually process, and send me back the response in another XML file that I need to parse and retrieve the response object.
Is there anyway to use the client jar in a dummy mode or something, where it looks like we are calling the client, but all we are doing is getting the raw SOAP request to a file
I kind of a hit a dead end and I am not totally sure how to proceed here, any help or suggestions would be appreciated
You might try SoapUI, it's a free web service testing tool. I know you can view the raw data of your soap request and response with it. soapUI

Extracting SOAP request from wsdl using wsdl4j

My inputs consist of a WSDL file and an operation name. I need to create a SOAP request and response XML instance after parsing the WSDL. What are my options to implement this? Which parser should I use? I tried wsdl4j. I was able to retrieve the Schema Object. But how do I convert this schema object to a SOAP Request in XML? I was not able to figure that out.
Did you try to use soapUI software ? I always used it in order to validate my manualy written SOAP requests (to a WSLD webservice), but it could give you the target direction
Try membrane SOA SOAP Model library.
Example code:
http://www.membrane-soa.org/create-soap-request.htm
Note: This is not a promotion. Membrane SOA is apache 2.0 licence project and I have no relation with it, except a user. Adding URL is only for helping.

Using a Web-Service with Java Servlets

I'm trying to develop a very simple Java web application using JSP and Servlets.
1) There is a textbox and a submit button on the page,
2) The user enters his name, say John, to the textbox and clicks the button,
3) The string is forwarded to my servlet,
4) At the doPost method of my servlet, I access the posted string variable,
5) The web service I'll use has a sayHello method that takes an argument and returns "Hello " concatenated with the argument,
6) So, I call the sayHello method of the web-service, get the returned variable and forward this to a JSP, which basically writes Hello John.
I'm familiar with the JSP and Servlet thing, but I don't know how to use an already existing web-service, or how to make use of a functionality that is already implemented in that web-service.
All I have is the name of the method, sayHello, the URL of the web service, http://example.com/hello_service and a link to a wsdl file which contains xml-like code that I do not know how to make use of.
My question is, how do I make use of that web service, or how do I call a method inside a servlet?
Thanks in advance.
I'm using Eclipse for JavaEE Developers. How do I generate a client automatically?
Drop the WSDL file in your dynamic web project (or create a new project for it), rightclick it, choose Web Services > Generate Client, complete the wizard with default settings. A new package will be created where the generated WSDL client code is been placed. One of those classes have a ServiceLocator in the classname.
In the servlet, you need to instantiate the ServiceLocator class, get the SOAP service from it and then invoke the desired methods on it. Further detail can't be given since the WSDL is unknown.
See also:
Eclipse - Creating Web Service Client (Eclipse's own tutorial does it bit differently)
You can use "wsimport" from jax-ws to generate a client jar for the web-service. Then, including the client jar in your classpath, you can call the web service just like you would call any regular method.
you have to create client stubs which will be part of your code project (which has the servlet). The WSDL defines how to generate these stubs. The you can call the methods in the stub from your servlet. You can use a variety of tools to generate these stubs, Axis2 is one of the most widely used.
Here is the apache Axis2 documentation which tell you how to do it.
This stub will have the methods that the wsdl has defined. You will basically call these methods and internally the stub implementation (autogenerated from wsdl by axis2) will create the SOAP request based on the arguments you pass to the method. Then it will send this request over HTTP or HTTPS to the webservice URL. You will feel like you're calling code that resides on your machine, but internally it makes the call to remote webservice.

How to match SOAP responses to the schema

Hi I am trying to evaluate a web service. I am using the Axis API to create the requests. I send requests with some attacks, and then want to validate the obtained response to the response schema. I don't have much idea as to how can I achieve this. Can some one help me to achieve this, or give me some pointers that would give me some idea to obtain this.
If you used the wsdl2java tool that comes with Axis2, the response message will be unmarshalled to the generated classes, and you will get an error if the reponse message does not correspond with the classes generated from the WSDL. So in this way you have a kind of implicit validation.
Jens-Martin is correct. If you're using the client generated by Axis wsdl2java, all the validation you need is happening behind the scenes. There are two kinds of validation going on:
SOAP has a schema definition, and the response must be a valid SOAP response or the client will throw an exception.
The WSDL you used to generate the client described what goes in the SOAP envelope of the response. If the response you get doesn't match, the client will throw an exception.
If you really feel compelled to write your own XML parser/validator and SOAP handler, you're on your own.
Try SOAPUI. It is quite a powerful open source testing tool for web services. You can construct test suites, do performance testing, and specify customized validation criteria.

Categories

Resources