JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

JAX-RS @MatrixParam annotation example


The idea of matrix parameters is that they are an arbitrary set of name-value pairs embedded in a uri path segment. A matrix parameter example is:

GET http://java2novice.com/spring;name=aop;[email protected]

The basic idea of matrix parameters is that it represents resources that are addressable by their attributes as well as their raw id. The @MatrixParam annotation allows you to inject URI matrix paramters into your method invocation

This page gives you an example using JAX-RS @MatrixParam annotation, which injects value from request parameters to your method input parameters.

In the previous examples we have given details of application setup, dependencies, web.xml file configurations: If you want to know about these configuration, please refer these:

Restful web services using RESTEasy hello world example.
Restful web services using Jersey hello world example.

Look at the below class to apply @MatrixParam annotation:

package com.java2novice.restful;

import javax.ws.rs.GET;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

@Path("/inventory")
public class InventoryService {

	@GET
	@Path("{deviceType}")
	public Response getInventoryDetails(@PathParam("deviceType") String deviceType,
			@MatrixParam("company") String company,
			@MatrixParam("model") String model){
		
		String resp = "Received request for device: "+deviceType+
						", comany: "+company+" and model: "+model;
		return Response.status(200).entity(resp).build();
	}
}

In the above example, if you use "/inventory/switch;company=cisco;model=nexus-5596" URI pattern with query parameters, getInventoryDetails() method will be invoked, and you will get below response.

Received request for device: switch, comany: cisco and model: nexus-5596

In the next page you will see an example on how to read multiple values of a query paramters

<< Previous Program | Next Program >>
blog comments powered by Disqus

Restful Web Services Examples

  1. Restful web services using RESTEasy hello world example.
  2. Restful web services using Jersey hello world example.
  3. JAX-RS @Path annotation example
  4. JAX-RS @Path annotation with regular expression match example
  5. JAX-RS @PathParam annotation example
  6. JAX-RS @QueryParam and @DefaultValue annotations example
  7. JAX-RS @MatrixParam annotation example
  8. How to read multiple values of a query paramter in JAX-RS restful web services?
  9. How to pass header parameters as method inputs in JAX-RS restful web services?
  10. How to read header parameters in JAX-RS restful web services?
  11. JAX-RS @FormParam annotation example
  12. How to upload file using Jersey restful web services?
  13. How to download file using java restful web services?
  14. XML based Restful web service with RESTEasy and JAXB.
  15. XML based Restful web service with Jersey and JAXB.
  16. Json based Restful web service with RESTEasy, Jettison and JAXB
  17. Json based Restful web service with RESTEasy and Jackson
  18. Json based Restful web service with Jersey and Jackson
  19. How to input json request with Jersey and Jackson?
  20. Java client for restful web service using java.net package
  21. Java client for restful web service using Jersey API
  22. Java restful webservices with HTTP basic authentication.
Knowledge Centre
wait Vs sleep methods
sleep(): It is a static method on Thread class. It makes the current thread into the "Not Runnable" state for specified amount of time. During this time, the thread keeps the lock (monitors) it has acquired.

wait(): It is a method on Object class. It makes the current thread into the "Not Runnable" state. Wait is called on a object, not a thread. Before calling wait() method, the object should be synchronized, means the object should be inside synchronized block. The call to wait() releases the acquired lock.
Famous Quotations
Before you go and criticize the younger generation, just remember who raised them.
-- Unknown Author

About Author

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2017 by Nataraja Gootooru. All Rights Reserved.