Re: Struts 2 URL parameters lost - final status
I am using Struts 2.0.6 and the jar contains struts struts-default.xml which contains the following property bean type=org.apache.struts2.dispatcher.mapper.ActionMapper name=struts class=org.apache.struts2.dispatcher.mapper.DefaultActionMapper / bean type=org.apache.struts2.dispatcher.mapper.ActionMapper name=composite class=org.apache.struts2.dispatcher.mapper.CompositeActionMapper / bean type=org.apache.struts2.dispatcher.mapper.ActionMapper name=restful class=org.apache.struts2.dispatcher.mapper.RestfulActionMapper / bean type=org.apache.struts2.dispatcher.mapper.ActionMapper name=restful2 class=org.apache.struts2.dispatcher.mapper.Restful2ActionMapper / We have a struts.xml in WEB-INF/classes folder and I was trying to override the default actionmapper by having the following lines in my struts.xml ( just for testing I am overriding with the default class itself ) bean type=org.apache.struts2.dispatcher.mapper.ActionMapper name=struts class=org.apache.struts2.dispatcher.mapper.DefaultActionMapper / But this results in an error when I started up tomcat Unable to load bean: type:org.apache.struts2.dispatcher.mapper.ActionMapper class:org.apache.struts2.dispatcher.mapper.DefaultActionMapper - bean - file:/C:/software/tomcat6/webapps/abc/WEB-INF/classes/struts.xml:17:149 Caused by: Bean type interface org.apache.struts2.dispatcher.mapper.ActionMapper with the name struts has already been loaded by [unknown location] - bean - file:/C:/software/tomcat6/webapps/abc/WEB-INF/classes/struts.xml:17:149 So the question that I have are 1) How do I override the mapping class ? 2) Why are there 4 bean declaration for actionmapper ? thanks in advance! JBL wrote: Final answer: we implemented a custom ActionMapper that handles a URL string that doesn't involve a ? to separate the query parameters. Stuck a reference to it in struts.properties: struts.mapper.class=mypackage.MyActionMapper Building a new ActionMapper isn't terribly difficult. It helps to define your expected URLs with a regular expression, then use a precompiled pattern. Ours looks something like: private static String NAMESPACE_REGEX = ...; private static String ACTION_REGEX = ...; private static String METHOD_REGEX = ...; private static String PARAMS_REGEX = ...; private static String URI_REGEX = (concatenate the four above) private static Pattern URI_PATTERN = Pattern.compile(URI_REGEX); Then, in getMapping(), pull out the URI (similar to DefaultActionMapper) and call Matcher m = URI_PATTERN.matcher(uri); If you get a match, create a new ActionMapping and set its components based on the matching groups: mapping.setNamespace(m.group(1)); mapping.setName(m.group(1)); etc. You can parse the parameter section and build a map to pass to mapping.setParams(). Using a precompiled pattern may or may not be the most efficient possible solution, but it helps you define exactly what URIs you expect. I recommend throwing a bunch of possibilities at it in your unit test code with various components present and missing. If you're a little unsure about regular expressions, build some unit tests for those, too. Sun has a decent write-up in their Java documentation: http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html Especially read the Groups and Capturing section, it's a handy tool to have in your portfolio. We may yet discover why we couldn't get query parameters, but this works for now. Good luck. -- View this message in context: http://www.nabble.com/Struts-2-URL-parameters-lost-tf4196254.html#a12160600 Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Struts 2 URL parameters lost - final final status
Turns out OC4J had a bug. They fixed it; we now have 10.1.3.3, and it works fine. /story JBL wrote: We have a link to a Struts 2 action that includes a URL parameter (.../something_method.action?name=NAME), and the URL parameter is getting lost -- it doesn't show up in the action, the request map (when we implement RequestAware), the parameter map (when we implement ParameterAware), or a custom interceptor we put at the top of the interceptor stack. -- View this message in context: http://www.nabble.com/Struts-2-URL-parameters-lost-tf4196254.html#a12075310 Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Struts 2 URL parameters lost
Final answer: we implemented a custom ActionMapper that handles a URL string that doesn't involve a ? to separate the query parameters. Stuck a reference to it in struts.properties: struts.mapper.class=mypackage.MyActionMapper Building a new ActionMapper isn't terribly difficult. It helps to define your expected URLs with a regular expression, then use a precompiled pattern. Ours looks something like: private static String NAMESPACE_REGEX = ...; private static String ACTION_REGEX = ...; private static String METHOD_REGEX = ...; private static String PARAMS_REGEX = ...; private static String URI_REGEX = (concatenate the four above) private static Pattern URI_PATTERN = Pattern.compile(URI_REGEX); Then, in getMapping(), pull out the URI (similar to DefaultActionMapper) and call Matcher m = URI_PATTERN.matcher(uri); If you get a match, create a new ActionMapping and set its components based on the matching groups: mapping.setNamespace(m.group(1)); mapping.setName(m.group(1)); etc. You can parse the parameter section and build a map to pass to mapping.setParams(). Using a precompiled pattern may or may not be the most efficient possible solution, but it helps you define exactly what URIs you expect. I recommend throwing a bunch of possibilities at it in your unit test code with various components present and missing. If you're a little unsure about regular expressions, build some unit tests for those, too. Sun has a decent write-up in their Java documentation: http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html Especially read the Groups and Capturing section, it's a handy tool to have in your portfolio. We may yet discover why we couldn't get query parameters, but this works for now. Good luck. -- View this message in context: http://www.nabble.com/Struts-2-URL-parameters-lost-tf4196254.html#a12023713 Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Struts 2 URL parameters lost
Mihel, thanks for the suggestion; my immediate response was, Why didn't I think of that? Unfortunately, nothing seems to change. The generated HTML turns out about the same in any case. Per Ian's posting, I've also tried removing the wildcard, to no effect. I'll reply again if anything turns up. Jon mihel wrote: JBL wrote: We have a link to a Struts 2 action that includes a URL parameter (.../something_method.action?name=NAME), and the URL parameter is getting lost -- it doesn't show up in the action, the request map (when we implement RequestAware), the parameter map (when we implement ParameterAware), or a custom interceptor we put at the top of the interceptor stack. Have you tried this s:url value=editGadget.action s:param name=id value=%{selected} / /s:url as described here: http://struts.apache.org/2.x/docs/url.html ? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/Struts-2-URL-parameters-lost-tf4196254.html#a11943813 Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Struts 2 URL parameters lost
Ian, thanks for the suggestion; unfortunately, it seems to produce the same result. I've trimmed it to look like: action name=something class=...SomethingAction result/WEB-INF/... .jsp/result /action (Wildcard and method backreference removed, and method name trimmed from URL in JSP.) It makes it through the execute() method, but still seems to drop the URL parameters. Per mihel's suggestions (a later response), I also tried using the s:url ... tag, which didn't seem to affect things either. The generated HTML looked about the same in any case. You mentioned the action mapper -- someplace to look for more answers? I'll reply again if anything turns up. Jon Ian Roughley wrote: Since it works for the form, but not the wildcard action mapping, it might be an issue with the action mapper. Try using a non-wildcard mapping to see if it makes a difference. /Ian JBL wrote: We have a link to a Struts 2 action that includes a URL parameter (.../something_method.action?name=NAME), and the URL parameter is getting lost -- it doesn't show up in the action, the request map (when we implement RequestAware), the parameter map (when we implement ParameterAware), or a custom interceptor we put at the top of the interceptor stack. When we submit a form to the same action with the same parameter (input type=text name=name value=NAME/), it comes through just fine for both maps (request and parameters), and ParametersInterceptor transfers the form parameter values to the action just as you'd expect. We've tried hard-coding the method name in struts.xml, figuring the wildcard processor might chop off the request parameter; no luck. As early as we can pick things out of the request cycle, the URL parameters appear to be gone. struts.xml looks like: struts package name=... namespace=... extends=struts-default ... action name=something_* class=...SomethingAction method={1} result/WEB-INF/... .jsp/result /action /package /struts We're using Struts 2.0.8. There's a similar question in the Struts 2 FAQs about the ParametersInterceptor not setting values, but the answer there turns out to be that your setter and getter have to use the same type. (See http://struts.apache.org/2.x/docs/faqs.html, in the Interceptors section.) Ian Roughley has a handy book available as a free PDF on InfoQ.com (http://www.infoq.com/minibooks/starting-struts2 - please forgive the plug); it suggests on page 23 that you should be able to see URL parameters via the ParametersInterceptor. Nothing I've seen elsewhere contradicts this, though the ParametersInterceptor page (http://struts.apache.org/2.x/docs/parameters-interceptor.html) says that it would typically be used to apply form parameters to an action. Any help would be appreciated. Thanks, Jon - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/Struts-2-URL-parameters-lost-tf4196254.html#a11943812 Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Struts 2 URL parameters lost - update (no solution yet)
An update for those interested: struts.properties defines struts.dispatcher.parametersWorkaround (false by default), and says it's for some app servers that don't handle HttpServletRequest.getParameterMap() (including mine, OC4J): http://struts.apache.org/2.x/docs/strutsproperties.html This sounds very closely related, but changing it to true didn't solve the problem. I made sure the relevant boolean flag got set and affected behavior in org.apache.struts2.Dispatcher, where the prepare(HttpServletRequest, HttpServletResponse) method executes request.getParameter(foo) if paramsWorkaroundEnabled is set. The comment: 'simply read any parameter (existing or not) to prime the request'. My guess is that this forces the request to process the ServletInputStream and build the parameter map; not sure, though. No (URL) parameters have yet appeared. Looking at the byte[] in the ServletInputStream, it's easy to find the original URL with all parameters intact, but the offset (several hundred) seems to indicate that something has already processed it. JBL wrote: We have a link to a Struts 2 action that includes a URL parameter (.../something_method.action?name=NAME), and the URL parameter is getting lost -- it doesn't show up in the action, the request map (when we implement RequestAware), the parameter map (when we implement ParameterAware), or a custom interceptor we put at the top of the interceptor stack. When we submit a form to the same action with the same parameter (input type=text name=name value=NAME/), it comes through just fine for both maps (request and parameters), and ParametersInterceptor transfers the form parameter values to the action just as you'd expect. We've tried hard-coding the method name in struts.xml, figuring the wildcard processor might chop off the request parameter; no luck. As early as we can pick things out of the request cycle, the URL parameters appear to be gone. struts.xml looks like: struts package name=... namespace=... extends=struts-default ... action name=something_* class=...SomethingAction method={1} result/WEB-INF/... .jsp/result /action /package /struts We're using Struts 2.0.8. There's a similar question in the Struts 2 FAQs about the ParametersInterceptor not setting values, but the answer there turns out to be that your setter and getter have to use the same type. (See http://struts.apache.org/2.x/docs/faqs.html, in the Interceptors section.) Ian Roughley has a handy book available as a free PDF on InfoQ.com (http://www.infoq.com/minibooks/starting-struts2 - please forgive the plug); it suggests on page 23 that you should be able to see URL parameters via the ParametersInterceptor. Nothing I've seen elsewhere contradicts this, though the ParametersInterceptor page (http://struts.apache.org/2.x/docs/parameters-interceptor.html) says that it would typically be used to apply form parameters to an action. Any help would be appreciated. Thanks, Jon -- View this message in context: http://www.nabble.com/Struts-2-URL-parameters-lost-tf4196254.html#a11953312 Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Struts 2 URL parameters lost
JBL wrote: We have a link to a Struts 2 action that includes a URL parameter (.../something_method.action?name=NAME), and the URL parameter is getting lost -- it doesn't show up in the action, the request map (when we implement RequestAware), the parameter map (when we implement ParameterAware), or a custom interceptor we put at the top of the interceptor stack. Have you tried this s:url value=editGadget.action s:param name=id value=%{selected} / /s:url as described here: http://struts.apache.org/2.x/docs/url.html ? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Struts 2 URL parameters lost
Since it works for the form, but not the wildcard action mapping, it might be an issue with the action mapper. Try using a non-wildcard mapping to see if it makes a difference. /Ian JBL wrote: We have a link to a Struts 2 action that includes a URL parameter (.../something_method.action?name=NAME), and the URL parameter is getting lost -- it doesn't show up in the action, the request map (when we implement RequestAware), the parameter map (when we implement ParameterAware), or a custom interceptor we put at the top of the interceptor stack. When we submit a form to the same action with the same parameter (input type=text name=name value=NAME/), it comes through just fine for both maps (request and parameters), and ParametersInterceptor transfers the form parameter values to the action just as you'd expect. We've tried hard-coding the method name in struts.xml, figuring the wildcard processor might chop off the request parameter; no luck. As early as we can pick things out of the request cycle, the URL parameters appear to be gone. struts.xml looks like: struts package name=... namespace=... extends=struts-default ... action name=something_* class=...SomethingAction method={1} result/WEB-INF/... .jsp/result /action /package /struts We're using Struts 2.0.8. There's a similar question in the Struts 2 FAQs about the ParametersInterceptor not setting values, but the answer there turns out to be that your setter and getter have to use the same type. (See http://struts.apache.org/2.x/docs/faqs.html, in the Interceptors section.) Ian Roughley has a handy book available as a free PDF on InfoQ.com (http://www.infoq.com/minibooks/starting-struts2 - please forgive the plug); it suggests on page 23 that you should be able to see URL parameters via the ParametersInterceptor. Nothing I've seen elsewhere contradicts this, though the ParametersInterceptor page (http://struts.apache.org/2.x/docs/parameters-interceptor.html) says that it would typically be used to apply form parameters to an action. Any help would be appreciated. Thanks, Jon - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]