Skip to main content

17 posts tagged with "java"

View All Tags

路 6 min read

In this article, I will explain how to secure your Redis databases using SSL (Secure Sockets Layer). In production, it is a good practice to use SSL to protect the data that are moving between various computers (client applications and Redis servers). Transport Level Security (TLS) guarantees that only allowed applications/computers are connected to the database, and also that data is not viewed or altered by a middle man process.

You can secure the connections between your client applications and Redis cluster using:

  • One-Way SSL: the client (your application) get the certificate from the server (Redis cluster), validate it, and then all communications are encrypted
  • Two-Way SSL: (aka mutual SSL) here both the client and the server authenticate each other and validate that both ends are trusted.

In this article, I will focus on the Two-Way SSL, and using Redis Enterprise.

路 7 min read

Introduction#

In this article, I will show you how to update Redis Enterprise on PCF and see how Redis Enterprise cluster will guarantee a service continuity using out of the box failover.

If you need a Cloud Foundry application that calls Redis automatically you can use this project simple-redis-spring-demo-pcf.

For this article, I will upgrade Redis Enterprise for PCF from the version v5.4.2400147 to the latest version, currently v5.4.40700169.

路 8 min read

As you may have seen, I have joined Redis Labs a month ago; one of the first task as a new hire is to learn more about Redis. So I learned, and I am still learning.

This is when I discovered Redis Streams. I am a big fan of streaming-based applications so it is natural that I start with a small blog post explaining how to use Redis Streams and Java.

What is Redis Streams?

Redis Streams is a Redis Data Type, that represents a log so you can add new information/message in an append-only mode (this is not 100% accurate since you can remove messages from the log). Using Redis Streams you can build "Kafka Like" applications, what I mean by that you can:

  • create applications that publish and consume messages (nothing extraordinary here, you could already do that with Redis Pub/Sub)
  • consume messages that are published even when your client application (consumer) is not running. This is a big difference with Redis Pub/Sub
  • consume messages starting a specific offset, for example, read the whole history, or only new messages

In addition to this, Redis Streams has the concept of Consumer Groups. Redis Streams Consumer Groups, like Apache Kafka ones, allows the client applications to consume messages in a distributed fashion (multiple clients), providing an easy way to scale and create highly available systems.

Enroll in the Redis University: Redis Streams to learn more and get certified.

Sample Application

The redis-streams-101-java GitHub Repository contains sample code that shows how to

  • post messages to a streams
  • consume messages using a consumer group

路 5 min read

In this article we will see how to create a pub/sub application (messaging, chat, notification), and this fully based on MongoDB (without any message broker like RabbitMQ, JMS, ... ).

So, what needs to be done to achieve such thing:

  • an application "publish" a message. In our case, we simply save a document into MongoDB
  • another application, or thread, subscribe to these events and will received message automatically. In our case this means that the application should automatically receive newly created document out of MongoDB

All this is possible with some very cool MongoDB features: capped collections and tailable cursors,

路 4 min read

An easy way to create large dataset when playing/demonstrating Couchbase -or any other NoSQL engine- is to inject Twitter feed into your database.

For this small application I am using:

In this example I am using Java to inject Tweets into Couchbase, you can obviously use another langage if you want to.

The sources of this project are available on my Github repository Twitter Injector for Couchbase you can also download the Binary version here, and execute the application from the command line, see Run The Application paragraph. Do not forget to create your Twitter oAuth keys (see next paragraph)

Create oAuth Keys#

The first thing to do to be able to use the Twitter API is to create a set of keys. If you want to learn more about all these keys/tokens take a look to the oAuth protocol : http://oauth.net/

1- Log in into the Twitter Development Portal : https://dev.twitter.com/

2- Create a new Application

Click on the "Create an App" link or go into the "User Menu > My Applications > Create a new application"

3- Enter the Application Details information

4- Click "Create Your Twitter Application" button

Your application's OAuth settings are now available :

5- Go down on the Application Settings page and click on the "Create My Access Token" button

