Java Web Services Tutorial with Examples
November 10, 2013Web Services work on the basis of client-server model. Messages run on HTTP. The basic idea behind web services is interoperating between software running on different technologies. Web Services uses XML that enables web services to pass structured messages between client and server. They are loosely coupled but perform complex task. In java there are two basic web services JAX-WS and JAX-RS. JAX-WS is also called SOAP based web service and JAX-RS is called REST web service. Find the different examples to understand web services.
@QueryParam Example in REST Web Service n JAXRS, to consume values from query string we use @QueryParam. It is applied in method argument level. For more than one keys in query string, we need to use more than one @QueryParam. JSON Response Using RESTful Web Service On this page we will learn how a RESTful web service will return a JSON response. To create server for RESTful Web Service, we are using RESTEasy and for client we are using Jersey. SOAP Web Service Security: Authentication with MessageContext and BindingProvider This page will provide how to do authentication in our soap based web service application. MessageContext and BindingProvider will play the role to achieve it. When to Use SOAP and REST Web Services SOAP web service is based on simple object access protocol whereas REST web service is Representational State Transfer. Here we will discuss when to use SOAP based web service. Axis2 Code First Approach Web Services in Java In this page we will learn code first approach to develop axis2 web service. We write code of web service interface and generate WSDL file that is given to the client. The service is deployed in the axis2 application. Java SAAJ Web Service Example SAAJ is SOAP with Attachments API for Java. With the help of SAAJ, a developer can produce and consume messages conforming to SOAP. This page will describe how to use SAAJ in our application. Download file Using JAX-WS Web Service in Java This page will provide a demo for downloading a file using JAX-WS web service in java. We are using here MTOM that is message transmission optimization mechanism. We will create two project, one for server. Upload File Using RESTful Web Services with JAX-RS On this page we will provide how to upload file using RESTful Web Services with JAX-RS using Jersey. Uploading file using Using RESTful Web Services with JAX-RS is easy. Download File Using RESTful Web Services with JAX-RS On this page we will run the demo for how to download a file using RESTful Web Services with JAX-RS using Jersey. JAX-RS provides Response class that handles the downloading of file. Example of @PathParam in JAX-RS Web Services @PathParam extracts the URI values and matches to @Path. And hence gets the input parameter. @PathParam can be more than one and is set to methods arguments. Example of @Path in JAX-RS Web Services @Path in JAX-RS Web Services is the relative path for accessing the web service class. This plays the role for creating URI. It depends on us how long relative path is required. Example of RESTful Web Services with JAX-RS REST is Representational State Transfer. REST works on some constraints like uniform interface and we get performance, scalability, and modifiability. RESTful web services have the best performanc. How to Run wsgen and wsimport in JAX-WS Web Services wsgen and wsimport are the tools for JAX-WS web services and generates artifacts. These artifacts helps for deployment and invocation of JAX-WS web services. JAX-WS Web Service Simple Example JAX-WS is java API for XML Web Service. JAX-WS uses XML messages to communicate with the client. These XML messages are Simple Object Access Protocol (SOAP).