Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Wednesday, December 16, 2020

Failed to transfer file: http://repo1.maven.org/maven2. Return code is: 501 , ReasonPhrase:HTTPS Required


If you are getting the following error when you are building your Java project using maven or gradle:

Failed to transfer file: http://repo1.maven.org/maven2. 
Return code is: 501 , ReasonPhrase:HTTPS Required

And you are thinking what happened, I haven’t changed anything in my project, no new dependencies, or repositories. The answer is that you haven’t changed anything. 

Do not panic! Effective January 15, 2020, the Central Repository is not longer supporting communication over HTTP and it requires requests to the repository must be over HTTPS.

Monday, August 31, 2020

Latency for sharing data while using Hazelcast on Virtual Machine


A few days back we found out one old app which was running on multiple nodes while having in-memory cache usage. So, as a result, there was a case when the request came to the first node and the second node didn't get that data, and the app wasn't functioning properly. 

So, as always first thing which we considered to use Redis. However, we don't have ready to use the Redis cluster and we started looking for other solutions in a market. Finally, I saw there is a Hazelcast which allows sharing data between nodes even without having the Hazelcast cluster. Of course, it is working when you are running in the same network. So, nodes should be able to multicast and make a proper cluster.

Wednesday, November 13, 2019

Java List vs List<?> vs List<Object>

Before generics were introduced developers used lists as List which means you can store any type of objects including null inside it and when you read it you need to cast it
List list = new ArrayList();
list.add("String test");
list.add(new Date());

String s = (String) list.get(0);
From code above you can expect ClassCastException because if you try to assign 2nd item to String it will not succeed and you will get an exception during runtime. To prevent it you need to check if your type is correct and then cast as below

Sunday, April 15, 2018

Unable to Find Valid Certification Path to Requested Target while using Java on Server

SSL Certificates are small data files that digitally bind a cryptographic key to an organization’s details. 
When installed on a web server, it activates the padlock and the https protocol and allows secure connections from a web server to a browser. 

Typically, SSL is used to secure credit card transactions, data transfer, and logins, and more recently is becoming the norm when securing browsing of social media sites.

Even now, most the browsers show sites as "Not Secure" when they don't have SSL certificates

Maybe you also faced an issue like below:

Tuesday, June 7, 2016

Openfire Custom database integration steps

Instant messaging (IM) has enjoyed phenomenal success as a person-to-person communication tool; in some instances, it has supplanted email as the preferred means of online communication. Now, developers are using this technology for application-to-person and application-to-application communication.

There are too many IM servers which work with XMPP protocol. Some of them are paid/Enterprise and some of them are OpenSource.

We are using "Openfire" as a IM server for our projects. It is free, open source and java based. Except this advantages it has too many plugins which you can use for free. Openfire is a XMPP server and it has own client application with name "Spark".

Thursday, March 26, 2015

JDBC URL to connect RAC database or How add multiple hosts in jdbc url

Today I will share new problem which I have solved.

In my last project I was connected to Oracle database (RAC) database using multiple hosts and I want to share oracle connection string which uses multiple hosts.

So while you are connecting from oracle clients (as PL/SQL developer) it is easy to define multiple hosts in tnsnames.ora




Thursday, September 25, 2014

Oracle JDBC problem - Locale not recognized on Glassfish

When you create JDBC connection pool for oracle you may seen error like below:

Ping Connection Pool failed for DBNAME. Connection could not be allocated because: Locale not recognized Please check the server.log for more details.

Solution of this problem is so simple. How we can solve this problem???

Tuesday, September 17, 2013

Shuffle an Array in Java with Easy or Fast way


Objects are a powerful software engineering construct, and Java uses them extensively. While developing Android applications you need fast way of doing something. For example:
Often u need randomized Array which u will save state of stage or something.
In that case how you change order of Array randomly???


There are 2 famous way for this:

Thursday, July 18, 2013

SOLVED: Unknown type '246 in column 2 of 3 in binary-encoded result set


Today at our firm was problem like as "Unknown type '246 in column 2 of 3 in binary-encoded result set" when selected table has column as decimal(10, 2) type. This errors cause because we use old version of mysql jdbc driver. Solution for this problem is:
  1. Download new version of driver
  2. Convert double column to char on selection.
    SELECT CAST(your_column AS char(15)) your_column FROM your_table;
    So in this case on java side u can get it as Double again.

Saturday, March 16, 2013

Create your web services with Spring

In this post I will show "Spring way" to build RESTful web services. It also explained how to produce multiple representations (JSON, XML and etc.), which is an important feature for RESTful web services.
This article explains another way to produce multiple representations using HttpMessageConverter, and examples in the article show how to use RestTemplate with HttpMessageConverter to communicate with services. HTTP requests and responses are text based, meaning a browser and server communicate by exchanging raw texts. With Spring, however, methods in the controller class return pure 'String' type and domain models (or other Java built-in objects). How can Spring serialize/de-serialize the objects to raw texts? This is handled by HttpMessageConverter. Spring has bundled implementations that can meet your common needs. Table 1 shows some examples.

Tuesday, December 25, 2012

Read data from SSL X.509 Certificates

