Saturday, February 27, 2010

cglib problems

If you get the following, the problem is the maven repository on java.net has a corrupted cglib.

Downloading: https://maven-repository.dev.java.net/nonav/repository/cglib/jars/cglib-full-2.0.2.jar
352b downloaded (cglib-full-2.0.2.jar)
[WARNING] *** CHECKSUM FAILED - Checksum failed on download: local = 'bf6c0a94ff26337817cc7e276e0176ceedade91f'; remote = '


To get around this, add the following to your settings.xml. It will exclude the java.net repositories that are directly referenced in the castor pom.


<profiles>
<profile>
<id>excludejava</id>
<repositories>
<repository>
<id>java.net</id>
<url>https://maven-repository.dev.java.net/nonav/repository</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>maven2-repository.dev.java.net</id>
<url>https://maven2-repository.dev.java.net/nonav/repository</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>excludejava</activeProfile>
</activeProfiles>


See log4j 1.2.15 points to nonfuctional maven-repository.dev.java.net packages breaking whole build for more info. Hopefully someone can clean up the java.net repositories.

Wednesday, February 24, 2010

Getting started with portletUnit2

The portletUnit project is being rewritten to make it simpler to maintain and to use.

Creating a simple portlet application

Add a repository to the settings.xml:

portletunit
PortletUnit Repository
http://portletunit.sf.net/maven2

daily


never



Then run the create:
mvn archetype:generate -DarchetypeCatalog=http://portletunit.sf.net/maven2/archetype-catalog.xml

If you have firewall issues, copy that xml to ~/.m2/archetype-catalog.xml and run mvn archetype:generate -DarchetypeCatalog=local


Thursday, January 28, 2010

Understanding the Java Portlet Specification 2.0 (JSR 286)

Thursday, May 15, 2008

PortletWork: Testing Portlets with Jetty, Pluto and JWebUnit

PortletWork: Testing Portlets with Jetty, Pluto and JWebUnit: "After my last two entries, I've gotten some questions about using pluto embedded in jetty to create automated integration tests for JSR 168 portlets. Using the maven-jetty-plugin for running the portlets is great for fast, iterative development. But it can't be used to run automated integration tests. Remembering an excellent article from Johannes Brodwall's blog about integration testing with Jetty and JWebUnit, I wanted to extend his approach to use the embedded jetty-pluto setup I have created. This turned out to be to be quite easy."

Thursday, May 01, 2008

Bare Bones Browser Launch for Java • • • Use Default Browser to Open a Web Page from portletUnit

One drawback of portletUnit is not being able to really see the rendered code. Using the ideas of the Bare Bones Browser Launch for Java, I am now able to display the rendered code.

Bare Bones Browser Launch for Java • • • Use Default Browser to Open a Web Page from a Swing Application: "Java is often touted as the programing language of the Internet, so you would think Java might include a standard platform-independent mechanism to launch the user's default web browser. Unfortunately, this commonly needed feature is left to the application developer to build, and it's not particularly easy."


The code I am using is:


/**
* Show the response in a browser.
*
* @param response
* the response
* @param class1
* not used but the intent is to add a system propery regex that
* will control whether this page is loaded or not. Default will be none.
* @param id
* another regex system property will match against this. Default will be all.
* @throws Exception
* on error
*/
public static void showResponseInBrowser(WebResponse response, Class class1, String id) throws Exception {
String text = response.getText();
File f = File.createTempFile("httpUnit", ".html");
f.deleteOnExit();
PrintWriter fod = new PrintWriter(new FileOutputStream(f));
fod.print("<head><base href="'http://localhost'/"> </head>");
fod.print(text);
fod.close();
URL url = f.toURL();
openURL(url);
}

/**
* Bare Bones Browser Launch Version 1.5 (December 10, 2005) By Dem
* Pilafian. Supports: Mac OS X, GNU/Linux, Unix, Windows XP
*
* Example Usage: String url = "http://www.centerkey.com/";
* BareBonesBrowserLaunch.openURL(url); Public Domain Software -- Free to
* Use as You Like
*
* @param url
* the url to open
* @throws ClassNotFoundException
* getting class
* @throws NoSuchMethodException
* yes
* @throws SecurityException
* well
* @throws InvocationTargetException
* trying to invloke
* @throws IllegalAccessException
* trying to access
* @throws IllegalArgumentException
* bad arguement
* @throws IOException
* opening window
* @throws InterruptedException waiting
*/
public static void openURL(URL url) throws ClassNotFoundException, NoSuchMethodException,
IllegalAccessException, InvocationTargetException, IOException, InterruptedException {
String osName = System.getProperty("os.name");

if (osName.startsWith("Mac OS")) {
Class fileMgr = Class.forName("com.apple.eio.FileManager");
Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] {String.class });
openURL.invoke(null, new Object[] {url.toString() });
} else if (osName.startsWith("Windows")) {
String cmdLine = "rundll32 url.dll,FileProtocolHandler " + url.toString();
Process exec = Runtime.getRuntime().exec(cmdLine);
exec.waitFor();
} else { // assume Unix or Linux
String[] browsers = {"firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" };
String browser = null;
for (int count = 0; count < browsers.length && browser == null; count++) { if (Runtime.getRuntime().exec(new String[] {"which", browsers[count] }).waitFor() == 0) { browser = browsers[count]; } } if (browser == null) { throw new IllegalStateException("Could not find web browser"); } else { Runtime.getRuntime().exec(new String[] {browser, url.toString() });
}
}
}


I am creating a <base> for all the links so the images and CSS all get included as needed.

Friday, April 25, 2008

PortletUnit and Spring Portlet: Checking form validation errors

Spring Portlet allows validators to be added to SimpleFormController and objects that extend it. When the form is submitted, the validators are run and if any fail, the form is redisplayed with error messages indicating the problem areas. When testing with portletUnit, it is not obvious how to check if there were any form errors. Fortunately, using the render listener feature of PortletRunner, there is a simple way to check for validator errors.

WebResponse response = runner.getResponse(MAGIC_URL);
WebForm form = response.getFormWithID(PRINT_COMMAND);
form.setParameter(PrintData.PARAMETER_NAME_PURPOSE, REPORT_PURPOSE);
SubmitButton button = form.getSubmitButtonWithID(IDPRINT);
runner.addRenderListener(new PortletUnitRenderListener() {

public void after(Portlet arg0, RenderRequest request, RenderResponse arg2) throws Exception {

BindException bindException = (BindException) request.getPortletSession().getAttribute(
"org.springframework.web.portlet.mvc.RenderErrors");

assertEquals(0, bindException.getErrorCount());
}

public void before(Portlet arg0, RenderRequest arg1, RenderResponse arg2) throws Exception {
// EMPTY
}

});
form.submit(button);


The trick is to know that the BindException object is stored in the portlet session with the name org.springframework.web.portlet.mvc.RenderErrors. Simply install a listener and in the after method check to make sure there were no errors. You can use the same technique to ensure validation errors really do happen.

Wednesday, January 30, 2008

Using portletUnit with Maven Surefire

I have been using portletUnit with Maven and surefire. There are a couple of issues that need to be worked around.

Issue 1: Dependencies

portletUnit still relies on 3 special jar files and these need to be added to your local maven repository. The effort to move to a more stable dependency tree is underway.

Issue 2: Jasper classpath

Out of the box, surefire forks the unit tests. Jasper does not like it. If JSPs are complaining about missing classes, try turning off forking with:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>never</forkMode>
</configuration>
</plugin>