You have now all the necessary information to create your application:

  • Consumer key
  • Consumer secret
  • Access token
  • Access token secret

These keys will be uses in the twitter4j.properties file when running the Java application from the command line

Create the Java Application#

The following code is the main code of the application:

Some basic explanation:

  • The setUp() method simply reads the twitter4j.properties file from the classpath to build the Couchbase connection string.
  • The injectTweets opens the Couchbase connection -line 76- and calls the TwitterStream API.
  • A Listener is created and will receive all the onStatus(Status status) from Twitter. The most important method is onStatus() that receive the message and save it into Couchbase.
  • One interesting thing : since Couchbase is a JSON Document database it allows your to just take the JSON String and save it directly. cbClient.add(idStr,0 ,twitterMessage);

Packaging#

To be able to execute the application directly from the Jar file, I am using the assembly plugin with the following informations from the pom.xml:

  ...<archive><manifest><mainclass>com.couchbase.demo.TwitterInjector</mainclass></manifest><manifestentries><class-path>.</class-path></manifestentries></archive>...

Some information:

  • The mainClass entry allows you to set which class to execute when running java -jar command.
  • The Class-Path entry allows you to set the current directory as part of the classpath where the program will search for the twitter4j.properties file.
  • The assembly file is also configure to include all the dependencies (Twitter4J, Couchbase client SDK, ...)

If you do want to build it from the sources, simply run :

mvn clean package

This will create the following Jar file ./target/CouchbaseTwitterInjector.jar

Run the Java Application#

Before running the application you must create a twitter4j.properties file with the following information :

twitter4j.jsonStoreEnabled=true
oauth.consumerKey=[YOUR CONSUMER KEY]oauth.consumerSecret=[YOUR CONSUMER SECRET KEY]oauth.accessToken=[YOUR ACCESS TOKEN]oauth.accessTokenSecret=[YOUR ACCESS TOKEN SECRET]
couchbase.uri.list=http://127.0.0.1:8091/poolscouchbase.bucket=defaultcouchbase.password=

Save the properties file and from the same location run:

jar -jar [path-to-jar]/CouchbaseTwitterInjector.jar

This will inject Tweets into your Couchbase Server. Enjoy !

路 One min read

I am using internally Blojsom for blogging about the product I am taking care of: OC4J and especially the Web Services stack. In this post I am quickly documenting, as the title says, how to install Blojsom on OracleAS 10g.

1-Download#

The first thing to do is to download the product itself, just download the Blojsom quickstart from sourceforge.

2-Deploy#

Since, Blojsom is distributed as a WAR file you have nothing special to do, just deploy it. Anyway I have created a viewlet 聽that shows step by step deployment using Oracle Enterprise Manager.

So the application link will be: http://localhost:8888/blojsom/

Note: if you want to use the command line utility (admin.jar) or the Ant deployment task, you should package the Web archive in an EAR file.

3-Update the home page#

The easiest way will be to just change the index.html page to redirect to the default blog. The index.html page to be modified is in:

  • $ORACLE_HOME/j2ee/home/application/blojsom/blojsomXXXX/index.html where blojsomXXXX is the name of the Web application generated during deployment.
4- Start blogging...#

This is it...

路 3 min read

I would like react to last week marc andreessen's words (netscape founder during the php/zend conference andreessen basically says that PHP will beat Java and succeeds where Java is not. Most of the reasons that Andreesen used to justify this saying are because of PHP simplicity. Do you think he is talking about the language or the application server -yeah, let's call it this way... (J2EE...)..

Let's talk about J2EE first, it is true that when you take a look to the learning curve of J2EE and PHP it is a no brainer.. PHP is effectively more simple. But we can start with the acronyms themselves: J2EE==Enterprise, where PHP==Personal Home Page ( since then renamed Hypertext Processor). So from the origins the 2 technologies were not here to achieve the same goals. But PHP has proven that it could be used for complex application/Web sites, and still keep it simplicity.

