Registering sling servlet for resource
Hi, I am trying to register a servlet for resource type, and its not working. It works just fine if I register for path. 1. I have a component (JSP) in CQ as /test/login 2. I am having form as following form method=POST action=%=resource.getPath() %.html input name=someField type=text input type=submit value=submit/input /form 3. I have a servlet registerd to handle POST request. The servlet is registered for resource type as follows /* @scr.property name=sling.servlet.resourceTypes value=test/login*/ I expect that when the form is submitted, the servlet registered for that resource type should be invoked. But its not working. Am I missing something here? Thanks, Unmesh
Re: Registering sling servlet for resource
On 13.02.11 20:00, Unmesh Joshi unmeshjo...@gmail.com wrote: /* @scr.property name=sling.servlet.resourceTypes value=test/login*/ If this is the complete javadoc annotations for the servlet class, then the following is missing: - @scr.component / @scr.service marking it as a component and service (providing an implementation for the javax.servlet.Servlet interface) - setting the property sling.servlet.methods to handle POST requests (by default, I think it will only be called for GET requests) Hence you probably need: /** * @scr.component metatype=false * @scr.service * @scr.property name=sling.servlet.resourceTypes value=test/login * @scr.property name=sling.servlet.methods value=POST */ Regards, Alex -- Alexander Klimetschek Developer // Adobe (Day) // Berlin - Basel
Re: Registering sling servlet for resource
Thanks!. Adding /*@scr.property name=sling.servlet.methods value=POST*/ did the trick. On Mon, Feb 14, 2011 at 1:43 AM, Alexander Klimetschek aklim...@adobe.com wrote: On 13.02.11 20:00, Unmesh Joshi unmeshjo...@gmail.com wrote: /* @scr.property name=sling.servlet.resourceTypes value=test/login*/ If this is the complete javadoc annotations for the servlet class, then the following is missing: - @scr.component / @scr.service marking it as a component and service (providing an implementation for the javax.servlet.Servlet interface) - setting the property sling.servlet.methods to handle POST requests (by default, I think it will only be called for GET requests) Hence you probably need: /** * @scr.component metatype=false * @scr.service * @scr.property name=sling.servlet.resourceTypes value=test/login * @scr.property name=sling.servlet.methods value=POST */ Regards, Alex -- Alexander Klimetschek Developer // Adobe (Day) // Berlin - Basel
Using ResourceProviders or Servlets for handling GET requests
Hi, In Sling, we can Servlets are written for handling POST request. (Even JSPs and other scripts can be used, but I will like to stick to Servlets) For GET requests, either Servlets or ResourceProviders can be used. What is the common idiom or good design practice? ResourceProviders or Servlets? Thanks, Unmesh
Re: Using ResourceProviders or Servlets for handling GET requests
ResourceProviders and Servlets do completely different things. ResourceProviders provide resources. Servlets produce representations of resources. Justin On Feb 13, 2011, at 4:23 PM, Unmesh Joshi unmeshjo...@gmail.com wrote: Hi, In Sling, we can Servlets are written for handling POST request. (Even JSPs and other scripts can be used, but I will like to stick to Servlets) For GET requests, either Servlets or ResourceProviders can be used. What is the common idiom or good design practice? ResourceProviders or Servlets? Thanks, Unmesh
Re: Using ResourceProviders or Servlets for handling GET requests
So If I have a content page, say /content/mysite/accounts.html. And I want to handle GET request for this, there are following options. 1. If I have a template/component backing accounts.html, which is JSP, I can call a service in JSP scriptlet So, the sequence is GET /content/mysite/accounts.html accounts.html == accounts.jsp (component) account.jsp == % AccountService service = sling.getService(AccountService.class) % Display account details. 2. If I do not want GET request to directly go to JSP, I will write a servlet for handling GET request under path say /mysite/accounts GET /mysite/accounts/ SlingServlet for handling Populate account object in session forward request to /content/mysite/accounts.html 3. Instead of servlet, write a ResourceProvider for path /mysite/accounts GET /mysite/accounts ResourceProvider builds AccountSummary resource How does this wire back to JSP component?? Which of the above options is generally used? I want to avoid option 1. Thanks, Unmesh On Mon, Feb 14, 2011 at 4:55 AM, Justin Edelson jus...@justinedelson.com wrote: ResourceProviders and Servlets do completely different things. ResourceProviders provide resources. Servlets produce representations of resources. Justin On Feb 13, 2011, at 4:23 PM, Unmesh Joshi unmeshjo...@gmail.com wrote: Hi, In Sling, we can Servlets are written for handling POST request. (Even JSPs and other scripts can be used, but I will like to stick to Servlets) For GET requests, either Servlets or ResourceProviders can be used. What is the common idiom or good design practice? ResourceProviders or Servlets? Thanks, Unmesh
Re: Problems deploying to a servlet container
On Mon, Feb 14, 2011 at 2:45 AM, Justin Edelson jus...@justinedelson.com wrote: On Sat, Feb 12, 2011 at 7:25 PM, Nicolai Willems niwi...@gmail.com wrote: On Sun, Feb 13, 2011 at 12:11 AM, Justin Edelson jus...@justinedelson.com wrote: On Feb 12, 2011, at 5:06 PM, Nicolai Willems niwi...@gmail.com wrote: On Sat, Feb 12, 2011 at 10:22 PM, Justin Edelson justinedel...@gmail.com wrote: On 2/12/11 4:16 PM, Nicolai Willems wrote: On Sat, Feb 12, 2011 at 10:07 PM, Justin Edelson justinedel...@gmail.com mailto:justinedel...@gmail.com wrote: You have a few options: 1) Set a system property sling.home.prefix to /var/lib/sling - this will make sling home /var/lib/sling/_context path (e.g. /var/lib/sling/_todoer) For future reference - this would on a linux box be export sling.home=your/fancy/path right? I am on my way to editing to installing to servlet container wiki entry - so this would be nice info. No. export is an environment variable. A system property is usually set by passing -Dname=value to the JVM. How you do this on a particular servlet container is container-specific, but there usually is an environment variable you can set. Something like this: export JAVA_ARGS=-Dsling.home=/your/fancy/path Google set system property container name for specific instructions. I know your/fancy/path isn't meant to be serious, but worth noting: if you put a relative path here, it will be relative from the container's home directory which is exactly what you are trying to avoid IIUC. Ahh, my bad - I meant it to be absolute. But I'll note that when updating the page. Something like, If setting this property should be effective you should use an absolute path Well, a relative path would still be_effective_ :) 2) Edit the WAR file and set either a servlet init param or a context param called sling.home. The value of this parameter will be used directly, i.e. not have the context path appended to it. I used sort of this approach, I changed the init-param for the servlet in web.xml. Now running nice and smooth. Just be sure if you happen to run multiple Sling webapps in the one container that you have a different parameter value for each webapp. This is an edge case, but is the point of having the context path part of the path when you use either the default or the system property technique (as system properties are obviously shared across all webapps in a single JVM). Would using a path like /var/lib/sling/${context.path} resolve the above issue? So in the tomcat example you would do export JAVA_OPTS=/var/lib/sling/${context.path}. Sling does this for you. If you set the system property sling.home.prefix to /var/lib/sling, the actual sling.home directory will be that prefix _plus_ the context path. If you set sling.home in web.xml, the context path is not appended. Note the difference in names: sling.home.prefix vs. sling.home I'm sorry to report this - but setting JAVA_OPTS as described here: http://wiki.apache.org/tomcat/FAQ/Miscellaneous#Q5 adding -Dsling.home.prefix=/var/lib/sling/ dosen't do the trick for me. Any suggestions? What *exactly* are you doing and what specifically is going wrong? Sorry for not updating this issue. But I found that it's tomcat/ubuntu that dosen't accept JAVA_OPTS, I think they would like to have CATALINA_OPTS instead. So looking at ps aux | grep tomcat showed that every time I changed JAVA_OPTS nothing happened. So now I fiddled with the init-script, and it works like a charm. Thanks for your help all the way. Shortly I'll be writing a little article about it. I tried this scenario and saw the expected result: * unpacked Tomcat 6.0.29 and did this: export JAVA_OPTS=-Dsling.home.prefix=/var/lib/sling ran /usr/local/apache-tomcat-6.0.29/bin/startup.sh Then I deployed a recent build of the Sling WAR using context path /slingtomcat The Tomcat log then showed this: Feb 13, 2011 8:41:42 PM org.apache.catalina.core.ApplicationContext log INFO: sling: Setting sling.home=/var/lib/sling/_slingtomcat (servlet context path) Which is the expected result. Justin Justin Again - thanks for the quick reply. This mailing list is so good! We try :) Justin Regardless of the method, you should see a log message in the servlet container's log like this: Setting sling.home=sling home (source) where source should tell you how sling home was set. HTH, Justin On 2/12/11 3:44 PM, Nicolai Willems wrote: Hello When deploying to tomcat 6 under Ubuntu, sling wont start up. In the logs it tells me that it is unable to create the directory sling/_todoer - inspecting the path, I found that sling is trying to create a directory directly under my tomcat root var/lib/tomcat6. This seems like undesirable behavior. Is there some
Re: request.getCharacterEncoding() always returns ISO-8859-1
Hi Vidar, Thank you for the suggestion. I will try it. Now I found that request filters are described here http://sling.apache.org/site/filters.html Best regards, Peter On Fri, Feb 11, 2011 at 3:27 PM, Vidar Ramdal-2 [via Apache Sling] ml-node+2473494-998661287-5...@n3.nabble.com wrote: On Thu, Feb 10, 2011 at 11:56 PM, Peter Dotchev [hidden email]http://user/SendEmail.jtp?type=nodenode=2473494i=0 wrote: Hi, Recently http://dotev.blogspot.com/2011/02/posting-non-ascii-characters-in-web.html I stumbled over this issue too. I don't want to add _charset_ input to all the forms. Is there a way to set the request encoding to UTF-8? IMHO it would be better if the request encoding is configurable like it is done in Wicket. http://wiki.apache.org/tomcat/FAQ/CharacterEncoding Tomcat FAQ suggests using a filter. How can I do that in Sling? Hi, you can implement the javax.servlet.Filter interface and register your implementation as a Filter service: @Component(immediate = true) @Properties({ @Property(name = filter.scope, value = request, propertyPrivate = true), @Property(name = filter.order, value = -9, propertyPrivate = true) }) @Services({@Service(javax.servlet.Filter.class)}) public class YourFilter implements javax.servlet.Filter { ... } -- Vidar S. Ramdal [hidden email]http://user/SendEmail.jtp?type=nodenode=2473494i=1 - http://www.idium.no Sommerrogata 13-15, N-0255 Oslo, Norway + 47 22 00 84 00 Quando omni flunkus moritatus! -- If you reply to this email, your message will be added to the discussion below: http://apache-sling.73963.n3.nabble.com/request-getCharacterEncoding-always-returns-ISO-8859-1-tp1740512p2473494.html To unsubscribe from request.getCharacterEncoding() always returns ISO-8859-1, click herehttp://apache-sling.73963.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=1740512code=ZG90Y2hldkBnbWFpbC5jb218MTc0MDUxMnwtMTcyMjY3ODE2NA==. -- View this message in context: http://apache-sling.73963.n3.nabble.com/request-getCharacterEncoding-always-returns-ISO-8859-1-tp1740512p2474201.html Sent from the Sling - Users mailing list archive at Nabble.com.