portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Deryk Sinotte (JIRA)" <jetspeed-...@portals.apache.org>
Subject [jira] Commented: (JS2-734) Calling PortletContext.getResource in Portlet.init can throw NullPointerException
Date Mon, 18 Jun 2007 16:56:26 GMT

    [ https://issues.apache.org/jira/browse/JS2-734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12505881
] 

Deryk Sinotte commented on JS2-734:
-----------------------------------

Now I'm feeling a bit dense.

The Portlet.init( PortletConfig portletConfig) method takes a PortletConfig parameter.  Which
init() method am I calling inside of that?  Are you saying that I should create a separate
init() method that doesn't take a PortletConfig but does the other logic that I need?  And
if so, how exactly should this address the issue?  Wouldn't the resulting behaviour really
be the same?

I did notice that the Portlet.init( PortletConfig portletConfig) method does seem to be called
twice for some reason even though the portlet only appears once (which I believe violates
the spec).  Is this related?

In any event, I implemented what you recommended and this is what it looks like:

package foo.test;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.Portlet;
import javax.portlet.PortletConfig;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;

public class MyPortlet implements Portlet {

    private transient PortletConfig portletConfig;

    public void init(PortletConfig portletConfig) throws PortletException {
        System.out.println("MyPortlet.init: called");
        this.portletConfig = portletConfig;
        this.initialize();
    }

    private void initialize(){
        PortletContext context = portletConfig.getPortletContext();
        try {
            URL resource = context.getResource("/");
            System.out.println("MyPortlet.initialize: resource = " + resource);
        } catch (MalformedURLException e) {
            e.printStackTrace();
            System.out.println("MyPortlet.initialize: problem getting resource\n" + e);
        }
    }

    public void processAction(ActionRequest actionRequest,
                              ActionResponse actionResponse)
            throws PortletException, IOException {
        System.out.println("MyPortlet.processAction: called");
    }

    public void render(RenderRequest renderRequest,
                       RenderResponse renderResponse)
            throws PortletException, IOException {
        System.out.println("MyPortlet.render: called");

        PortletContext context = portletConfig.getPortletContext();
        try {
            URL resource = context.getResource("/");
            System.out.println("MyPortlet.render: resource = " + resource);
        } catch (MalformedURLException e) {
            System.out.println("MyPortlet.render: problem getting resource\n" + e);
        }
        renderResponse.setContentType("text/html");
        PrintWriter writer = renderResponse.getWriter();
        writer.print("rendered");
        writer.flush();
    }

    public void destroy() {
        System.out.println("MyPortlet.destroy: called");
    }
}


Then I added a single instance to the default-page.psml.  When loading the page, I see the
same error:

2007-06-18 10:47:11,173 [http-8080-Processor25] ERROR org.apache.jetspeed.factory.JetspeedPortletFactory
- PortletFactory: Failed to load portlet foo.test.MyPortlet
java.lang.NullPointerException
        at org.apache.jetspeed.container.JetspeedPortletContext.getResource(JetspeedPortletContext.java:193)
        at foo.test.MyPortlet.initialize(Unknown Source)
        at foo.test.MyPortlet.init(Unknown Source)
        at org.apache.jetspeed.factory.JetspeedPortletInstance.init(JetspeedPortletInstance.java:84)
        at org.apache.jetspeed.factory.JetspeedPortletFactory.getPortletInstance(JetspeedPortletFactory.java:229)
...

I also see the following System.out calls:

MyPortlet.init: called
MyPortlet.init: called
MyPortlet.initialize: resource = jndi:/localhost/jetspeed/
MyPortlet.render: called
MyPortlet.render: resource = jndi:/localhost/jetspeed/