So PHP is simple this is true, but Java on the server could be also. I think that the complexity comes from the fact that J2EE its expert always see an application as a enterprise application, and what that means in term of life cycle, development process, packaging and so on....聽聽聽 Why am I saying that it is coming from the expert? Just take a look to a PHP tutorial and a J2EE one? This is clear that you must be a very good and experienced developer to start with J2EE... But this is is not coming from the technologies, but mainly the way we talk about it. I think we should talk a little more about simple development with Java. For example focusing o JSP and JSTL for simple stuff. I agree that putting too much logic in JSP and reduce the number of layer is 'bad' for complex applications, but it could be used for some. Why do we need to always package a WAR or EAR file? Yes you can technically deploy exploded archive and modify the information after the fact. This is not necessary the best practices but it could be useful for some applications (not necessary only in development environment.

About the language itself, sure that Java is more complex, it is considerate as a System Level Language, where PHP is a scripting language. Do we still compare Shell and C? No we need both of them isn't?

In the same time, Java as a language must be simplified, or let be more precise... I think Java developers need the simplicity of scripting languages such as PHP but with the power of Java under the cover. And this is happening right now. JavaScript is now integrated to Java 6, Groovy provided a well integrated JVM with a very powerful and simple syntax. Grails -Groovy On Rails- provided a simple framework for CRUD applications.

Still skeptical about the simplicity of PHP, try it...

Still skeptical about Java being simple, try a scripting language... for example Groovy

In conclusion the platform of my dream should:

  • Keep the simple case simple
  • Made the impossible possible

And I am sure that Java is the good language and platform for that; but Groovy and other scripting languages will help. And I will also continue to develop using PHP too. And both worlds will coexists and be integrated using Web Services and or JSR-223.

路 One min read

Finally the Java specification about Web Service will have a name that makes sense... moving away from JAX-RPC to JAX-WS (JAX Web Services)...

The JAX-RPC name, which stands for Java API for XML-based RPC, is misleading because developers assume it is only about RPC, according to Doug Kohlert, a Sun staff engineer, in his blog this week. 鈥淏y renaming JAX-RPC to JAX-WS, we can eliminate this confusion,鈥 Kohlert wrote. JAX-WS stands for Java API for XML Web Services.

This infoworld article will give you more details.

路 One min read

Mike Keith, Oracle Toplink architect, persistence guru, and member of the EJB 3.0 Expert Group, gives an, in his last entry an overview of EJB 3.0, in the context of the comparison with Hibernate and especially explaining why the statement that we sometimes hear "EJB 3.0 is Hibernate" is wrong.

This blog entry as been selected as a news by The Server Side, titled "EJB 3.0 is not Hibernate" and is very active in term of comments/reaction, feel free to add yours there.

In the same time if you want to learn more about EJB 3.0 and start developing with it you can find infromation and EJB 3.0 container on OTN.

路 One min read

Raghu just posted an interesting article asking the question "Does EJB 3.0 really make application development easy?".

So as you will see EJB 3.0 does simplify the development by reducing the number of source and descriptor files that you have to manipulate. (I won't go in the detail of the number of lines of Java or XML). What I really like about EJB 3.0 is not only the fact that Entity bean are POJOs, but also that now you can read the code and understand how the application is build, thanks to the annotations! I am sure that if you got the EJB 2.x genes you do not find them complex, but I did not have this mutation...

I am inviting you to download the Oracle EJB 3.0 Developer Preview to be more familiar with this technology.

路 One min read

This new Java World article compares the different Java scripting languages (Groovy, JudoScript, Pnuts, JRuby, Jacl, Jython, Rhino, and BeanShell), and list the issues that you have to select the good one...

In this article that I like I would like to read a little about the JSR-223 that should help with the integration part.

I will be very interested to know how you use Java Scripting language in your projects, so feel free to drop me a comment or mail ( tugdual[at]grallandco[dot]com )

路 4 min read

I have been working on the JavaOne Oracle Demo Ground where I was demonstrating OracleAS Portal 10g. I also attend several sessions (EJB 3.0 & CMP Persistence, J2EE 1.4 Web Services, AOP) and Thomas Kurian and James Gosling keynotes.

Also Tuesday afternoon I have been on duty on the Oracle Pod in the Apple developer conference, where I was demonstrating Oracle RDMS and JDeveloper 10g.

JavaOne

Oracle had a very nice and big demo ground, with the best location: in the front of the main entrance. The main theme was Racing Cars. Oracle organized racing contest using Sony Play Station with Gran Turismo 3.

The 10 stations demonstrated the same application that recall the main theme since user can create easily a new racing team. To summarize, we have developed a J2EE 1.3/1.4 application using ADF and POJO (Toplink) but also we integrated JSF for the view, Web Service call and integration with business process using the new Oracle BPEL Process Manager. (Oracle announced the acquisition of Collaxa).

On the Portal station, the demo showed how easy it is to integrate existing MVC application(Struts, ADF, ...) using the Oracle JPDK. Portal teal also built a nice demonstration that shows the same portlet -business logic and view- developed using proprietary APIs (JPDK) and standard based implementation (WSRP & JSR-168). Lot of people stop by the portal pod, and I was pleased with the quality of the questions:

  • Portlet Standards: Oracle provides a JSR-168/WSRP container but also a Developer Preview of the OracleAS 10g Portal that allows you to register and executes WSRP based portlet.

  • Struts, ADF, ad JSF integration: The Oracle PDK provides a Struts integration based on extension of the Struts Tags and has a specific Portlet Renderer.

  • Web Services & Portal: OmniPortlet and Coded Portlets allow developer to easily integrate Web Services into Portal.. and for example it is easy to create a portlet that will kick-off a Business Process that is running inside the Oracle BPEL Process Manager.

Linda DiMichel's session about EJB 3.0 was a big one, the room was packed. EJB is taking the good path. Simplification of the objects no need to multiply the artifacts and deployment descriptors: EJB 3.0 will use Java annotations. 3.0 will use POJO -Plain Old Java Objects- and allow native SQL. This is just a very short summary of the new spec that looks very very good ! (and similar to what Toplink is doing for years)

AOP was also on of the think I wanted to see during this event. I was really pleased by the AOP Panel of Wednesday afternoon. James Gosling, Graham Hamilton, Cedric Beust and Gregor Kiczales presented and discussed AOP in general and AOP in J2EE/Java in particular. My interpretation of the whole discussion is:

Everybody thinks that AOP is interesting, and will make code cleaner; but we have a lot to do to simplify the development. Like Cedric and James said, I am "conflicted" about AOP, and I think the reason is because we see the benefits of AOP in simple case such as logging... But harder to implement cleanly when the aspects are complex such as authentication/authorization or persistence. The Java community still need to work on this to be sure that developers will develop better code; AOP will give it, just have to find the good way ! I have also watched Alex Vasseur and Jonas Boner's session about AOP and J2EE, mainly focus on AspectWerkz. I really liked the paper with lot of demonstration that show simple and concrete example of AOP within J2EE container.

Like lot of us I will continue to invest into AOP and experiment it within the J2EE world. James Strachan - JSR 241 Lead- session was also a very popular one. This session introduced the Groovy Programming Language that leverage the Java Language but using a concise and object oriented scripting language. I will not detail the content of groovy here, it will be better for you to take a quick look to the Groovy Web Site knowing that you can download the language and start to develop script with it.

Apple WWDC 2004

I was not able to attend any session... not event Steve Job's keynote. But I worked on the Oracle demo pod Tuesday afternoon.

We had 2 dual G5 with 'old' cinema displays -hope that next year we will have the 30 inches display!-, these machines were used to run Oracle 10g database and JDeveloper, currently available to developer, you can download them from OTN.

But the big news is the fact that these products will be production on Mac OS X soon:

  • Oracle 10g server production in fall

  • Oracle 10g JDeveloper production in September