Fast ssl certificate for tomcat development (windows)

If you need a fast ssl certificate for your tomcat, go into your home directory:
open a windows cmd

keytool -genkey -keyalg RSA -alias selfsigned -storepass changeit -validity 360 -keysize 2048

Add the following connector to your Tomcats server.xml:

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
			maxThreads="150" scheme="https" secure="true" clientAuth="false"
			sslProtocol="TLS" />

Your default non-https connector should have a redirect on the ssl port (f.i. here 8443).

This should look like this:

<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1"
			redirectPort="8443" />

To verify your settings create a class named AuthenticationServlet:

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.HttpConstraint;
import javax.servlet.annotation.ServletSecurity;
import javax.servlet.annotation.ServletSecurity.TransportGuarantee;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class AuthenticationServlet
 */
@ServletSecurity(@HttpConstraint(rolesAllowed="joern", transportGuarantee=TransportGuarantee.CONFIDENTIAL))
@WebServlet("/AuthenticationServlet")
public class AuthenticationServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public AuthenticationServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter writer = null;
		
		try{
			writer = response.getWriter();
			writer.write("You are now on a secured connection, well done!");
			writer.flush();
		}finally{
			if(writer!=null){
				writer.close();
			}
		}
	}
}

You will get something like this if you try to browse your ssl secured website. Don’t mind it’s just because of your new self signed certificate.
sslwarning

And if you didn’t somehow defined the role (f.i. here joern) you will see the following 403 error:
403

windows azure @ javaone

Microsoft showed the creation of a program running Windows Azure and Glassfish Server in the cloud. Windows Azure has eclipse support, therefor it’s really easy to publish into the cloud.

But didn’t see anything special other componies don’t support. In the end all cloud providers try to sell their datacenter capabilities which originally were planed to be used for other services (ie Bing, Google Search, Amazon store).

One thing to mention, the microsoft guy showed some sort of network authentication. They said that this is a security layer so that in conclusion the developer don’t has to care for his appliacation security. I think this is a really wrong approach I would never give the security in other hands, and never directly in the hands of the microsoft cloud. In my opinion this is more network authentication which can be used in addition to programmtic security (equal to radius).

Link to the slides will be available asap.

Restful webservices @javaone

Jax-RS was one of the most mentioned topics in the java one session. Now everyone tries to use jersey +json to develop new applications. I believe, that this is more than a hype, because json and restful were used by other languages for years. But it will depend on your use case whether to take soap or rs ws. I will still stay with soap in terms of application communication because of the easy creation of stubs and even other features (f.i. security) matter. The overhead of soap is, as discussed a lot, not really a big problem. It’s more the ease for use, for f.i. frontend developers, that matter.

Practical Restful Persistence

* Eclipse Link MOXy enables easy JAXB binding of pojos with JSON (Jax-RS) with integration of JPA.
* easyily supports http (get, put, delete..) methods for objects
* just add jpa_rs library to your project, dependcies on eclipse link and jersey
* not useable with hibernate yet
* partial loading not support yet

* will work with tomcat should work with other container/application server (only with eclipseLink)

more information here moxy website

Keynotes

Yesterday (Sunday) the java one started with a very nice introduction/keynote. It’s topics was mainly the newly introduced Java EE 7 and a perspective for Java 8 (and a few on Java 9).

To sum it up in short here a my most interesting points on this keynote:

* Freely available Java EE Webprofile appliction server from IBM available
* packaged hashmaps can reduce heap size usage and improve speed, realy check this out if you’re working with big data
* Lambda will be introduced by the available rc of java se 8. It’s now available.
* Netbeans has build in support for java scripting (incl. debugging) especially for the following frameworks: angular.js,
knockout.js, jquery

Funny, while demonstating Netbeans crashed. 🙂 Everybody knows, than can happen.

* The newly introduced websockets in java ee 7 are very impressive I hope I will find the time to develop some on my own.

* JSON support was added by Java EE 7
* jAVA ME 8 is available for testing and should be a real performance boost (works even on raspberry pi fluently)
* Java 9 will use GPUs

Java EE6 / @MultipartConfig

The Multipart annotation, introduced by EE 6, is very helpful to create a multipart upload.

First you need to create an upload form with method „post“ and enctype „multipart“.

fileupload.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Fileuploads</title>
</head>
<body>
	  
	<form action="/OCEJWCD/fileupload" method="POST" enctype="multipart/form-data">
		    <input type="file" name="name">
		     <input type="submit"
			value="POST">   
	</form>

</body>
</html>

Next you can easily annotate your request accecpting servlet class with @WebServlet and @MultipartConfig. The MultipartConfig tells the servlet that there will be an incoming multipart upload and you’ll be able to access these parts via the HttServletRequest object.

FileUpload.java

package de.joerndettmer;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

@WebServlet(urlPatterns = "/fileupload", name = "fileuploadServlet")
@MultipartConfig
public class FileUpload extends HttpServlet {

