Tag Archives: Java

Java – Convert InputStream to String

Recently, i have created a simple Java Servlet server which could parse a request xml from the HTTP POST Request and then return the HTTP Response together with the response xml. In the server implementation, i need to convert an InputStream into a String. The following code shows you how to make it.

In this example, the program will read the data.txt file and print the content to the console. Continue reading Java – Convert InputStream to String

Struts 2 – Model View Controller in Struts 2

The previous article shows you how to configure a basic Struts 2 project in Maven.
Struts 2 – Setup a Struts 2 Web Application in Maven
 

Now, i continue the Struts 2 tutorial and build the first set of model, view and controller.
1. Create the MessageStore model Continue reading Struts 2 – Model View Controller in Struts 2

Struts 2 – Setup a Struts 2 Web Application in Maven

I follow the Struts 2 tutorial and setup a simple Struts 2 application.
Create Struts 2 Web Application Using Maven To Manage Artifacts and To Build The Application
 

I used the struts2-core version 2.2.1 and also added a maven-jetty-plugin for running the web application. But when i run mvn jetty:run, the following error is found.
java.lang.IllegalArgumentException: Javassist library is missing in classpath! Please add missed dependency!

It is found that in struts2-core version 2.2.1, the Javassist dependency was excluded in OGNL. So i have to add this dependency in the pom.xml by myself.
 

So here comes to the project details. Continue reading Struts 2 – Setup a Struts 2 Web Application in Maven

Java – Connect Windows Active Directory Through LDAP @ 1

The Java Naming and Directory Interface (JNDI) is the standard Java API for multiple naming and directory services such as Lightweight Directory Access Protocol (LDAP).

Active Directory is a group of network services like account authentication and it supports LDAP. Therefore, you can write a Java program using JNDI in order to obtain the account credentials in the Active Directory of a Windows Server. Here comes the example. Continue reading Java – Connect Windows Active Directory Through LDAP @ 1

Objective-C – NSDictionary Example

NSDictionary is a useful object to store key-pair values just like HashMap in Java.

You can create and iterate a NSDictionary as follow

// Create a NSDictionary
NSArray *keys = [NSArray arrayWithObjects:@"key1", @"key2", @"key3", nil];
NSArray *objs = [NSArray arrayWithObjects:@"obj1", @"obj2", @"obj3", nil];
NSDictionary *dict = [NSDictionary dictionaryWithObjects:objs forKeys:keys];
	
// Iterate it
for (id key in dict) {
	NSLog(@"key: %@   value:%@", key, [dict objectForKey:key]);
}

  Continue reading Objective-C – NSDictionary Example

Portecle – Keystore and Certification Manager

Previously, i was working with an web application which allows me to upload a certificate into a keystore. Unfortunately, it only accept certificate in Base64/PEM format but not binary. So i have to convert the certificate into Base64/PEM and this could be done by Portecle.

Portecle is a very useful Java program with User Interface which make keystore and certificate management a piece of cake. The following screenshots show you how to get the Base64/PEM encoding from a binary certificate. Continue reading Portecle – Keystore and Certification Manager

Maven – Using maven-jetty-plugin to Start a webapp of another Maven Module

Normally, the maven-jetty-plugin should be configured in the pom of your Maven webapp project/module. But the project i am working is a legacy Java project with many modules and the webapp module depends on others. so i cannot simply start it due to the build sequence.

What i am going to do is to add an new Maven module for integration test of the Maven webapp module and it would be build in the last module such that all other modules are ready.
Continue reading Maven – Using maven-jetty-plugin to Start a webapp of another Maven Module

Run Selenium in Tapestry Maven Project

If you want to know how to run Selenium in a Maven webapp project, you can refer to the following post.
Selenium – Integrate the Selenium Tests into Maven Build
 

If you are a Tapestry user, the pom.xml in the above article may not work as the webapp cannot be started in the Embedded Jetty (404 Not Found). I am not sure the reason behind but i find a work around to solve the problem. The tricky thing is in the Embedded Jetty configuration in the cargo2-maven-plugin.
Continue reading Run Selenium in Tapestry Maven Project