[ 
https://issues.apache.org/jira/browse/WICKET-5318?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13756417#comment-13756417
 ] 

Hans Lesmeister commented on WICKET-5318:
-----------------------------------------

Thanks for the advice. I will test it a.s.a.p. Another work-around is to use 
{{response.setError(404)}} like here:
{code}707
    public IResource getResource() {
        return new AbstractResource() {
            @Override
            protected ResourceResponse newResourceResponse(Attributes 
attributes) {
                PageParameters parameters = attributes.getParameters();
                if (parameters == null) {
                    throw new IllegalStateException("parameters is null");
                }

                final String folder = ParameterUtil.getString(parameters, 
"folder", "");
                final String name = ParameterUtil.getString(parameters, "name", 
"");
                final String resolution = ParameterUtil.getString(parameters, 
"resolution", "");

                final InputStream stream = 
odcService.createStreamFromPath(folder, resolution, name);
                final ResourceResponse response = new ResourceResponse();

                if (stream == null) {
                    log.info("Asset {}/{}/{} not found", new Object[] {folder, 
resolution, name});
                    response.setError(404, "Asset " + folder +"/" + resolution 
+ "/" + name + " not found");
                }
                else {
                    response.setWriteCallback(new WriteCallback() {
                        @Override
                        public void writeData(Attributes attributes) throws 
IOException {
                            try {
                                writeStream(attributes, stream);
                            } finally {
                                IOUtil.close(stream);
                            }
                        }
                    });
                }

                return response;
            }
        };
    }
{code}

                
> Mounted Dynamic Resource: IllegalStateException
> -----------------------------------------------
>
>                 Key: WICKET-5318
>                 URL: https://issues.apache.org/jira/browse/WICKET-5318
>             Project: Wicket
>          Issue Type: Task
>          Components: wicket
>    Affects Versions: 6.8.0
>         Environment: Java 1.6, Windows 7
>            Reporter: Hans Lesmeister
>            Assignee: Martin Grigorov
>         Attachments: QuickStartWicket6.zip
>
>
> Copied from:
> http://apache-wicket.1842946.n4.nabble.com/Mounted-Dynamic-Resource-IllegalStateException-td4660927.html
> To deliver resources (mainly images) dynamically, we have created a custom 
> ResourceReference and mounted that to a path:
>   // in our Application.init():
>   mountResource("assets/${path}/${name}, new CustomResourceReference());
>   
>   // in CustomResourceReference:
>       public IResource getResource() {
>         return new AbstractResource() {
>             @Override
>             protected ResourceResponse newResourceResponse(Attributes 
> attributes) {
>                 // (slightly simplified for readability)
>                 final String folder = parameters.get("folder").toString();
>                 final String folder = parameters.get("name").toString();
>                 ResourceResponse response = new ResourceResponse();
>                 response.setWriteCallback(new WriteCallback() {
>                     @Override
>                     public void writeData(Attributes attributes) throws 
> IOException {
>                         InputStream stream = null;
>                         try {
>                             log.debug("Getting stream for {}/{}", folder, 
> name);
>                             stream = ourService.createStreamFromPath(folder, 
> name);
>                             if (stream == null) {
>                                 log.debug("Stream for {}/{} could not be 
> retrieved. Returning 404", folder, name);
>                                 throw new 
> AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND);
>                             }
>                             log.debug("Writing stream", folder, name);
>                             writeStream(attributes, stream);
>                         } finally {
>                             IOUtil.close(stream);
>                         }
>                     }
>                 });
>                 return response;
>             }
>         };
>     }
>   
> As long as the image is there and an inputstream can be retrieved from our 
> service, everything works fine. However if a stream is not available, we 
> throw an AbortException 404. In that case later on there is this stacktrace 
> on the console:
> java.lang.IllegalStateException: Response is no longer buffering!
>       at 
> org.apache.wicket.protocol.http.HeaderBufferingWebResponse.reset(HeaderBufferingWebResponse.java:205)
>       at 
> org.apache.wicket.request.flow.ResetResponseException$ResponseResettingDecorator.respond(ResetResponseException.java:87)
>       at 
> org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:861)
>       at 
> org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
>       at 
> org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:93)
>       at 
> org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261)
>       at 
> org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218)
>       at 
> org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
>       at 
> org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)
>       at 
> org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:201)
>       at 
> org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:282)
>       at 
> com.cantaa.emb.ofsi.frontend.common.OFSIWebFilter.doFilter(OFSIWebFilter.java:28)
> This again leads to Wicket trying to deliver the ErrorPage which is not 
> wanted.
> So my question is: what do we do wrong? I guess I should not throw an 
> AbortException here, but what do I do instead to get a 404 to the browser? 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to