On Wed, Dec 21, 2011 at 7:50 PM, Pablo Díaz <inspd...@gmail.com> wrote: > Thank you for your answer but I think this is only correct when you are > returning a CharSequence, what's happen when you like returning Image, for > example? >
If you need to return an Image then definitely you don't need to extend a Page. See solution 1) I suggested - using IResource. > El 21/12/11 10:33, Martin Grigorov escribió: > >> The problem with EmptyRequestHandler is that the previous response is >> reset and an empty is written to the client. >> >> There are several solutions for your problem: >> 1) use a IResource instead of a Page. You don't use components anyway. >> See wicketinaction.com/2011/07/wicket-1-5-mounting-resources/ for more >> info. >> >> 2) Use a WebPage that implements >> org.apache.wicket.markup.IMarkupResourceStreamProvider and >> org.apache.wicket.markup.IMarkupCacheKeyProvider >> The first interface is needed to generate the markup dynamically. E.g. >> : return new StringResourceStream(yourDataReturnedFromHttpClient) >> The second should return "null" in #getCacheKey() to not cache the >> result from the first. I.e. Wicket will ask IMarkupCacheKeyProvider >> for new data for each request. >> >> 3) Do what Igor suggested with EmptyRequestHandler but use >> TextRequestHandler(yourDataReturnedFromHttpClient) instead. >> >> On Tue, Dec 20, 2011 at 10:11 PM, Igor Vaynberg<igor.vaynb...@gmail.com> >> wrote: >>> >>> what is the stack trace look like now? >>> >>> also, no need to extend a webpage, why not just impplement >>> IRequestHandler directly and mount it somewhere so you can construct >>> urls to it... >>> >>> -igor >>> >>> On Tue, Dec 20, 2011 at 11:24 AM, Pablo Díaz<inspd...@gmail.com> wrote: >>>> >>>> I've done that, but I get the same result :( >>>> >>>> El 20/12/11 20:18, Igor Vaynberg escribió: >>>> >>>>> (httpservletresponse)getresponse().getcontainerresponse() >>>>> >>>>> -igor >>>>> >>>>> On Tue, Dec 20, 2011 at 10:58 AM, Pablo Díaz<inspd...@gmail.com> >>>>> wrote: >>>>>> >>>>>> Ok, but How I can get the httpservletresponse object to write in it? >>>>>> I'm >>>>>> extending the WebPage class ... >>>>>> >>>>>> El 20/12/11 19:26, Igor Vaynberg escribió: >>>>>> >>>>>>> try writing directly into httpservletresponse instead of wicket's >>>>>>> response. there is a bug fix for this in the upcoming release.... >>>>>>> >>>>>>> -igor >>>>>>> >>>>>>> On Tue, Dec 20, 2011 at 10:03 AM, Pablo Díaz<inspd...@gmail.com> >>>>>>> wrote: >>>>>>>> >>>>>>>> Ok, thank you, I'm not getting the error if I use your code, but I'm >>>>>>>> not >>>>>>>> able to gets the response (I always get a blank image, when I must >>>>>>>> get >>>>>>>> a >>>>>>>> map). >>>>>>>> >>>>>>>> I mean, I only like getting the request done from someone and check >>>>>>>> if >>>>>>>> he >>>>>>>> has enough privileges to do some operation Then, I change some >>>>>>>> parameters >>>>>>>> depends on his role he can. >>>>>>>> >>>>>>>> My code is like this: >>>>>>>> >>>>>>>> public class ProxyAction extends WebPage { >>>>>>>> >>>>>>>> public ProxyAction(PageParameters parameters){ >>>>>>>> URL url = null; >>>>>>>> Logger logger = Logger.getLogger(ProxyAction.class); >>>>>>>> HttpURLConnection con = null; >>>>>>>> Response response = getResponse(); >>>>>>>> ByteArrayBuffer bab = new ByteArrayBuffer(); >>>>>>>> >>>>>>>> try { >>>>>>>> String mapserverUrl = >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> "http://localhost/cgi-bin/mapserv?mode=map&map=/var/local/mapserver/inveco/map/client_draw.map&layers=provincias"; >>>>>>>> Iterator<String> it = claves.iterator(); >>>>>>>> while(it.hasNext()){ >>>>>>>> String clave = (String) it.next(); >>>>>>>> mapserverUrl= mapserverUrl + "&"+ clave+"="; >>>>>>>> List<StringValue> valores = >>>>>>>> parameters.getValues(clave); >>>>>>>> for(int i=0; i<valores.size(); i++){ >>>>>>>> mapserverUrl = mapserverUrl+valores.get(i)+" "; >>>>>>>> } >>>>>>>> } >>>>>>>> >>>>>>>> url = new URL(mapserverUrl); >>>>>>>> con = (HttpURLConnection) url.openConnection(); >>>>>>>> >>>>>>>> InputStream istream = con.getInputStream(); >>>>>>>> byte[] b = new byte[1]; >>>>>>>> for(;;){ >>>>>>>> if(istream.read(b) == -1) >>>>>>>> break; >>>>>>>> bab.write(b); >>>>>>>> } >>>>>>>> >>>>>>>> response.write(bab.getRawData()); >>>>>>>> getRequestCycle().replaceAllRequestHandlers(new >>>>>>>> EmptyRequestHandler()); >>>>>>>> >>>>>>>> } catch (MalformedURLException e) { >>>>>>>> logger.error(e.getMessage()); >>>>>>>> } catch (IOException e) { >>>>>>>> logger.error(e.getMessage()); >>>>>>>> } >>>>>>>> //this.getRequestCycle().setResponse(response); >>>>>>>> } >>>>>>>> } >>>>>>>> El 20/12/11 18:17, Igor Vaynberg escribió: >>>>>>>> >>>>>>>>> in the future, start with the error :) >>>>>>>>> >>>>>>>>> you have to tell wicket that it should not render the page after >>>>>>>>> you >>>>>>>>> have written the data out... >>>>>>>>> >>>>>>>>> output.write(data); >>>>>>>>> getrequestcycle().replaceallrequesthandlers(new >>>>>>>>> EmptyRequestHandler()); >>>>>>>>> >>>>>>>>> >>>>>>>>> -igor >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> On Tue, Dec 20, 2011 at 8:54 AM, Pablo Díaz<inspd...@gmail.com> >>>>>>>>> wrote: >>>>>>>>>> >>>>>>>>>> Because when I try to write to response I get's this error: >>>>>>>>>> >>>>>>>>>> ERROR - DefaultExceptionMapper - Unexpected error occurred >>>>>>>>>> java.lang.IllegalStateException: Can't call write(CharSequence) >>>>>>>>>> after >>>>>>>>>> write(byte[]) has been called. >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.apache.wicket.protocol.http.BufferedWebResponse.write(BufferedWebResponse.java:465) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1525) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1638) >>>>>>>>>> at org.apache.wicket.Page.onRender(Page.java:904) >>>>>>>>>> at >>>>>>>>>> org.apache.wicket.markup.html.WebPage.onRender(WebPage.java:140) >>>>>>>>>> at >>>>>>>>>> org.apache.wicket.Component.internalRender(Component.java:2347) >>>>>>>>>> at org.apache.wicket.Component.render(Component.java:2275) >>>>>>>>>> at org.apache.wicket.Page.renderPage(Page.java:1035) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:105) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:224) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.apache.wicket.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:167) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:750) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:252) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:209) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:280) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:162) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:218) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) >>>>>>>>>> at org.mortbay.jetty.Server.handle(Server.java:324) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829) >>>>>>>>>> at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514) >>>>>>>>>> at >>>>>>>>>> org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) >>>>>>>>>> at >>>>>>>>>> org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395) >>>>>>>>>> at >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488) >>>>>>>>>> >>>>>>>>>> I tried to do this in serveral versions of wicket and always get >>>>>>>>>> the >>>>>>>>>> same >>>>>>>>>> error. >>>>>>>>>> >>>>>>>>>> El 20/12/11 17:15, Igor Vaynberg escribió: >>>>>>>>>> >>>>>>>>>>> why doesnt that work in wicket? >>>>>>>>>>> >>>>>>>>>>> -igor >>>>>>>>>>> >>>>>>>>>>> On Tue, Dec 20, 2011 at 12:46 AM, Pablo Díaz<inspd...@gmail.com> >>>>>>>>>>> wrote: >>>>>>>>>>>> >>>>>>>>>>>> Hi, >>>>>>>>>>>> >>>>>>>>>>>> I'm trying to do something like an internal proxy in my web-app >>>>>>>>>>>> to >>>>>>>>>>>> check >>>>>>>>>>>> permisions to connect from my portal to a mapserver server. >>>>>>>>>>>> >>>>>>>>>>>> So, I'm trying to get de request from an OpenLayers and redirect >>>>>>>>>>>> the >>>>>>>>>>>> connection throw my internal proxy (after check the roles) . >>>>>>>>>>>> I've done this before in Struts, but I don't know how do this in >>>>>>>>>>>> Wicket. >>>>>>>>>>>> In Struts is something similar to do this: >>>>>>>>>>>> >>>>>>>>>>>> HttpClient client = new HttpClient(); >>>>>>>>>>>> GetMethod method = new GetMethod(mapserverURL); >>>>>>>>>>>> >>>>>>>>>>>> method.getParams().setVersion(HttpVersion.HTTP_1_0); >>>>>>>>>>>> >>>>>>>>>>>> // Provide custom retry handler is necessary >>>>>>>>>>>> >>>>>>>>>>>> method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, >>>>>>>>>>>> new DefaultHttpMethodRetryHandler(3, false)); >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, >>>>>>>>>>>> "ISO-8859-1"); >>>>>>>>>>>> method.getParams().setCredentialCharset("ISO-8859-1"); >>>>>>>>>>>> >>>>>>>>>>>> try { >>>>>>>>>>>> // Execute the method. >>>>>>>>>>>> int statusCode = client.executeMethod(method); >>>>>>>>>>>> >>>>>>>>>>>> if (statusCode != HttpStatus.SC_OK) { >>>>>>>>>>>> System.err.println("Method failed: " + >>>>>>>>>>>> method.getStatusLine()); >>>>>>>>>>>> } >>>>>>>>>>>> >>>>>>>>>>>> InputStream input = method.getResponseBodyAsStream(); >>>>>>>>>>>> output = response.getOutputStream(); >>>>>>>>>>>> >>>>>>>>>>>> byte[] data = new byte[1]; >>>>>>>>>>>> for (;;) { >>>>>>>>>>>> >>>>>>>>>>>> if ((input.read(data)) == -1) { >>>>>>>>>>>> break; >>>>>>>>>>>> } >>>>>>>>>>>> >>>>>>>>>>>> output.write(data); >>>>>>>>>>>> >>>>>>>>>>>> } >>>>>>>>>>>> } catch (HttpException e) { >>>>>>>>>>>> System.err.println("Fatal protocol violation: " + >>>>>>>>>>>> e.getMessage()); >>>>>>>>>>>> e.printStackTrace(); >>>>>>>>>>>> return null; >>>>>>>>>>>> } catch (IOException e) { >>>>>>>>>>>> System.err.println("Fatal transport error: " + >>>>>>>>>>>> e.getMessage()); >>>>>>>>>>>> e.printStackTrace(); >>>>>>>>>>>> return null; >>>>>>>>>>>> } finally { >>>>>>>>>>>> // Release the connection. >>>>>>>>>>>> method.releaseConnection(); >>>>>>>>>>>> } >>>>>>>>>>>> return null; >>>>>>>>>>>> >>>>>>>>>>>> Can anybody help me? >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> --------------------------------------------------------------------- >>>>>>>>>>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >>>>>>>>>>>> For additional commands, e-mail: users-h...@wicket.apache.org >>>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> --------------------------------------------------------------------- >>>>>>>>>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >>>>>>>>>>> For additional commands, e-mail: users-h...@wicket.apache.org >>>>>>>>>>> >>>>>>>>>> >>>>>>>>>> --------------------------------------------------------------------- >>>>>>>>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >>>>>>>>>> For additional commands, e-mail: users-h...@wicket.apache.org >>>>>>>>>> >>>>>>>>> >>>>>>>>> --------------------------------------------------------------------- >>>>>>>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >>>>>>>>> For additional commands, e-mail: users-h...@wicket.apache.org >>>>>>>>> >>>>>>>> >>>>>>>> --------------------------------------------------------------------- >>>>>>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >>>>>>>> For additional commands, e-mail: users-h...@wicket.apache.org >>>>>>>> >>>>>>> --------------------------------------------------------------------- >>>>>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >>>>>>> For additional commands, e-mail: users-h...@wicket.apache.org >>>>>>> >>>>>> --------------------------------------------------------------------- >>>>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >>>>>> For additional commands, e-mail: users-h...@wicket.apache.org >>>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >>>>> For additional commands, e-mail: users-h...@wicket.apache.org >>>>> >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >>>> For additional commands, e-mail: users-h...@wicket.apache.org >>>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >>> For additional commands, e-mail: users-h...@wicket.apache.org >>> >> >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org