Skip to main content

Posts

Showing posts with the label Rest web services

Jersey Framework Client - How to add HTTP Basic Authentication Header to HTTP Request?

Introduction In this tutorial, we will learn how to add HTTP basic authorization token to the HTTP request header. We will use Jersey Framework to consume RESTful web services. Read the following post if you want to learn how to secure web services using HTTP Basic Authentication Jersey Java Framework - How to add HTTP Basic Authentication to RESTful web services? Maven Dependencies <dependency>     <groupId>org.glassfish.jersey.core</groupId>     <artifactId>jersey-client</artifactId>     <version>2.29</version>  </dependency>  <dependency>     <groupId>org.glassfish.jersey.inject</groupId>     <artifactId>jersey-hk2</artifactId>     <version>2.29</version> </dependency> Basic Authentication is the most simple way to secure HTTP requests. It has the following format Authorization: Basic base64-encoding of username:password Jersey Client Jersy is the refe

Jersey Client - How to skip SSL certificates validation?

Introduction In this tutorial, we will explore to skip SSL certificates validation using the Jersy Client. We will use jersey Framework to consume the restful web services. It is very easy to consume the web services hosted on HTTP protocol. Challange is consuming the web services hosted on HTTPS with SSL certificates enabled. Maven Dependencies <dependency>     <groupId>org.glassfish.jersey.core</groupId>     <artifactId>jersey-client</artifactId>     <version>2.29</version> </dependency> Jersey Client Jersy is the reference implementation of JAX-RS. JAX-RS makes it very easy for Java developers to develop and consume RESTFul web services. Client Code import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Invocation; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Response; public class SkipSSLCertificateClient { public static Stri

Spring RestTemplate - How to skip SSL certificates validation?

In this tutorial, we will explore to consume restful web services hosted on https URL with SSL certificates. We will use Sprint RestTemplate to consume the restful web services. It is very easy to consume the web services hosted on HTTP protocol. Challange is consuming the web services hosted on HTTPS with SSL certificates enabled. I encountered the following exception when accessing SSL hosted web services Caused by: javax.net.ssl.SSLHandshakeException:        sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target  at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1917) We will use  SSLContext to skip SSL validation. What is SSL Context? SSL Context is a collection of ciphers, trusted certificates, TLS extensions and options, and protocol versions. It acts as a factory

Jersey Java Framework - How to add HTTP Basic Authentication to RESTful web services?

Overview I have shown you in the following post how to develop the RESTful web services using the Jersey Java Framework Jersey JAX-RS Framework - Step by Step Guide for Developing RESTful web services There are different security levels that we can add to web services a) Authentication b) Authorization c) Encryption The scope of this post is for Authentication. If we look at the available options then we have a) OpenID b) OAuth c) HTTP Basic Authentication  HTTP Basic level authentication is the weakest among the above three available options but it is still preferable over no Authentication :) Let's start how to implement  the Basic HTTP Authentication. Requirements for this tutorial  Eclipse  Maven Jersey Framework Tomcat STEP 1 First, we will code our filter to process the request before redirecting it to the respective resource. We will achieve it by implementing the  ContainerRequestFilter. We will add the following dependency to the

Jersey JAX-RS Framework - Step by Step Guide for Developing RESTful web services

Overview Jersey is a Java framework for developing RESTful web services. It is an implementation of JAX-RS reference.  In addition to JAX-RS , Jersey has its extended APIs that eases the development of restful web services and client development. In this tutorial, I will guide you through the steps to jump-start developing the RESTful web services using the Jersey framework. Requirements for this tutorial Eclipse Maven Jersey Framework Tomcat or any other Servlet container STEP 1 Open the Eclipse and create an empty Maven web project. Add the following dependencies   <dependencies>         <dependency>             <groupId>javax.ws.rs</groupId>             <artifactId>javax.ws.rs-api</artifactId>             <version>${jaxrs.version}</version>         </dependency>         <dependency>             <groupId>org.glassfish.jersey.containers</groupId>             <artifactId>jersey

Jersey Framework - java.lang.IllegalStateException: InjectionManagerFactory not found.

I have used Jersey Framework for RESTful web services development. I encountered the following error when I tried to upgrade it from 2.25 to 2.26 java.lang.IllegalStateException: InjectionManagerFactory not found. at org.glassfish.jersey.internal.inject.Injections.lambda$lookupInjectionManagerFactory$0(Injections.java:98) at java.util.Optional.orElseThrow(Unknown Source) at org.glassfish.jersey.internal.inject.Injections.lookupInjectionManagerFactory(Injections.java:98) at org.glassfish.jersey.internal.inject.Injections.createInjectionManager(Injections.java:93) at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:282) at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:335) at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:178) at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:370) at javax.servlet.GenericServlet.init(GenericServlet.java:158) at org.a

A complete guide to securing Spring RESTful web services using HTTP Basic Authentication header

In the following tutorial, I have shown you how to develop RESTful web services using Spring Boot Spring Data Rest web services for Beginners - Step By Step Guide This is a simple and easy written tutorial for beginners who are interested to explore the trending and widely used J2EE framework. In this tutorial, we will learn how to secure the Restful web services using the HTTP Basic Authentication header. According to rfc7617,  basic authentication is the method for HTTP user agent to provide the following two pieces of information in a request User Name Password In this method, the HTTP request contains the header in the following format Authorization: Basic <credentials>  where <credentials> is base64(username:password) Step 1 Add the following dependency to the maven <dependency>   <groupId>org.springframework.boot</groupId>   <artifactId>spring-boot-starter-security</artifactId> <dependency> Step

Spring Data Rest web services for beginners - Step By Step Guide

This tutorial is designed for those who have not worked with the Spring Framework or rest web services before. I am keeping it simple and less verbose so that readers can easily follow the steps and start developing the restful web services using Spring Data Rest. Spring Framework is the trending and widely used J2EE frameworks. It has various modules for web development. In this tutorial, we will use the Spring Data Rest. RESTful Web services Representational State Transfer (REST)  is based on server-client architecture and uses the HTTP protocol(stateless protocol). CRUD operations can be easily mapped on HTTP methods Create POST Read GET Update PUT Delete Delete Prerequisites for this tutorial Java 8 or later version Eclipse Maven Let's start developing the RESTful web services STEP 1 Open a new Maven Project in the eclipse, let's call it MyFirstRestApp.  We will use the Spring Boot for this tutorial. Open the maven.xml file and ad