I have a servlet to a webservice in java,
I have a servlet that process user information ,(registeration) and return a result as a string , how do I use that servlet as webservice to be called and do the same thing?
Look at JAX-WS that is a Java specification for webservices, making a POJO service available as a Webservice Soap Endpoint.
http://jax-ws.java.net/
You may need to move your code from your servlet to a POJO class.
There are several methods depending on your need.
I found the WebService Axix User guide quite useful here -> http://ws.apache.org/axis/java/user-guide.html
It contains description on how to use the Java2WSDL tool which ultimately allows you to publish your final webservice. http://ws.apache.org/axis/java/user-guide.html#Java2WSDLBuildingWSDLFromJava
Related
I was wondering if it was actually possible to create a Java SOAP Webservice without using it's WSDL.
Context:
The idea is that I have to mock a webservice, so I have its WSDL. The mock will only read the soap request, search if there are any similar request (as key in a map) and send the matching response (as its value). This is for automated testing purpose. The problem is not the "map" part.
Anyway, I've been using Axis and eclipse to generate classes and files and load them in tomcat from the WSDL. So far it've been a mess, with a lot of compatibility issues between these components. And it's gonna be much more difficult to compare the input or serialize the output to do what I want this way.
I thought about creating a REST endpoint and send the soap request through it (so I would directly get the SOAP request !), but I rode somewhere that soap request weren't valid and wouldn't be retreived by the REST endpoint... Also, won't the client application throw an error if there is no WSDL at this address ?
My question is:
Is there a way to create an access point, that looks like a SOAP Webservice (from clients), but which allows me to get the full soap request (as a String for example) and send a response (still as a String) inside a Java app?
Complements:
I'm looking for something, a library, maybe just an annotation on Servlets, that doesn't needs (if possible) to generate a huge load of classes and xml files everywhere. The app would be running on tomcat (but I can be a basic Java app). Using maven and spring wouldn't be a problem.
Thanks in advance !
Normally, clients do not require an WSDL. But it is a nice feature - use a normal servlet and handle the "?WSDL" manually. Then use some simple XPath or parse logic to extract the payload as a DOM document.
I'm trying to develop, using Java, a simple application that call a web-service restful which returns an xml and then I need to provide the result to a jsp page.
I was thinking to use CXF but what is not clear is the fact that the restful service can have different urls with parameters like:
http://ws-host.com/rest/products?BRAND=020&LOCALE=en_gb?product_code=600200
http://ws-host.com/rest/products?BRAND=020&LOCALE=en_gb&VEHICLE_BRAND=test
or
http://ws-host.com/rest/dealers?BRAND=020&LOCALCE=en_gb&SEARCH_TERM=Test
How can I do that? I'm a bit confused.
Thanks
CXF supports JSR-339 spec so you can use this API to create your mappings with different parameters.
You can use #QueryParam annotation, here is an example
I have to request a PHP page with 3 Parameters (e.g. www.test.com/index.php?name=mrTest&no=1&id=10001). I'm using WSDL2JAVA for other Services and am now wondering if it is possible to generate a similar Service for this case. This PHP page Returns an XML. I'm just consumer/client of the Service.
I could also make a simple request and then use JAXB to parse the XML but i would like to implement all my Services the same way.
So, does anybody has already implement a php page consumer using WSDL2JAVA?
Best regards
So from my understanding this is a simple PHP page not a SOAP service. Remember XML is just the protocol used in a SOAP service however a SOAP service consists out of a WSDL that is published describing operations and how to call those operations.
A simple PHP page even if it returns XML data is NOT a SOAP service and thus does NOT have a WSDL. You wont be able to use WSDL2JAVA for that.
This PHP page seems more like a REST type service that returns XML instead of JSON. To be honest it really sounds like a REST service.
Try using the latest SOAPUI to connect to the page and see if you can use the REST project type with this page. If it is a REST service it might have a WADL file. YOu can use the WADL2JAVA cxf utility to generate classes to you. HOwever this is a BIG might as most REST services dont use WADL's yet. See this link on CXF
I have experiences in creating clients to a SOAP Webservice using JAX-WS. Therefore I'd mainly create a #WebService class with #WebMethod methods that take #WebParam params and return a #WebResult.
Mostly I start using CXFto auto-generate the Java classes from theWSDL`.
But what if the webservice is a GET service instead of a SOAP, like http://www.cleartrip.com/places/hotels/info/41748.
I can use a XSD accordingly to auto-generate my Java classes to JAXB as well.
But how do I then call that GET-Service? Which framework will assist me here? Is it also possible with JAX-WS?
You are confused because this is a restfull service and not a SOAP web service, java has an API for accessing restful services easily, see 'https://jersey.java.net/documentation/latest/getting-started.html' for more info.
What you call a GET service looks like a RESTful service. Take a look at JAX-RS 2.0 and the new client API.
I wrote a java web service on Netbeans 6.9.1 and deployed on GlassFish 3.0.1
I have a wsdl url like this "http://localhost:8080/web2/service2Service?wsdl".
How can I use this url to access this web service from another java application.
Thanks
You need to generate some Java that represents the client's view of the Web Service and then invoke that Java. Here's an article which explains some of the detail.
Generating client from WSDL in Eclipse
The general idea is that you generate some Java classes from the WSDL. Those classes act as a proxy for the service you want to call. Your java invokes methods on the proxy objects, the generated code creates the appropriate SOAP messages, sends the HTTP request, interprets the response and your code just sees a Java result.
I just use the tooling built into Eclipse, but you will also find other suitable generators, for example in Apache's Axis
1º U must save the content in a "myWebServices.wsdl" file
2º Run your Wsdl converter, all compilers have one of this, normally the name is WDSL.EXE
This process will create a new file with NameSpace or Package with the definitions of webservices built in.
3º Then imports this package or built a library.
Develop web service Client in second application.
You can use Netbeans to create web service client by giving your wsdl url
The document at this url is the actual wsdl (a description of the actual webservice, written in WebService Definfition Language).
The description includes information about the services url, the protocol(s), the method names and and data objects. Your application will use that information to call the remote methods of that service.
The protocol may or may not be SOAP, and without knowing the webservice details, it's quite impossible to recommend a toolset or methodology to use the webservice, there is no general approach. In most cases we see SOAP, for those services I recomment soapUI as a general tool to use and test SOAP based webservices and apache axis to implement java based service consumers.