HowToDoInJava

  • Java 8
  • Regex
  • Concurrency
  • Best Practices
  • Spring Boot
  • JUnit5
  • Interview Questions

Jersey Selectable EntityFilteringFeature Example

By Lokesh Gupta | Filed Under: Jersey

Often times, you want to make RESTful API consumers capable of filtering data what they need from a GET API, rather than forcing them to consume all the response data unnecessary. There are two ways to achieve this filtering : server side response filtering and client side response filtering. Server side response filtering, though useful, […]

Jersey – How to set Cookie in REST API Response

By Lokesh Gupta | Filed Under: Jersey

In this example, we will learn to set cookies into HTTP responses sent by Jersey REST APIs. This example makes use of javax.ws.rs.core.Response for setting cookies into REST responses sent to REST clients. Set Cookie Syntax To set a cookie in REST API response, get the Response reference and use it’s cookie() method. Rest API […]

Jersey Client – Set Cookie Example

By Lokesh Gupta | Filed Under: Jersey

In this example, we will learn to set cookies into HTTP requests invoked by Jersey client. This example makes use of Invocation.Builder for setting cookies into outgoing REST calls. Set Cookie Example To set a cookie in REST API request, first get reference of Invocation.Builder from webTarget.request() method, and then use it’s methods. Rest API […]

Jersey Logging Request and Response Entities using Filter

By Lokesh Gupta | Filed Under: Jersey

By default, Jersey uses JUL for logging – and does not print request/response entity bodies in logs. To print entity content, you must create your own LoggingFiler, and register it in place of default org.glassfish.jersey.filter.LoggingFilter. In this example, I am creating one such basic CustomLoggingFilter which extends org.glassfish.jersey.filter.LoggingFilter and implements ContainerRequestFilter and ContainerResponseFilter interfaces so […]

Jersey REST Client Authentication Example

By Lokesh Gupta | Filed Under: Jersey

Learn to use Jersey REST client authentication using HttpAuthenticationFeature, which can be used to access REST APIs behind authentication security.

Jersey REST API Security Example

By Lokesh Gupta | Filed Under: Jersey

In this Jersey rest security example, we will learn to secure Jersey REST APIs with basic authentication. This will make mandatory every user to provide username/password to authenticate into portal. Also, user must have certain level of role as well. I have extended this example from my other example created for RESTEasy API security and […]

Jersey + Google Gson Example

By Lokesh Gupta | Filed Under: Jersey

This tutorial explains how to use google Gson with Jersey 2.x. There are some other java libraries also capable of doing this conversion e.g. MOXy, Jackson or JSONP; but Gson stands among very few which do not require any pre-annotated java classes OR sourcecode of java classes in any way. Table of Contents Maven dependencies/changes […]

Jersey + JSONP Example

By Lokesh Gupta | Filed Under: Jersey

This tutorial explains how to use JSONP JSON provider with Jersey 2.x. JSONP is also auto-discoverable just like what we discussed in Jersey MOXy example. Table of Contents JSONP maven dependencies/changes REST API code Model bean changes Manually adding JsonProcessingFeature JSONP maven dependencies/changes JSONP media module is one of the modules in Jersey 2.x where […]

Jersey + MOXy JSON Example

By Lokesh Gupta | Filed Under: Jersey

This tutorial explains how to use MOXy JSON feature with Jersey 2.x. MOXy is the default JSON-Binding Provider in Jersey 2.x. Though I still personally prefer Jackson over MOXy for performance reasons. Table of Contents MOXy maven dependencies/changes REST API code Model bean changes Manually adding MoxyJsonFeature Customize behavior using MoxyJsonConfig Demo MOXy maven dependencies/changes […]

Jersey-quickstart-archetype Hello World Example

By Lokesh Gupta | Filed Under: Jersey

In this example, we will create a jersey RESTful API web application using jersey-quickstart-webapp maven archetype in eclipse. Table of Contents Install remote archetypes in eclipse Create new maven project using jersey-quickstart-webapp Generated Files Run The Application Install remote archetypes in eclipse The very first step before creating actual maven quick-start application, is to install […]

Jersey – Case-insensitive @Path URLs

By Lokesh Gupta | Filed Under: Jersey

By default in JAX-RS, ALL URLs specified in @Path annotations are CASE-SENSITIVE. In this tutorial, I am giving a simple example of CASE-INSENSITIVE URLs which cane be used inside @Path annotation on any Jersey JAX-RS REST API. How to make URLs case in-sensitive To make URLs case-insensitive, change the @Path URLs like below: Change above […]

