Skip to main content

Posts

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

Top 20 JVM languages

Java is a popular object-oriented programming language. It was developed with an intention of WORA i.e. write once, run anywhere. Compiled Java code can run be run on any platform without recompilation. Java runs on Java Virtual Machine (JVM). JVM is a virtual machine and it is required by the computer to run any code compiled to Java bytecode.  Besides Java, the following languages can be run on JVM Scala Kotlin Clojure Apache Groovy Frege Ceylon Redline Smalltalk Xtend Haxe JRuby Kawa scheme Armed Bear Common Lisp Neo4j Nashorn Jacl Simula Jabaco JScheme Bigloo Renjin

Oracle How to reset Sequence without dropping it

In this article, we will learn how to reset Sequence to a particular value without dropping it. Let's suppose the current value of the sequence e.g seq_person_id is 10234 and we want to reset it to 100. Step 1 alter sequence  seq_person_id increment by -10134 minvalue 0 Note : MINUS sign with 10134. Step 2 select  seq_person_id.nextval from dual Step 3 alter sequence  seq_person_id  increment by 1 minvalue 0; The sequence is now reset to 100. 

SQL Reporting Services Missing in Action in Visual Studio 2017

Microsoft RDLC Report Designer for Visual Studio To install these extensions: Launch Visual Studio 2017 -> Go to Tools Menu -> Select Extensions and Updates -> In the Extensions and Updates dialog box, select the Online option -> Click in the Search Visual Studio Marketplace dialog box, top right hand corner -> Type in Report -> Press return -> Select Microsoft Rdlc Report Design for Visual Studio -> Press the Download button -> Select Microsoft Reporting Services Project -> Press the Download button -> Press the Close button -> Close Visual Studio 2017 The extensions will install Open Visual Studio 2017 SQL Server Reporting Services will be installed ___Stay Happy_____________

No 'Access-Control-Allow-Origin' header is present on the requested resource.

//No 'Access-Control-Allow-Origin' header is present on the requested resource__ Access-Control-Allow-Origin error mostly when you access web api without client like from ajax or javascrip call Issue can be resolved in following steps. 1) Goto global aspx calss of WebApi 2) After default start method add below mentioned code in step 3 3) protected void Application_BeginRequest(object sender, EventArgs e) { HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); if (HttpContext.Current.Request.HttpMethod == "OPTIONS") { HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "POST, PUT, DELETE"); HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept"); HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000&

Gmail API - Invalid topicName does not match projects/../topics/*

I am exploring the Google Cloud PubSub these days. I am working on a project where I have to listen for the User's Gmail Inbox and then process the new emails as they arrive. I used a Gmail Client API to add the  watch  on user's Gmail. I encountered the following exception Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request {   "code" : 400,   "errors" : [ {     "domain" : "global",     "message" : "Invalid topicName does not match projects/modular-botany-234216/topics/*",     "reason" : "invalidArgument"   } ],   "message" : "Invalid topicName does not match projects/modular-botany-234216/topics/*" } at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146) Solution After a bit of struggle and google, I found that I have created th

Java - How to remove characters from a String at a specific index?

In this post, I will show you how to remove the characters/string from a string at a specific index. In Java, there is no such function available in String class. We have the following two alternates available StringBuilder StringBuffer Option 1 (StringBuilder)     StringBuilder builder = new StringBuilder("hello to Java");              builder.delete( 5, 8 );     System.out.println( builder );// OUTPUT  hello Java To remove a single character     StringBuilder builder = new StringBuilder("hello to Java");           builder.deleteCharAt( 0 );     System.out.println( builder );// OUTPUT ello to Java Option 2 (StringBuffer)     StringBuffer buffer = new StringBuffer ("hello to Java");     buffer .delete( 5, 8 );     System.out.println(  buffer );// OUTPUT hello Java To remove a single character     StringBuffer  buffer  = new  StringBuffer  ("hello to Java");           buffer .dele

Java - How to insert characters in a String at a specific index?

I was translating a DotNet project to Java. In code, CSharp  insert String function was used and I wrote my own Java function to insert characters/string at a specific index of string. Following is the code     public static String insert(String originalString,int offset, String injectString) {         if(offset>= originalString.length()) {             return originalString;         }         String firstPart = originalString.substring( 0, offset);         String secondPart = originalString.substring( offset);               return firstPart.concat( injectString ).concat( secondPart );     }  Later on, I found the StringBuffer's built-in  insert function for the same purpose         StringBuffer buffer = new StringBuffer();         buffer.append( "Hello Java" );         buffer.insert( 6, "to " );         System.out.println( buffer ); // OUTPUT  Hello to Java

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