> Calling PortletContext.getResource in Portlet.init can throw NullPointerException
> ---------------------------------------------------------------------------------
>
>                 Key: JS2-734
>                 URL: https://issues.apache.org/jira/browse/JS2-734
>             Project: Jetspeed 2
>          Issue Type: Bug
>          Components: Container
>    Affects Versions: 2.1
>            Reporter: Deryk Sinotte
>
> It's fairly easy to demonstrate the issue.  In the init() method of a simple Portlet,
if I attempt to get the PortletContext and then call getResource on it like so:
>         PortletContext context = portletConfig.getPortletContext();
>         try {
>             URL resource = context.getResource("/");
>         } catch (MalformedURLException e) {
>              e.printStackTrace();
>         }
> I'll get the following:
> 2007-06-14 15:13:31,125 [http-8080-Processor25] ERROR org.apache.jetspeed.factory.JetspeedPortletFactory
- PortletFactory: Failed to load portlet foo.test.MyPortlet
> java.lang.NullPointerException
>         at org.apache.jetspeed.container.JetspeedPortletContext.getResource(JetspeedPortletContext.java:193)
>         at foo.test.MyPortlet.init(Unknown Source)
>         at org.apache.jetspeed.factory.JetspeedPortletInstance.init(JetspeedPortletInstance.java:84)
>         at org.apache.jetspeed.factory.JetspeedPortletFactory.getPortletInstance(JetspeedPortletFactory.java:229)
>         at org.apache.jetspeed.aggregator.impl.HeaderAggregatorImpl.renderHeaderFragment(HeaderAggregatorImpl.java:1056)
>         at org.apache.jetspeed.aggregator.impl.HeaderAggregatorImpl.aggregateAndRender(HeaderAggregatorImpl.java:1037)
>         at org.apache.jetspeed.aggregator.impl.HeaderAggregatorImpl.aggregateAndRender(HeaderAggregatorImpl.java:1029)
>         at org.apache.jetspeed.aggregator.impl.HeaderAggregatorImpl.aggregateAndRender(HeaderAggregatorImpl.java:1029)
>         at org.apache.jetspeed.aggregator.impl.HeaderAggregatorImpl.build(HeaderAggregatorImpl.java:1007)
>         at org.apache.jetspeed.aggregator.HeaderAggregatorValve.invoke(HeaderAggregatorValve.java:48)
>         at org.apache.jetspeed.pipeline.JetspeedPipeline$Invocation.invokeNext(JetspeedPipeline.java:166)
>         at org.apache.jetspeed.decoration.DecorationValve.invoke(DecorationValve.java:97)
>         at org.apache.jetspeed.pipeline.JetspeedPipeline$Invocation.invokeNext(JetspeedPipeline.java:166)
>         at org.apache.jetspeed.pipeline.valve.impl.ActionValveImpl.invoke(ActionValveImpl.java:182)
>         at org.apache.jetspeed.pipeline.JetspeedPipeline$Invocation.invokeNext(JetspeedPipeline.java:166)
>         at org.apache.jetspeed.container.ContainerValve.invoke(ContainerValve.java:76)
>         at org.apache.jetspeed.pipeline.JetspeedPipeline$Invocation.invokeNext(JetspeedPipeline.java:166)
>         at org.apache.jetspeed.profiler.impl.ProfilerValveImpl.invoke(ProfilerValveImpl.java:255)
>         at org.apache.jetspeed.pipeline.JetspeedPipeline$Invocation.invokeNext(JetspeedPipeline.java:166)
>         at org.apache.jetspeed.security.impl.LoginValidationValveImpl.invoke(LoginValidationValveImpl.java:159)
>         at org.apache.jetspeed.pipeline.JetspeedPipeline$Invocation.invokeNext(JetspeedPipeline.java:166)
>         at org.apache.jetspeed.security.impl.PasswordCredentialValveImpl.invoke(PasswordCredentialValveImpl.java:149)
>         at org.apache.jetspeed.pipeline.JetspeedPipeline$Invocation.invokeNext(JetspeedPipeline.java:166)
>         at org.apache.jetspeed.localization.impl.LocalizationValveImpl.invoke(LocalizationValveImpl.java:169)
>         at org.apache.jetspeed.pipeline.JetspeedPipeline$Invocation.invokeNext(JetspeedPipeline.java:166)
>         at org.apache.jetspeed.security.impl.AbstractSecurityValve$1.run(AbstractSecurityValve.java:118)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at javax.security.auth.Subject.doAsPrivileged(Subject.java:454)
>         at org.apache.jetspeed.security.JSSubject.doAsPrivileged(JSSubject.java:195)
>         at org.apache.jetspeed.security.impl.AbstractSecurityValve.invoke(AbstractSecurityValve.java:112)
>         at org.apache.jetspeed.pipeline.JetspeedPipeline$Invocation.invokeNext(JetspeedPipeline.java:166)
>         at org.apache.jetspeed.container.url.impl.PortalURLValveImpl.invoke(PortalURLValveImpl.java:67)
>         at org.apache.jetspeed.pipeline.JetspeedPipeline$Invocation.invokeNext(JetspeedPipeline.java:166)
>         at org.apache.jetspeed.capabilities.impl.CapabilityValveImpl.invoke(CapabilityValveImpl.java:128)
>         at org.apache.jetspeed.pipeline.JetspeedPipeline$Invocation.invokeNext(JetspeedPipeline.java:166)
>         at org.apache.jetspeed.pipeline.JetspeedPipeline.invoke(JetspeedPipeline.java:145)
>         at org.apache.jetspeed.engine.JetspeedEngine.service(JetspeedEngine.java:214)
>         at org.apache.jetspeed.engine.JetspeedServlet.doGet(JetspeedServlet.java:242)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
>         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
>         at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
>         at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
>         at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
>         at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
>         at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:688)
>         at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:658)
>         at org.apache.jsp.index_jsp._jspService(index_jsp.java:44)
>         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
>         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
>         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
>         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
>         at org.apache.jetspeed.engine.servlet.XXSUrlAttackFilter.doFilter(XXSUrlAttackFilter.java:51)
>         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
>         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
>         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
>         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
>         at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
>         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
>         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
>         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
>         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
>         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
>         at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
>         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
>         at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
>         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
>         at java.lang.Thread.run(Thread.java:613)
> It appears the PortletContext gets created but the wrapped servlet context that it uses
is null.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message