Jersey Client Example – Jersey 2 Client API

By Lokesh Gupta | Filed Under: Jersey

Jersey 2 client API finds inspiration in the proprietary Jersey 1.x Client API. In this Jersey client example, we will learn to build client API and invode different REST methods and consule the API results.

Jersey exception handling – Jersey ExceptionMapper Example

By Lokesh Gupta | Filed Under: Jersey

In Jersey ExceptionMapper example, we will learn to handle custom exceptions using ExceptionMapper interface while developing Jersey RESTful web services. For demo purpose, I am modifying the sourcecode written for jersey download file example. Table Of Contents 1. Jersey custom exception with ExceptionMapper 2. How to throw exception from REST API 3. Demo 1. Jersey […]

Jersey – Ajax Multi-File Upload Example

By Lokesh Gupta | Filed Under: Jersey

Learn to use Ajax with JAX-RS webservices (Jersey used in example) to upload multiple files with single button click. Also look at form based file upload example and file download example as well. Table of Contents Jersey maven multipart dependency Add MultiPartFeature Write Upload REST API HTML/Ajax code Demo of Multiple files upload Jersey maven […]

Jersey file upload example – jersey 2 MultiPartFeature

By Lokesh Gupta | Filed Under: Jersey

In this Jersey file upload example, learn to upload binary files (e.g. PDF files in this example) using Jersey’s multipart support for file upload.

Jersey file download example – StreamingOutput

By Lokesh Gupta | Filed Under: Jersey

In this Jersey file download example, we will learn to write a Jersey rest api which will be able to stream or download file (e.g. PDF/Excel/Text files) to requesting client. I will be using javax.ws.rs.core.StreamingOutput class for building this JAX-RS API. Table of Contents 1. REST API to stream file with StreamingOutput 2. Jersey file […]

[Solved] java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer

By Lokesh Gupta | Filed Under: Jersey

You can face this exception if you are setting up jersey 2 project first time in eclipse using maven plugin. Message is simple enough to identify the root cause the Jersey libraries are not in classpath. Exception will look like this. Solution – Add Jersey Library in Deployment Assembly Open your project’s deployment assembly configuration. […]

Jersey 2 hello world example – Jersey 2 tutorial

By Lokesh Gupta | Filed Under: Jersey

I have published lots of tutorials for developing REST apis using RESTEasy. In this Jersey 2 tutorial, I will go through configuration steps in detail for setting up a Jersey 2 example web application project. Table of Contents 1. What changed from Jersey 1.x to Jersey 2.x 2. Jersey 2 maven dependencies 3. web.xml Changes […]

Jersey Hello World Example

By Lokesh Gupta | Filed Under: Jersey

I have written a number of posts on JAX-RS RESTEasy concepts and how to. Now I have started exploring Jersey which is another popular framework for making RESTFul applications. To start with, I am writing my hello world application in this post, which I will modify in next posts to show demos of other features […]

SOLVED: java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

By Lokesh Gupta | Filed Under: Jersey

If you have start working on Jersey then you might face this issue while configuring it. This is the result of insufficient project dependencies on runtime. This issue is likely to be faced in tomcat server. The error log will look like this. To solve this issue, correct the project dependencies in pom.xml like below. […]

Search Tutorials

  • Email
  • Facebook
  • RSS
  • Twitter

Jersey Tutorial

  • Jersey – Hello World
  • Jersey2 – Hello World
  • Jersey – quickstart-archetype
  • Jersey – Custom Logging
  • Jersey – Set Cookie
  • Jersey – File Download
  • Jersey – File Upload
  • Jersey – Multi-File Upload
  • Jersey – Exception Handling
  • Jersey – MOXy JSON
  • Jersey – JSONP
  • Jersey – Google Gson
  • Jersey – Security

Jersey Client

  • Jersey Client – Access REST APIs
  • Jersey Client – Authentication
  • Jersey Client – Set Cookie

Popular Tutorials

  • Java 8 Tutorial
  • Core Java Tutorial
  • Java Collections
  • Java Concurrency
  • Spring Boot Tutorial
  • Spring AOP Tutorial
  • Spring MVC Tutorial
  • Spring Security Tutorial
  • Hibernate Tutorial
  • Jersey Tutorial
  • Maven Tutorial
  • Log4j Tutorial
  • Regex Tutorial

Meta Links

  • Advertise
  • Contact Us
  • Privacy policy
  • About Me

Copyright © 2016 · HowToDoInjava.com · All Rights Reserved. | Sitemap