I have a wsdl file and a detailed document about all the elements in every request and response from a web-service provider. My job is to compose around 40 requests and parse corresponding responses.
More specifically, our platform submits the requests and gets responses from the service, so for me, as an application developer, I only need to compose soap requests and pass them as String to the platform. I also get response as String from the platform.
I tried StringBuilder, but it looks pretty primitive. It has to be a better way to do it.
Can I put all the requests in an xml document and somehow generate requests from it?
Or even better, is it possible to generate requests from the wsdl file?
Thanks,
Sarah
Have a look at the wsdl2java utilities (there are several versions, one packaged with Axis2, another from IBM, etc.). These can generate client stubs from your WSDL, and should save you a considerable amount of work.
EDIT: Just realized that this may require some additional work since you say your platform submits the requests. The generated code should be attempting to submit strings to the service if that is what's specified by your WSDL, perhaps you can modify the code to pass the strings to your platform?
JAX-WS's wsimport
Client stubs w/ XFire
Axis2's wsdl2java
IBM's wsdl2java
You can use SAAJ API for this purpose.
For more details visit these links:
http://docs.oracle.com/javaee/5/tutorial/doc/bnbhg.html
https://saaj.dev.java.net/nonav/spec-1.3/api/
http://lia.deis.unibo.it/Courses/TecnologieWeb0708/materiale/laboratorio/guide/j2ee14tutorial7/SAAJ3.html
The simplest way is soap-ws library: https://github.com/reficio/soap-ws
SoapClient client = SoapClient.builder()
.endpointUrl("http://rpc.middleearth.com")
.build();
client.post(envelope);
Related
I have to write a REST client to consume a service written in .Net. The problem is that the .Net service returns a gzip compressed serialized DataSet. How do I parse it? I have seen other solutions explaining how to do it using SOAP (I have to use REST). Another solution says to write a .Net proxy. But my deployment server is a linux machine with limited access so I may not have the luxury of using tools like Mono.
The folks exposing service haven't provided any wsdl specs. Just given ways to construct URLs that when invoked will return what I need. So what's my way forward :
Try SOAP? Is that even possible? I have no wsdl info. So I assumed it will be REST.
Create a .Net proxy that consumes this service and converts to more readable xml, and find ways to make this .Net exe run on linux?
Continue searching for a solution/library that can read DataSet? I have been developing clients using Spring RestTemplate which doesn't seem to work here.
Also, accessing the URL from Advanced Rest client shows that Content-Type: compressed/DataSet
So I had to end up creating a .Net proxy that decompresses and deserializes the DataSet response, convert to xml and save at a shared location from where Java program can pick up.
I want to run some integration tests on a WSDL client application. Therefore I'd like to have the WSDL server (which is not in control of me) to response with the same xml response always.
How could I achieve this? Is there any tool out that offers a wsdl endpoint an can always return the same xml (which I then could take from my live logs)?
SOAPUI offers this functionality. I've used it before with ease.
Alternatively if you do not want to go through the hassle of converting the WSDL request to a meaningful response, take a look at services like mocky which simply echo back a payload.
Take a look at Soap-UI - it has the ability to mock web services exactly as you mentioned using just a wsdl. You can then decide which XML the mocked web service will return, and it will run as a server locally. Instead of pointing to the 'real' server you can then point to your own local endpoint in order to retreive the same response. More information available on my blog here
I am using Apche Axis2 for a web service client. I know to get the output of a web service. But I want to get the soap Request and response from the wsdl file.
My wsdl is http://localhost:8080/getDetails?wsdl
It would be great if some can share their experiences.
Thanks in Advance.
If you want to use a software for that, use SoapUI.
If you want to do it from Java, you have these options.
Generate the classes for a SOAP Client using wsdl2java command.
There are many ways of doing this depends on the implementation you used.
Generate the classes for a SOAP Client using maven plugin, use this axistools-maven-plugin
After this search for a class having a name "...Locator" and "..PortType", use these classes.
OR,
Search for an Interface which has all the exposed methods and find a way to implement it.
Use SoapUI Tool , provide your WSDL path to this tool , it will load all operations from WSDL once if you click on perticular operation you can get sample SOAP request(XML payloads).
I am doing a project using Java and BPEL. I successfully created webservices in Java and integrated them using BPEL. All i generated a single output WSDL file. Now, I have to use this output WSDL file in my application using SOAP communication. How can i do that? Is there any help out side for such scenarios? Walkthroughs are really appreciated..
Depending on the architecture of your application (Standard Java, Spring-based, ...) there might or not be a documented procedure to consume a SOAP-based webservice.
On the other hand, you're always free to pick a webservice development framework to handle that. For instance, you could pick either CXF or AXIS2 (I believe these are the two most popular frameworks for Java WebServices). Each of these frameworks provides a tool called "wsdl2java" that helps you generate client-side/server-side/both Java classes. Then, you can easily add those classes and the requireds libraries to your application.
Having used CXF in the past, It even does provide several way to consume a webservice
Generating the client-side classes
Using CXF dynamic client factory : basically, you'll retrieve an endpoint proxy from a factory object.
Hope that'll help
I start with SoapUI (or downloadable from sourceforge), that will let you consume the WSDL and fire off requests against your server. Typically I'm hitting someone else's webservice, and trying to figure out what the data looks like before I start wiring my code together, but in your case its just a verification that the services would be/are working.
Then, as #KHY said, you can automatically convert the wsdl into java with a wsdl2java and start coding (look under the Related list on the right panel of this SO screen)
If it is a Java application, then the easiest way to consume a service is using JAX-WS. It's really easy to create a Web service client from WSDL.
See this link
Once you deploy the BPEL project on server, then refer the WSDL with http://server:port/application/YourBPELProjectService?WSDL in the consuming application. You will need to write different client code based on the BPEL type - Synchronous, Asynchronous etc.
I want to send a request to a web service, and read the response.
So far, I used JAXB to generate Java classes from an XSD, which I am assuming I will use to read the response?
What is the best way for me to implement the request? The web service I am using is a servlet and requires a POST. Is my only option to send a string that is a SOAP request using HttpURLConnection?
I recommend a visit to Apache CXF. What you want is not just naked JAX-B, but a JAX-WS+JAX-B service, which will take care of all this for you. In particular, you can use a JAX-WS provider to create a soap endpoint when there is no WSDL.
If you say you're in control of the other party - or actually you are that party because you just want to do remoting between two JVMs, then use another remoting solution. Depending on your needs, you could use something like protobuf, hessian, or something like Terracotta.
These frameworks are much easier to use and far more efficient.