Jax-rs file download example

Jax-rs file download jersey example ImageService.java import java.io.File; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder;   @Path("/image") public class ImageService { private static final String FILE_PATH = "D:\\java.jpg";   @GET @Path("/get") @Produces("image/png") public Response getFile() { File file = new File(FILE_PATH); ResponseBuilder response = Response.ok((Object) file); response.header("Content-Disposition", "attachment; filename=image_from_server.png"); return response.build();   … Read more

Jax-rs file upload example

Jax-rs file upload jersey example uploadFile.java import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response;   import com.sun.jersey.core.header.FormDataContentDisposition; import com.sun.jersey.multipart.FormDataParam;     @Path("/file") public class UploadFileService { @POST @Path("/upload") @Consumes(MediaType.MULTIPART_FORM_DATA) public Response uploadFile( @FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail) {   String uploadedFileLocation = … Read more

Jax-rs form parameters example

Jax-rs form parameters jersey example TestWS.java import javax.ws.rs.FormParam; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.core.Response;   @Path("/student") public class TestWS { @POST @Path("/add") public Response addStudent( @FormParam("name") String name, @FormParam("rollNo") String rollNo) { String output = "Student Name: " + name + ", Roll No.: " + rollNo; return Response.status(200).entity(output).build(); } }import javax.ws.rs.FormParam; import javax.ws.rs.POST; import … Read more

Jax-rs matrix parameters example

Jax-rs matrix parameters jersey example TestWS.java import javax.ws.rs.GET; import javax.ws.rs.MatrixParam; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; import javax.ws.rs.core.MediaType;   @Path("/helloTest") public class TestWS { @GET @Path("{name}") @Produces(MediaType.TEXT_PLAIN) public Response getMassegeWithMultiParam( @PathParam("name") String name, @MatrixParam("class") String className, @MatrixParam("rollNo") String rollNo) { String output = "Student Name: " + name + ", Class: " +className+ … Read more

Jax-rs path multiple parameters example

Jax-rs path multiple parameters jersey example TestWS.java package com.w3schools.ws;   import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; import javax.ws.rs.core.MediaType;   @Path("/helloTest") public class TestWS { @GET @Path("{id}") @Produces(MediaType.TEXT_PLAIN) public Response getMassegeWithSingleParam( @PathParam("id") String id) { String output = "RESTful WS Jersey example. " + "Hello your id is : " + id; … Read more

Jax-rs uri matching example

Jax-rs uri matching jersey example TestWS.java import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; import javax.ws.rs.core.MediaType;   @Path("/helloTest") public class TestWS { @GET public Response getMassege1() { String output = "RESTful WS Jersey example. Hello World."; return Response.status(200).entity(output).build(); }   @GET @Path("/world") @Produces(MediaType.TEXT_PLAIN) public Response getMassege2() { String output = "RESTful WS Jersey … Read more

Jax-rs hello world jersey example

RESTful web services: REST stands for REpresentational State Transfer. Unlike SOAP it is a web standards based architecture and not protocol. It uses HTTP protocol for data communication. REST provides the facility to represent a resource in various formats like text, JSON and XML. Note: JSON is the most popular format. Jax-rs hello world jersey … Read more

Jax-ws web service document style example

JAX-WS Document style: A Document style SOAP message body contains an XML document that can be validated against a defined XML schema. It is a more customizable and flexible approach as the protocol relies on the pre-defined schema to determine the structure of the SOAP message. That means we are free to customize the SOAP … Read more

Jax-ws web service rpc style example

JAX-WS RCP style: JAX-RPC stands for Java API for XML-based RPC. It allows a Java application to invoke a Java-based Web service with a known description while still being consistent with its WSDL description. JAX-RPC is one of the Java XML programming APIs. A RPC style SOAP messages body contains an XML representation of the … Read more

Jax-ws web service tutorial

JAX-WS: JAX-WS stands for Java API for XML Web Services. It is a set APIs for creating web services and clients which communicates through XML format. It allows us to write message-oriented (Document-oriented) as well as Remote Procedure Call-oriented (RPC-oriented) web services. Note: It is part of standard Java API and we don’t have to … Read more