Simple (standalone) Java SOAP web service client from WSDL using Maven - java

I'm looking to generate a simple standalone Java client which will make calls to a SOAP web service, given a wsdl. When I say simple and standalone I mean that once I'm done I want to be able to do something like
import my.generated.nonsense;
public static void main(String[] args) {
Client client = new Client();
client.getSomething();
}
I've had great time recently with Maven on some other projects and I want to keep that going, so would aim to use it here. I don't want the tool to generate anything expect the classes that allow me to do the above.
Anyone done this recently and can recommend a ws library and Maven plugin? Thanks.

Have a look at CXF and its Maven plug in. CXF would generate code similar to yours (of course web services could fail and you should add exception handling). Have in mind though that SOAP web services is a complicated topic and simplicity in the generated code may not be always desirable. Generating a client with the default settings may not work for some clients. You would then need to tweak the configuration of the code generation and/or add code to handle it. CXF is good both for easy/default clients and more complicated ones.

I would recommend SOAP UI for what you need to do. You do not need to write any code - you can call the web service from the soap UI client.
If you need to automate making soap calls you can use the maven plugin as part of your build/deploy process. More info about the maven plugin here:
http://www.soapui.org/Test-Automation/maven-2x.html

Related

Consume SOAP webservice in java, only WSDL in hand

I need to consume a web service in java/jsp code. Only the WSDL is available for me to start.
I understand I need to convert the WSDL into java client JAR file using AXIS2 / CXF but I cannot build the whole application on this.
Can someone provide a simple example or basic steps for me to start on this?
I am not able to join the dots here. WSDL, java client JAR, AXIS2.... All online tutorials point on 'creating' a web service.
There are a number of tools capable of doing this included in various frameworks and app servers (CXF, JBoss/Wildfly, etc.), but the JDK itself includes a tool called wsimport which can consume a WSDL file and produce the JAX-WS stubs you need to remotely-invoke the service endpoints via a Java client.
Here's one quick description: http://www.mkyong.com/webservices/jax-ws/jax-ws-wsimport-tool-example/; here is the Oracle documentation for the tool in JDK 7: http://docs.oracle.com/javase/7/docs/technotes/tools/share/wsimport.html.
WSDL is just the conract for the web service. You need to generate client code using it, later you can implement your code to call the web service. Like #maerics pointed out, you should use wsdl2java to generate your client code for AXIS2 and use your client to consume the web service.
You can check this link for an example of client stub generation for AXIS2.

How can I create Endpoint for WebService?

How can I create an Endpoint for a web service? I am a beginner to the web services world.
I have got the WSDL and I would like to create a web service based on that WSDL. I have used Apache CXF to generate client stubs. What would be the next steps to test it as a service?
How can I create EndPoints?
How can I mimic the WSDL soapbind address locally and test it?
Let me clarify the Question. Looks like there is confusion. Thanks #Buhake Sindi for point it out.
I have got the WSDL and generated the Client stubs by using Apache CXF Framework in Eclipse. I need to test the WebService client code whether its working or not. How to test this approach now? My WSDL URL is not working at this moment.
How to test my client stub(from generated Impl Class)?
Do I need to create any Endpoints to mimic the WSDL URL(which is not running now)?
Hope the Question is clear now...
You can test client code even without creating web service implementation also. Are you aware of SoapUI tool? Use that to import the wsdl to create a project.
It gives you the option to create a mock service also along with the request. You can run that mock service and test your client against that service without writing any service code. I use it for testing all the time. Also you can create Success, Failure, and Fault response to test different scenarios. Mock service will also show you the request received by the service. This feature works like a charm. Let me know if you need help in setting up mock service in SoapUI.
You may follow this link to get started:
http://www.soapui.org/Getting-Started/mock-services.html
You run wsdl2java from CXF to generate server-side stubs. Then you fill in the code in the stubs. Then you set up a service to deploy.
There is no mechanism I know if that will create mock services. What would you expect them to do?
See the samples from the CXF distribution, particularly the wsdl-first samples.
A better approach would be to use JMock to mock the client side SEI, and not try to come up with a dummy service.

How to see request generated by wsdl2java code?

I using a stub generated by wsld2java:
ServicesStub.ResponseMessage resp = stub.processService(rm);
Also Rampart module is engaged which includes a security header.
How can I see the complete XML request which gets send to the server?
Or if you don't want to be tied to Eclipse use TCPMON http://ws.apache.org/commons/tcpmon/
You basically redirect traffic through TCPMON and you view exactly what HTML actions happen between your outgoing webservices call (Either REST or SOAP) and you can diagnose, very useful for when SOAP faults do not properly translate to Java with useful error messages.
Eclipse has a build in tcp/monitor tool - netbeans something similar. Also possible is a normal network monitor tool like shark or a web proxy build for debugging purpose.

How to connect WSDL file in my application using SOAP service?

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.

Testing Web Services Consumer

Here are some tools that I have found to test web services consumers:
http://www.soapui.org/
https://wsunit.dev.java.net/
Are there any others? I would prefer testing frameworks that are written in Java or Python.
I have used soapui by a maven plugin. It can create junit-linke reports to be run and analysed like unit tests. This can be easily integrated in continious build, also with the free distribution of soapui.
I've used Web Service Studio.
Web Service Studio is a tool to invoke web methods interactively. The
user can provide a WSDL endpoint. On clicking button Get the tool
fetches the WSDL, generates .NET proxy from the WSDL and displays the
list of methods available. The user can choose any method and provide
the required input parameters. On clicking Invoke the SOAP request is
sent to the server and the response is parsed to display the return
value.
This tool is meant for web service implementers to test their web
services without having to write the client code. This could also be
used to access other web services whose WSDL endpoint is known.
Also the Web Services Explorer in Eclipse which comes as part of the Web Tools Platform.
Through UDDI and WSIL, other applications can discover WSDL documents
and bind with them to execute transactions or perform other business
processes. The Web Services Explorer allows you to explore, import,
and test WSDL documents.
The Grinder is right up your ally with both Java and Python, that handles most web services, (SOAP/REST/CORBA/RMI/JMS/EJB) etc.
http://grinder.sourceforge.net/
You really need to be more specific: What is it that you want to test in your WS-consumer? That it calls the right WS? This looks a bit pointless - WS are a perfect place for mocking whatever may be called - without anything being called.
In order to test the consumer you'd otherwise be writing a Webservice that mocks the original, right? I'd suppose that the communication protocol that goes through the wire is not the clients domain - e.g. it's generated. So the only thing a WS-consumer's client sees is the interface. And there's nothing to test in an interface.
It might be that I completely misunderstood your question - please clarify if I did. I'll revise the answer then.

Categories

Resources