In order to enabled autowiring capabilities, add the following properties to the beans element.
xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"
xmlns:context="http://www.springframework.org/schema/context"
And make sure this line is included within the beans element
<context:annotation-config />
Next, in your code, get an instance of AutowireCapableBeanFactory.
Hint: Subclasses of AbstractApplicationContext have a getAutowireCapableBeanFactory, just one way to get such an instance.
Finally call the autowireBean(MyObject) method and like magic, so long as the annotations are correct, Spring will inject the correct instances.
Monday, May 9, 2011
Thursday, May 5, 2011
Steps to add ssl cert to JVM
Found a great link for adding certs to java for windows, Mac, and linux.
http://eclipse.open.collab.net/servlets/ProjectProcess?pageID=3450
http://eclipse.open.collab.net/servlets/ProjectProcess?pageID=3450
Wednesday, April 27, 2011
jquery.dataTables
Great plugin for jQuery that makes creating a dynamically sortable, searchable, and page-able table via JavaScript a snap.
First create a properly formated html table with a unique id: eg. <table id="mytable"><thead></thead><tbody></tbody></table>
Then with one line of JavaScript, the table transforms into the dynamic table described above.
<script>
$('#myTable').dataTable();
</script>
PROS: Super easy with lots of baked in functionality
CONS: Requires all the table data to be written out to html page, possibly eating up unnecessary bandwidth.
See Also:
First create a properly formated html table with a unique id: eg. <table id="mytable"><thead></thead><tbody></tbody></table>
Then with one line of JavaScript, the table transforms into the dynamic table described above.
<script>
$('#myTable').dataTable();
</script>
PROS: Super easy with lots of baked in functionality
CONS: Requires all the table data to be written out to html page, possibly eating up unnecessary bandwidth.
See Also:
Friday, April 22, 2011
How to create a custom TypeConverter in Stripes
Stripes uses TypeConverters to take convert JSP responses (typically a serialized form), and convert it back into Java types. Most conversions that you will need are already provided by default (see like below), but I found with Enums sometimes special cases are needed. There are ways to register customer converts globally, but in this case I just needed it for a specific case.
Once the class is defined, it needs to be wired up in the ActionBean. In the below snipped, note the converter param in the @Validate annotation.
See Also:
Example Custom TypeConverter
public class MyEnumeratedTypeConverter extends EnumeratedTypeConverter{
@Override
public MyEnum convert(String input, Class targetType, Collection errors) {
MyEnum type = //Your conversion logic here.
if(type == null){
errors.add(new ScopedLocalizableError("converter.enum", "notAnEnumeratedValue"));
}
return type;
}
}
@Override
public MyEnum convert(String input, Class targetType, Collection
MyEnum type = //Your conversion logic here.
if(type == null){
errors.add(new ScopedLocalizableError("converter.enum", "notAnEnumeratedValue"));
}
return type;
}
}
Once the class is defined, it needs to be wired up in the ActionBean. In the below snipped, note the converter param in the @Validate annotation.
Example Wire-Up
@Validate(required = false, on={"fetch"}, converter=MyEnumeratedTypeConverter.class)
public void setMyEnums(Collection myenums){
this.myenums = myenums;
}
public void setMyEnums(Collection
this.myenums = myenums;
}
See Also:
Thursday, April 7, 2011
Ignoring Certs for Testing
Had an issue while using XFire (legacy version of CXF), where I needed to access a website using ssl but that had a self-signed cert. The Protocol constructor is depreciated, but for testing purposes works fine.
EasySSLProtocolSocketFactory basically uses a "null" implementation of a X509TrustManager.
See Also:
http://stackoverflow.com/questions/2301548/calling-axis2-web-service-from-xfire-client-the-endpoint-reference-epr-for-the
Example
//protocol=https, etc
protected static void ignoreCertsFor(String protocol, int port){
Protocol.registerProtocol(protocol, new Protocol(protocol, new EasySSLProtocolSocketFactory(), port));
}
protected static void ignoreCertsFor(String protocol, int port){
Protocol.registerProtocol(protocol, new Protocol(protocol, new EasySSLProtocolSocketFactory(), port));
}
EasySSLProtocolSocketFactory basically uses a "null" implementation of a X509TrustManager.
"null" X509TrustManager Example
new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
See Also:
http://stackoverflow.com/questions/2301548/calling-axis2-web-service-from-xfire-client-the-endpoint-reference-epr-for-the
Friday, April 1, 2011
How to create a Self-Executing Jar with Maven
Example
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>namespace.ClassWthMainMethod</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>namespace.ClassWthMainMethod</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
Maven Assembly Plugin Example
Example
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>create-target</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>path/to/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>create-target</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>path/to/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
See Also:
Subscribe to:
Posts (Atom)