ServletUnitServletContext

Adam Hardy <[email protected]>
Newsgroups gmane.comp.web.httpunit.devel
Message-ID <[email protected]>
Hi,

I am trying to test a website built with a templating package called Tiles - ( 
http://tiles.apache.org ) you may well have heard of it, it is quite popular.

I am doing the following:

StringBuilder xml = new StringBuilder();
xml.append("<?xml version=\"1.0\" etc etc etc....
ServletRunner servletRunner =
     new ServletRunner(new ByteArrayInputStream(xml.toString()
         .getBytes()), "/pattern-repo");
servletRunner.registerServlet("bla", EmptyServlet.class.getName());
WebRequest getRequest =
     new GetMethodWebRequest(
         "http://localhost/pattern-repo/test-result/edit.html");
getRequest.setParameter("code", "1");
WebForm form =
     servletRunner.getResponse(getRequest).getFormWithName(
         "testResultForm");


The problem occurs when the ServletRunner invokes Tiles. Tiles tries to retrieve 
its config from the ServletContext, but the ServletUnitServletContext 
implementation from ServletUnit has package default access modifier so this call 
fails:

private static Object getAttribute(Object context, String attributeName) {
     try {
         Class<?> contextClass = context.getClass();
         Method attrMethod = contextClass.getMethod("getAttribute", String.class);
         return attrMethod.invoke(context, attributeName);
     } catch (Exception e) {
         LOG.warn("Unable to retrieve container from specified context: '" + 
context + "'", e);
         return null;
     }
}


java.lang.IllegalAccessException: Class org.apache.tiles.access.TilesAccess can 
not access a member of class com.meterware.servletunit.ServletUnitServletContext 
with modifiers "public"
     at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
     at java.lang.reflect.Method.invoke(Method.java:578)
     at org.apache.tiles.access.TilesAccess.getAttribute(TilesAccess.java:125)
     at org.apache.tiles.access.TilesAccess.getContainer(TilesAccess.java:74)
     at org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:99)


Is there chance that ServletUnitServletContext can be made public?

Regards
Adam

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.