Jersey @MatrixParam webservices Restful JAX-RS tutorial


            Binds the value(s) of a URI matrix parameter to a resource method parameter, resource class field, or resource class bean property. Values are URL decoded unless this is disabled using the Encoded annotation. A default value can be specified using the DefaultValue annotation.

            Note that the @MatrixParam annotation value refers to a name of a matrix parameter that resides in the last matched path segment of the Path-annotated Java structure that injects the value of the matrix parameter.

Example
package com.candidjava.webservices.controller;

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.MediaType;
import javax.ws.rs.core.Response;

import com.candidjava.webservices.bean.User;

@Path("/User")
public class RegisterProcess
{
	
	@GET
	@Path("/welcomeMap/{countryName}")
	@Produces(MediaType.APPLICATION_JSON)
	public Response getRegisterDetails(@PathParam("countryName") String countryname, @MatrixParam("txt_username") String username, @MatrixParam("txt_password") String password)
	{

		System.out.println(countryname);
		System.out.println(username);
		System.out.println(password);

		User user = new User(username, password);

		return Response.ok().status(200).entity(user).build();

	}

}

User bean
package com.candidjava.webservices.bean;

public class User
{

	private String username;
	private String password;
	
	public User(String username,String password)
	{
		
		super();
		this.username=username;
		this.password=password;
		
	}
	
	public String getUsername()
	{
		return username;
	}

	public void setUsername(String username)
	{
		this.username = username;
	}

	public String getPassword()
	{
		return password;
	}

	public void setPassword(String password)
	{
		this.password = password;
	}
}

Screenshot

Download
            Matrixparam jersey example zip
            Matrixparam jersey example war


Related Post

Comments


©candidjava.com