I am developing a web service in java and Metro that requires a lot of information to be passed. For example, something like xml describing all the attributes of a customer.
I am wondering if there is some standard way in which to pass the data in a document. Currently I have been passing the data as a string parameter named 'customerXML'.
Any suggestions appreciated. FYI I have defined another restful ws using RestEasy which works great using input/output streams, but am looking for a way to leverage soap-based web services to expose similar functionality.
JAX WS is perfect for this requirement, It works on SOAP
My hypothesis is that there isn't a standard way to pass xml documents to a soap-based web service without coding the entire SOAP message yourself. Hence I do not think there is an easy way to do so and one reason why RESTful web services are gaining acceptance. The best way to do it using SOAP based web services is to pass the document as a string parameter and validate/parse within your server code.
Related
When migrating from SOAP based webservices to RESTful, how complicated is the task? I have worked on them individually, but never on any migration. Can any one tell me the points that need to be taken into consideration when doing this? Not sure if its an appropriate question. More like a discussion thing.
The general approach on any situation like that can be to have a middle adapter/layer work between your existing system and newly developed system.
Converting an existing SOAP web service into RESTful web service can be tedious depending upon the complexity of existing system. Rather we can take alternative approach where an REST Adapter can be written that acts as a mediator between existing SOAP system and freshly developed REST web service.
This way can be done with minimum efforts and delivery can be fast. But again it depends on what is the system all about, how complex is current SOAP web service.
So with this approach end client will generate a REST request that will be landed on REST adapter and from Adapter to existing SOAP web service, takes back the response from your SOAP web service converts it back ready for REST client response. Intermediate JSON to XML and XML to JSON conversions can be easily handled.
This approach can be better as if required adapter can be turned off. This
I'm not new to programming, but I have never created any server applications. I wish to a create server that provides data to an Android application, for example using a JSON string by POST/GET http requests that saves some data. I want to use Java EE, but I am unsure whether that is possible. I found tutorials that provide web browser pages, but I don't need this. Can somebody advise me?
As you are looking for simple JSON data representation, I would recommend going through a RESTful backend service and when it says REST in a Java Enterprise Edition, it says JAX-RS (RESTful Java specification) and its base implementation reference: Jersey.
It should not be the perfect place to detail how to implement a simple JSON backed service using Jersey, but going through the site references you should gain the basic knowledge on how to go for your first simple REST service.
I've some confusions about ReST clients and need a bit of help.
For ReST, does the service provider give WSDL document or not? If not, how does the client will know what kind of JSON data to expect? When I invoke the rest client, I will recieve the JSON/XML response in a string format which I'll need to convert it into a Java object(or Javascript, if using on client side) to do any meaningful tasks with the response. So it seems like I, as a client developer, need to know the WSDL or the Schema definition so that I can build a java object similar to the JSON response I'm expecting. But if you go by this answer, generating a client class based on the service definition flies directly in the face of ReST fullness. If that is the case, how do I go about creating my client code?
WADL/Web Application Description Language is not a standard but is gaining popularity for REST APIs contract definition.
The Web Application Description Language (WADL) is a machine-readable
XML description of HTTP-based web applications (typically REST web
services).1 WADL models the resources provided by a service and the
relationships between them.1 WADL is intended to simplify the reuse
of web services that are based on the existing HTTP architecture of
the Web.1[2] It is platform and language independent and aims to
promote reuse of applications beyond the basic use in a web
browser.
For documentation:
https://github.com/wordnik/swagger-core/tree/master/modules/swagger-jaxrs
For client code:
https://github.com/wordnik/swagger-ui
You integrate the library and annotate your resources and online documentation is generated on the fly.
You also need a client for which you can integrate the ui.
The dynamically generated REST client looks something like this:
http://petstore.swagger.wordnik.com/
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.
Basically I need webservice where client can request with id one boolean value from our webservice. What technology would be most suitable for this small API? Of course it is possible that there will be more functions to interface, but now we need only one function. It also needs to have authentication, so that only auhtorized clients can access service. And every client have different auth credientials.
What would be good technology for this purpose?
I am using resteasy to build my webservices and it is pretty easy to use ... just need to use annotations on my methods to deliver the webservices.
Here is a comparison of different JAX-RS frameworks. Take a look at it
First of all: authentication and authorization. Don't do it yourself, pick an app server or servlet container and configure it to do the job.
For the web service....
The simplest thing to do it just implement a servlet that responds to a POST (not a GET if request modifies internal state) and returns the result in the body. This way you don't need any frames works, no learning to do (if you already know servlets). The downside is it won't scale as you add more features, and your not using enough buzz words.
If you want a SOAP based webservice, then look at JAX-WS. Now that it's backed into java 6 it's pretty easy.
At the simplest level JAX-WS lets you put a few annotations on your class, like #WebService, and it auto generates a wsdl and exposes an instance of your class via the web service.
There is plenty of documenation out around how to do it:
http://java.sun.com/webservices/docs/2.0/tutorial/doc/
http://www.java-tips.org/java-ee-tips/java-api-for-xml-web-services/developing-web-services-using-j.html
http://cwiki.apache.org/GMOxDOC20/simple-web-service-with-jax-ws.html
JAX-WS + any servlet container (Tomcat is usual choice)
#WebService(targetNamespace = "http://affinity.foo.com", name="RewardsStatus")
#SOAPBinding(style=SOAPBinding.Style.RPC, use=SOAPBinding.Use.LITERAL)
public interface RewardsStatusIF {
#WebMethod(operationName="GetLastNotificationDate", action="urn:GetLastNotificationDate")
#WebResult(name="return")
public Date getLastNotificationDate() throws AffinityException;
...
Actually, you don't even need a servlet container. JAX-WS has a way to run the service under a standalone Java application. It has some limitations (I have failed to make a stateful service work), but it's
very simple to create.
Given that you tagged your question as "Java", I suggest Jetty. It is a very good small servlet engine. It has support for sessions, so adding authentication should not be a problem.
If you are using Java 6, there is already a HTTP Server builtin, it supports Http authentication. That's all you need. Check out,
com.sun.net.httpserver
You could use some restful framework like jersey.
An alternative to SOAP-based web services with JAX-WS would be JAX-RS (for RESTful web services).
We have a lot of scenarios on our project where we want small amounts of data available via simple HTTP URLs while the app is running and in my experience, Restlet (http://www.restlet.org/) seems to be one of the easiest things available for setting up simple "web-service"-like interfaces (RESTful interfaces) within Java apps.