2014-12-29

MOXy and JAXB






This articles explains how to use MOXy with JAXB to avoid needless POJO creations.

You can read it here

XML unmarshalling benchmark in Java











Here is a nice post with an actual benchmark on unmarshalling XML in java.

Read it here ..

Another benchmark here

Integrating Swagger Into JAX-RS With Java EE 6 Specification


Swagger is an awesome framework we often used to describe, consume and visualize our RESTful web services. Typically, we use Tomcat with Jersey as a servlet, then specify the Swagger package and Swagger Configuration class into web.xml, finally annotate the resources, methods and models to complete the configurations. Our team recently built a Java EE 7 application for a RESTful web service. The goal of this article is to share our experiences of configuring Swagger in Glassfish 4 without a web.xml.

Read more ...

2014-12-28

Make Maven package all dependency jars into my jar


Add the following in pom.xml


<build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>fully.qualified.MainClass</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
    </plugin>
  </plugins>
</build>
 
and you run it with
mvn clean compile assembly:single Compile goal should be added before assembly:single or otherwise the code on your own project is not included.

Source

Arquillian with NetBeans, GlassFish , JPA









A nice working example of Arquillian in Glashfish

Read it here

S.O.L.I.D. Software Development



Most professional software developers understand the academic definitions of coupling, cohesion, and encapsulation. However, many developers do not understand how to achieve the benefits of low coupling, high cohesion and strong encapsulation, as outlined in this article. Fortunately, others have created stepping stones that lead to these goals,

resulting in software that is easier to read, easier to understand and easier to change. In this article series, I will define three of the primary object-oriented principles and show how to reach them through the five S.O.L.I.D. design principles.

Have you ever played Jenga? It’s that game of wooden blocks that are stacked on top of each other in rows of three. In Jenga you try to push or pull a block out of the stack and place it on top of the stack without knocking the stack over. The player that causes the stack to fall loses.

Read more ...

How to add certificate to JVM

 

 

 

 

 

PKIX path building failed: SunCertPathBuilderException: unable to find valid certification path to requested target.

SSLHandshakeException: PKIX: unable to find valid certification path to requested target

This solution relates to the following stacktrace:

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.
    
We experienced this issue when a server changed their HTTPS SSL certificate, and our older version of java did not recognize the root certificate authority (CA).
If you can access the HTTPS URL in your browser then it is possible to update Java to recognize the root CA.
In your browser, go to the HTTPS URL that Java could not access. Click on the HTTPS certificate chain (there is lock icon in the Internet Explorer, or the domain name left of the URL in firefox) and navigate the certificate hierarchy. At the top there should be a Primary Root CA. This could be missing from your java cacerts file. Note down the Issuer and Serial Number.
To verify the root certificates, determine where the cacerts file is located. By default it is in jre/lib/security/cacerts. The default password for this keystore is 'changeit'.
e.g. on my machine, I have both JDK and JRE, here is where they are located.
./jdk1.6.0_24/jre/lib/security/cacerts
./jre1.6.0_24/lib/security/cacerts
Different versions of java can have different cacerts.
If you do not want to modify the default JRE store, you can make a copy, and use the following system properties to specify the location and password.
javax.net.ssl.trustStore
javax.net.ssl.trustStorePassword
Once you have your keystore, dump its contents by using the list option.
keytool -list -v -keystore /path/to/cacerts  > java_cacerts.txt
Enter keystore password:  changeit
In this example, /path/to/cacerts is the location of your cacerts file, and the output of the command will be saved in java_cacerts.txt.
Take a look at java_cacerts.txt. See if it includes the same certificate that is present in the browser by searching for a matching serial number. In the java_cacerts.txt file, the serial number will be in lowercase and without the ":" colon character. If it is not present, then this could be the reason for the error, and we can fix this by adding the certificate found in the browser.
Back in the browser, export the Root CA. Choose the "X.509 Certificate (DER)" type, so the exported file has a der extension.
Assuming the file is called example.der, pick the alias 'example' for this certificate. Next import the file.
keytool -import -alias example -keystore  /path/to/cacerts -file example.der
You will be prompted for a password, use 'changeit'
and response "yes" on whether to trust this key.
Dump the contents again to verify it contains your new certificate. Restart the JVM and check that it can now access the HTTPS URL. Also remove the java_cacerts.txt dump file.


Source

Popular Posts