Re: UrlResourceReference for images
Relative is not good because resources are served from different application, just currently both applications are deployed on same tomcat so they have urls http://localhost:8080/app1 and http://localhost:8080/app2. When smart wicket renders image src i get something like this: app2/image?item=123amp;id=1 so it thinks this is url of my main application (app1), but its not. When i modify with firebug to use full http://localhost:8080/app2 it works fine. So only solution is to override UrlRenderer? That would mean I would have to override also RequestCycle? Just for such simple case? Maybe there is simpler solution? -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/UrlResourceReference-for-images-tp4659261p4659271.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: UrlResourceReference for images
What you're saying is that a client requests the url http://localhost:8080/app1 and the img src attribute has app2/image?item-123 but you want it to be http://localhost:8080/app2/image?item-123 instead? Why does it make a difference? The relative url will be resolved to http://localhost:8080/app2/image?item-123 so it's actually the very same path. Check out the net tab in Firebug and you'll see it. When and if the image url changes to another Tomcat instance, Wicket will render it in full as required. Just change the UrlResourceReference to http://localhost:8081/app2 (the http:// is necessary I believe) to see it in action. On 07/06/2013 7:27 AM, bronius wrote: Relative is not good because resources are served from different application, just currently both applications are deployed on same tomcat so they have urls http://localhost:8080/app1 and http://localhost:8080/app2. When smart wicket renders image src i get something like this: app2/image?item=123amp;id=1 so it thinks this is url of my main application (app1), but its not. When i modify with firebug to use full http://localhost:8080/app2 it works fine. So only solution is to override UrlRenderer? That would mean I would have to override also RequestCycle? Just for such simple case? Maybe there is simpler solution? -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/UrlResourceReference-for-images-tp4659261p4659271.html Sent from the Users forum mailing list archive at Nabble.com. - 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
Re: UrlResourceReference for images
Yes that would be great, but src=app2/image?item-123 does not work (image is not loaded) and after changing it with firebug to src=http://localhost:8080/app2/image?item-123; works fine. Any ideas why is that? Any stupid mistake i overlooked? Maybe wicket interprets relative url as http://localhost:8080/app1/app2/image?item-123 somehow? Maybe because when i build url I put app2 as segment? (url.getSegments().add(app2);) I will try different way to construct url later. Thanks for help appreciate it :) -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/UrlResourceReference-for-images-tp4659261p4659279.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: UrlResourceReference for images
Try this: url.getSegments().add(); url.getSegments().add(site2); url.getSegments().add(image); Have a look at the code of Url#isAbsolute(). It checks if the first segment is empty which is not the case with the code you provided in the first email. This behavior of the segments array is definitely not intuitive... Another solution would be this: url = Url.parse(http://localhost:8080/;); url.getSegments().add(site2); url.getSegments().add(image); url.setQueryParameter(param1, 1); url.setQueryParameter(param2, 2); This creates the first empty segment automatically. On 07/06/2013 10:43 AM, bronius wrote: Yes that would be great, but src=app2/image?item-123 does not work (image is not loaded) and after changing it with firebug to src=http://localhost:8080/app2/image?item-123; works fine. Any ideas why is that? Any stupid mistake i overlooked? Maybe wicket interprets relative url as http://localhost:8080/app1/app2/image?item-123 somehow? Maybe because when i build url I put app2 as segment? (url.getSegments().add(app2);) I will try different way to construct url later. Thanks for help appreciate it :) -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/UrlResourceReference-for-images-tp4659261p4659279.html Sent from the Users forum mailing list archive at Nabble.com. - 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
Re: UrlResourceReference for images
If you have src=app2/image?item-123 in a resource located in http://localhost:8080/app1/, it will be resolved as http://localhost:8080/app1/app2/image?item-123 as you noticed. Adding / to the beginning should help: src=/app2/image?item-123 should be resolved as http://localhost:8080/app2/image?item-123. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/UrlResourceReference-for-images-tp4659261p4659281.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: UrlResourceReference for images
Hi, I just tried it and it worked! Thanks guys for help, this situation really surprised me :) On the bright side at least I learned about framework when solving this little problem of mine as its easy to go inside and check how it works (im quite new to wicket). Best regards! -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/UrlResourceReference-for-images-tp4659261p4659283.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: UrlResourceReference for images
Hello, See inline. On 06/06/2013 5:27 PM, bronius wrote: First of all Url api is extremely hard to work with, very hard to create url i need, I think there should be some option to simply create it with simple string. Anyway Url.parse method does not create full url for me (i have localhost:8080/site1 and localhost:8080/site2, but when url is created i get only site2 without full address). So I tried it myself like this: private Url createUrl(Charset charset) { Url url = new Url(charset) { private static final long serialVersionUID = 1L; @Override public String toString(final Charset charset) { return toString(StringMode.FULL, charset); } }; url.setProtocol(http); url.setHost(localhost); url.setPort(8080); url.getSegments().add(site2); url.getSegments().add(image); url.setQueryParameter(param1, 1); url.setQueryParameter(param2, 2); return url; } The key here as you probably noticed is StringMode.FULL passed to the toString method. The Url class stores separately the protocol, host name, port and path (the segments array) of a Url. Either way, toString is only used to build a resource key name in the constructor of UrlResourceReference. The actual url is still used in full by UrlResourceReference. However, see below. Not really nice, but at least Url object returned normal full url that i needed in toString. However UrlResourceReference still rendered not full url and thats where i got too pissed off and decided I need some rest :) I'm just interested if I'm even on the right track? How you would implement it? And why this simple thing is so complicated? :) I admit I was a bit drunk :) and don't have that much of experience with wicket, but this part looked really strange for me. But I suspect I'm missing something. The problem is probably because both applications have same start (http://localhost:8080) and wicket is too smart. As image from other random website is shown successfully. You are right. In a way, Wicket is too smart. Here is the code of interest from org.apache.wicket.request.UrlRenderer: protected boolean shouldRenderAsFull(final Url url) { Url clientUrl = request.getClientUrl(); if (!Strings.isEmpty(url.getProtocol()) !url.getProtocol().equals(clientUrl.getProtocol())) { return true; } if (!Strings.isEmpty(url.getHost()) !url.getHost().equals(clientUrl.getHost())) { return true; } if ((url.getPort() != null) !url.getPort().equals(clientUrl.getPort())) { return true; } if (url.isContextAbsolute()) { // do not relativize urls like /a/b return true; } return false; } What I don't understand however is why this relative url is not good for you. You talked about serving resources from another server, but I don't get it. Either a relative url or an absolute url would both point to the same resource when interpreted on the client. Regards, Bertrand - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org