According to X.509, you can create certificates with either RSA or DSA key pairs. But only RSA key pairs are capable of exchanging keys when starting a new SSL connection with a SSL server. You can only use RSA key pairs as your server certificates. On the other hand, CAs do not have to exchange keys. They only issue other certificates. You can use either RSA or DSA key pair as your CAs. But, some SSL programs do not support the DSA algorithm yet.

Sometimes u need check certificate valid date on server. U can do this in java simple:

Monday, November 19, 2012

Captcha for Java

       A CAPTCHA is a program that protects websites against bots by generating and grading tests that humans can pass but current computer programs cannot. For example, humans can read distorted text as the one shown on image, but current computer programs can't.
       The term CAPTCHA (for Completely Automated Public Turing Test To Tell Computers and Humans Apart) was coined in 2000 by Luis von Ahn, Manuel Blum, Nicholas Hopper and John Langford of Carnegie Mellon University.
       When u create web project sometimes u need captcha with colors of your site. That cases u can create captcha yourself as following:

Sunday, November 4, 2012

Parse XML and Properties config files

       .xml(Extensible Markup Language) and .properties is a file extension for files mainly used in Java related technologies to store the configurable parameters of an application.(.properties files can also be used for storing strings for Internationalization and localization - these are known as Property Resource Bundles.)

       Let's first start with XML config files. There are many XML parser technologies, but I will show how u can use Apache Commons Configuration library to parse and use XML config files.

       The Commons Configuration software library provides a generic configuration interface which enables a Java application to read configuration data from a variety of sources:

Thursday, October 18, 2012

Power of Spring's @ModelAttribute and @SessionAttributes

The Spring Framework is an open source application framework that aims to make J2EE development easier. Unlike single-tier frameworks, such as Struts or Hibernate, Spring aims to help structure whole applications in a consistent, productive manner, pulling together best-of-breed single-tier frameworks to create a coherent architecture.

How does @ModelAttribute work?
@ModelAttribute is a Spring-MVC specific annotation used for preparing the model data. It is also used to define the command object that would be bound with the HTTP request data. The annotation works only if the class is a Controller class (i.e. annotated with @Controller).

ModelAttribute can be applied on both methods as well as method-parameters. It accepts an optional "value", which indicates the name of the attribute. If no value is supplied to the annotation, then the value would be defaulted to the return type name in case of methods and parameter type name in case of method-parameters.

Tuesday, September 18, 2012

Spring 3 MVC Internationalization & Localization (i18n & l10N) and Reloader

In this post I will discuss about Internationalization (I18N) and Localization (L10N) in Spring 3.0 MVC. 

What is i18n and L10n?

In computing, internationalization and localization are means of adapting computer software to different languages and regional differences. Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. Localization is the process of adapting internationalized software for a specific region or language by adding locale-specific components and translating text.
The terms are frequently abbreviated to the numeronyms i18n (where 18 stands for the number of letters between the first i and last n in internationalization) and L10n respectively, due to the length of the words. The capital L in L10n helps to distinguish it from the lowercase i in i18n. Let's begin:

Thursday, September 13, 2012

Intercepting requests (annotation based request mapping)

       Spring Interceptors has the ability to pre-handle and post-handle the web requests. Each interceptor class should extend the HandlerInterceptorAdapter class. Here we will create a Login Interceptor by extending the HandlerInterceptorAdapter class. You can override any of the three callback methods preHandle(), postHandle() and afterCompletion(). As the names indicate the preHandle() method will be called before handling the request, the postHandle() method will be called after handling the request and the afterCompletion() method will be called after rendering the view.

Friday, May 25, 2012

Avoiding the "javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed" error

Hey folks,

today I'm gonna share one solution for a problem related to https hand-shake.

The SSLHandshakeException is thrown by java when the host you are trying to contact doesn't have a valid SSL certificate for that hostname.
For example, when I wanted to connect to the site which certificate details look like  "This CA Root certificate is not trusted because it is not in the Trusted Root Certification Authorities store.

So when we are making a request to that site using java URLConnection it gives us an exception look like "javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed" . Then I did research for this problem and found a solution as follows:

Wednesday, February 29, 2012

Connect to Remote database through SSH using Port Forwarding with Java

Yesterday I need connect connect our remote MySQL database that was setup on SSH enabled server and query database. Since it was on SSH enabled server, we can’t connect it directly using JDBC connection API.To achieve this, we first need to create SSH session and then using Port Forwarding we can forward the request to server and connect to database. I used JSchJSch is a pure Java implementation of SSH2.

Monday, October 24, 2011

PayPal Instant Payment Notification (IPN)

Lets start.

WHAT IS PayPal?
PayPal is a service that enables you to pay, send money, and accept payments without revealing your financial information.


WHAT IS IPN?
Instant Payment Notification (IPN) is a message service that notifies you of events related to PayPal transactions. You can use it to automate back-office and administrative functions, such as fulfilling orders, tracking customers, and providing status and other information related to a transaction.


The Following diagram shows requests and responses, which are the result of processing button clicks or API operations on PayPal. PayPal sends an IPN message when it sends a response to a request. The IPN message is not actually part of the response sent to your website. Rather, the IPN message is sent to the your listener, which allows you to take actions that are not directly tied to the operation of your website.