	private static final long serialVersionUID = 2575996974446997345L;

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		Collection<Part> filePart = req.getParts();
		FileOutputStream fos = new FileOutputStream(new File("fileupload.txt"));

		for (Part part : filePart) {
			int read = 0;
			InputStream filecontent = part.getInputStream();
			final byte[] bytes = new byte[1024];
			while ((read = filecontent.read(bytes)) != -1) {
				fos.write(bytes, 0, read);
			}
		}

		fos.flush();
		fos.close();

	}
}


For further information see: MultipartConfig Link

San Francisco Oracle Open World

From September 22 to 26, 2013, I will be at JavaOne in San Francisco, checking out the latest product and technology demos, meeting with fellow developers and industry experts, and learning about all things Java. I will blog my impressions. Perhaps you are going to join me. Ok, it’s a 12000 km trip from germany to usa but in my opinion it’s really cheap (in contrast to german it training).

179481-j1-sf-imattending-250x250-1946280

JRebel

Wow, I finally bought JRebel for my Java development. It’s realy a boost for development if you need to restart your app server often. In my case I save 20 minutes every day, because of the hot deployment features of JRebel. I heard that some people use JRebel in production environments. I’d like to see this in real life, but I can’t imagine that it wouldn’t lead into troubles.

If you want to try JRebel, a 30 day trial is available on their website.

JREBEL

JSP is dead – long live JSP

Yes jsp is not longer the basis for JSF. But it’s still part of EE 6 and will be updated to v.2.2 in EE 7. In my opionion it’s still one of the most implemented Frameworks and because of that JSP will be never (or at least not for the next 10 years) removed from the ee distribution.

Attached the link for the ee 7 draft:

http://jcp.org/en/jsr/detail?id=342

Installieren von Quality Plugins Netbeans

Es gibt Probleme mit dem Standard URL für SQE in Netbeans. Um FindBugs, Checkstyle, PMD etc. zu installieren bitte unter Tools>Plugins>Settings> Add
Name:SQE
URL: http://deadlock.netbeans.org/hudson/job/sqe/lastStableBuild/artifact/build/full-sqe-updatecenter/updates.xml

eintragen. Et voilá alles ist da (unter Plugins, test Checkstyle)

Viel Spaß damit.

NoSQL in vernünftig

Nachdem es einige NoSQL Datenbanken schafften nur sehr performant zu sein, gibt es inzwischen wirklich ernst zunehmende Vertreter. Warum? Weil Prinzipien wie ACID, Transaktionen, Hochverfügbarkeit und konkurrierende Zugriffe aus der realen Welt nicht wegzudenken sind. neo4j ist so ein Vertreter. Ich hoffe das ich in der Zukunft die Möglichkeit habe auch einmal von der Relationalen DB auf so eine DB setzten zu dürfen. Damit wäre das Objektrelationale Mapping überflüssig, und ich könnte viel mehr Zeit mit sinnvollen Dingen verbringen.

neo4j link

Buchemfpehlung zu Java EE 6 Stack

Aus einem vorhergehenden Projekt durfte ich mich mit dem aktuellen Java EE 6 Stack auseinandersetzen. Das Buch „Beginning Java EE 6 mit Glassfish“ hat mir dabei sehr geholfen. Es umschreibt kurz viele der JSR aus dem EE Full Profile. Dem Titel folgend wird zudem kurz auf die EInrichtung von Glassfish wie auf dessen Verwendung eingegangen. Bitte nicht von der einen schlechten Rezession auf Amazon abschrecken lassen .

Amazon Link

Java EE Full Profile

Schnelle Dokumentation unter Windows 7

Wenn schnell eine kurze bebilderte Anleitung / How-To erstellt werden soll, gibt es unter Windows 7 ein nützliches Tool. Die Problemaufzeichnung erfasst zu jeder Aktion auf dem Bildschirm eine Aufnahme. Es wird der ausgewählte Bereich automatisch markiert und es gibt eine Kommentarfunktion. Zum Starten der Problemaufzeichnung einfach unter Windows 7 Start > Programme/Dateien durchsuchen > psr.exe .

 

Graphik der Problemaufzeichnugn
PSR

Blueprint CSS Framework

Blueprint ist ein CSS Framework welches die Anordnung von Elementen auf einem Raster (Z.B. 12er) erlaubt. Hierdurch können sehr schnell sehenswerte Ergebnisse erzielt werden. Ich schreib nochmal ausführlich darüber wenn ich Zeit habe.

http://www.blueprintcss.org/

Übrigens, es gibt eine menge von diesen CSS Frameworks. Anschauen lohnt sich.

Murach’s Java Servlets and JSP

Ist ein klar strukturiertes Buch und eine zusätzliche Vorbereitung für den SCWCD. Für alle die Head First Titel zu chaotisch finden, gibt es hier übersichtliche Kapitel die beim Aufsetzen von Tomcat beginnen und dann über den Netbeans IDE zu den eigentlichen Inhalten JSPs und Servlets kommen. Es gibt immer vollständige Code Beispiele und es gibt weiterführende Download Materialien.

 

Amazon Link