Topic
1 reply Latest Post - ‏2012-08-02T07:42:50Z by nchieffo
nchieffo
nchieffo
2 Posts
ACCEPTED ANSWER

Pinned topic WCM java api: how to create a fake rendering context?

‏2012-07-21T07:40:38Z |
Hello, I'm writing a java library in which I need to include some functionality that need a RenderingContext instance to work.

For example I need to extract an ImageContentComponent url, and the only way to do that (as I know) is to run
workspace.generateURL(RenderingContext context, ContentComponent component)
Another example: I need to render a content, so the api to call is
workspace.render(RenderingContext renderingContext)

What I don't have in my library, is an instance of RenderingContext, because I want to do those operation and obtain the HTML code even without a real RenderingContext.
Why? For example simply because I need to run those operations inside a custom workflow action, where a RenderingContext is not available.

The api to create a RenderingContext is:
RenderingContext context = workspace.createRenderingContext(servletRequestObj,
servletResponseObj,
new HashMap(),
"http://HOSTNAME:PORT/CONTEXT",
"connect");

do you actually have any idea on what to pass as
servletRequestObj
servletResponseObj
?

Is there any usable mock class?

Thanks
Updated on 2012-08-02T07:42:50Z at 2012-08-02T07:42:50Z by nchieffo
  • nchieffo
    nchieffo
    2 Posts
    ACCEPTED ANSWER

    Re: WCM java api: how to create a fake rendering context?

    ‏2012-08-02T07:42:50Z  in response to nchieffo
    I've got a solution for this: you need the spring-core and spring-test jars.
    String wcmHost = "http://localhost:10039";
    String wcmServletPath = "/wps/wcm/connect";
    String wcmWebAppPath = wcmHost + wcmServletPath;

    ServletRequest request = new MockHttpServletRequest();
    ServletResponse response = new MockHttpServletResponse();
    HashMap<String, String> params = new HashMap<String, String>();
    RenderingContext renderingContext = _workspace.createRenderingContext(request, response, params);
    renderingContext.setWcmWebAppPath(wcmWebAppPath);
    renderingContext.setWcmServletPath(wcmServletPath);