How to test cxf generated SOAP client? - java

I have generated classes from a wsdl using wsdl2java from CXF. This wsdl has securitypolicy which uses security token though.
Could someone guide me how to test this client? I am stuck as the client tries to obtain a token from a mock server I built using WireMock, but it cannot as the mock server does not know how to respond.
Thanks!

Try generating server side classes using cxf and implement the server side method to respond with proper response.
Again this is kind of simulator which you build using cxf.

I'm answering my post again.
So there is no straightforward way of doing this as it is very difficult to mock a server with the security policies implemented.
Thus, what I did is create another service without the authentication part and tested it. We can also say that we don't need to test the authentication part as cxf anyways handles it.

Related

How to POST XML using CXF client?

I'm experienced in creating soap webservice clients with cxf and jaxb.
However now I have a jaxb java mapping class, and have to send this as XML using HTTP POST/1.1 to a URL path.
Question: can this be done using cxf? Or if not, with spring? I especially need (de)-serialization of request and response, automatic logging, etc. Just as it is the case with cxf soap clients.
Yes, you can use CFX for JAXWS clients. You simple need the WSDL from the service provider. Then you use wsdl2java tool to turn the WSDL into Java stub code that you then compile along with your application.
There is a really good guide here.

How to use WSDL url to create a request for data

I have a WSDL url(http:localhost:8080/userdata?wsdl) and I want to create a request to this webservice so I can fetch the data for further processing. Can I do this without wsimport?
If I have to create package from wsimport, how I can create a client which will use generated classes to create the XML request?
If I can do this without wsimport , how I can create a client which will create the XML request?
New to webservices, links to documentation would be appreciated. I am trying to understand this at the moment http://java.dzone.com/news/5-techniques-create-web-servic
You can use CXF wsdl2Java to generate a client code for the web service.
Once you run the wsdl2java , you will get a set of java classes generated for you. You can then use those classes to call the services without any explicit conversion of XML - the underlying framework will do it for you automatically. You can start with http://cxf.apache.org/docs/how-do-i-develop-a-client.html
I proposed CXF while you can look for many other alternatives - However, i have found CXF to be very feature rich and will help you in developing/working with web services.
On top of what Akhilesh said you can also create a Dynamic client for invoking WSDL. I have done it recently and i found it a little bit better then using CXF as dynamic client does not generate any code whatsoever. You just pass in the parameters to it and it does all the job for you. You can find a "shell" to build your own client HERE

What is purpose of CXF or Spring WS

I am new to consuming web services. I am trying to consume a SOAP service. This is currently in the test environment. What I have done is
Use wsdl2java to generate a wsdl that I have copied to my domain folder.
Use the API to send requests and receive responses.
What concerns me is do I need CXF or Spring WS to wire the service or is what I have sufficient. I am asking this because I have seen elsewhere like
What I don't get is where I would generate property when environments are switching from development to QA to production. And do I need to use CXF or Spring WS or are the annotated classes (#WebServiceClient sufficient) to consume the SOAP service. Basically, how to connect to different endpoints.
I apologize if this is rudimentary question. Thanks.
Spring-WS and Apache CXF are primarily useful for creating web-services. They are alternative web service implementations to the one that ships with Java6.
You can use them for writing clients, but there's not really much point, unless you're really keen on the alternative API that those provide.
The standard JAX-WS artifacts generated by wsdl2java should be perfectly sufficient for what you need.
As for your second question regarding how to target different prod/QA endpoints, you should ask a separate question for that, with full examples of what you have.

Remote Web Services

I am new to web services. I have a requirement in my project. I have to consume the web services of our vendor in my project. All he has shared with me is a WSDL file and a document about the description of the the different operations.
Question:-
1: What do I need to do consume these web services in my java project? I have been advised to use axis2, eclipse with tomcat6.
2: Do I need to ask for some other files/information from WS vendor OR wsdl file is enough to consume these web services?
3: Do I need to write a java WS client (using axis2 plugin) or another webservice which will talk to vendor web service?
Please suggest the best possible way.
I am sorry if the question sounds like a naive..
Axis is a solid choice for such application.
You need to generate an axis client based on the provided WSDL. Then you import the generated client and use it's methods. You can see the details of this process here (read whole page or starting from the linked section): http://ws.apache.org/axis2/1_0/userguide3.html#Writing_Web_Service_Clients_using_Code_Generation_with_Data_Binding_Support
You could also need some entry-point (WebService URL).
You need to generate a client, not a webservice. See point 1.
Don't use Axis if you need ambient authentication in a Windows environment. I went down that path and ended up going with Apache CXF - which seems better to me anyhow.
You can use SOAP UI to test the web service. It'll read the WSDL, let you create requests by filling in values, and display the response that you get back. It might help you get a better understanding of what the service does before you start writing your classes.
You don't need to create a new web service in order to consume a web service, you need to write a web service client.
Similar question to this one:
Steps in creating a web service using Axis2 - The client code
All the standard web frameworks have a command (normally called wsdl2java) that will read the WSDL and then generate a java based client object.
I can recommend Axis2, but another popular choice is CXF

How to Consume SOAP 1.2 Web Service Created in WCF by a Java Client?

I'm developing a Web Service Project in which I have to implement a web service that should be interoperable on all platforms. So initially I used basicHttpBinding as it uses SOAP 1.1 but I want the features of WS-* like reliable messaging, security, exceptions. So I used wsHttpBinding which is a SOAP 1.2 standard.
Now after deploying on my test server I used Netbeans IDE to generate a webservice client. So in return it called the wsimport tool in java to generate proxy classes. When I invoke any method it simply goes into non-working state like there is no activity for 5 mins. So I'm not able to figure out that whether Java client can consume a SOAP 1.2 web service created in WCF?
I need to know if I need to use any other binding than wsHttpBinding for all the features and have interoperability as well.
I don't get any error when i invoke the web method.I tried debugging it but to no help.i set break-point on the line which was invoking the method,when debugger reaches that line then nothing happens, IDE shows running status but there is no activity.If anyone can suggest a tool to monitor Http request to server.
Have you tried tracing the communication between the Java client and the WCF service?
I would do two things first, turn on logging in WCF; use a trace tool (there are many tike tcptrace) to act as a proxy between the client and server, then point the client at the trace tool and the trace tool at the server. That way you get to see the traffic and the XML (if any) sent back and fore. That should give you a much better idea as to what is going on.
Why not configure another endpoint using SOAP 1.1?

Categories