You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by Jacques Le Roux <ja...@les7arts.com> on 2012/10/01 07:41:55 UTC

Re: svn commit: r1391037 - in /ofbiz/trunk/framework: common/config/ webapp/src/org/ofbiz/webapp/control/

No because we need to take the hand on it. If we define a request of type none the RequestHandler will handle it and will end doing 
nothing.
Also we need to be able to define many external requests in a controller, sometimes for the same request-map.

Jacques

From: "Scott Gray" <sc...@hotwaxmedia.com>
> Couldn't you just define a default-request in the controller that points to a request uri which does nothing?  i.e. no event and a 
> response type of "none"
>
> Regards
> Scott
>
> On 28/09/2012, at 7:33 PM, Jacques Le Roux wrote:
>
>>> we talking about two servlets mapped to the same path?
>>
>> Actually not the same <servlet-mapping> than control  which is
>> <url-pattern>/control/*</url-pattern>
>>
>> The external one is
>> <url-pattern>/*</url-pattern>
>> There is a proper filter for external mapping
>>
>> They use both
>> <load-on-startup>1</load-on-startup>
>>
>> It's a bit like CatalogUrlServlet in eCommerce web.xml
>>
>> Not directly related but we also use Tuckey. So yes it's about Servlets
>>
>> Jacques
>>
>> From: "Scott Gray" <sc...@hotwaxmedia.com>
>>> I'm equally confused and the jira hasn't helped much.  Could someone define an "external request in controllers" for me?
>>>
>>> Typically if you want flexible request handling on the control path you use the <default-request/> element to point to a uri 
>>> that
>>> will handle the request within an event.
>>>
>>> I'm not sure I understand what type of setup would work when the ControlServlet/RequestHandler can't find something to render, 
>>> are
>>> we talking about two servlets mapped to the same path?
>>>
>>> Thanks
>>> Scott
>>>
>>> On 28/09/2012, at 9:58 AM, Adrian Crum wrote:
>>>
>>>> I'm confused. I want to have external requests and I want to throw exceptions when I have missing controller entries. How does
>>>> this change accommodate that?
>>>>
>>>> -Adrian
>>>>
>>>>
>>>> On 9/27/2012 3:49 PM, jleroux@apache.org wrote:
>>>>> Author: jleroux
>>>>> Date: Thu Sep 27 14:49:20 2012
>>>>> New Revision: 1391037
>>>>>
>>>>> URL: http://svn.apache.org/viewvc?rev=1391037&view=rev
>>>>> Log:
>>>>> Closes "ControlServlet - Exception thrown for requests not defined by controller.xml"
>>>>> https://issues.apache.org/jira/browse/OFBIZ-5037
>>>>>
>>>>> This has been tested in a custom project and work as expected it does not add any functional features for OFBiz if you don't 
>>>>> use
>>>>> external requests in controllers. So should have any impacts OOTB
>>>>>
>>>>> Added:
>>>>>    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandlerExceptionAllowExternalRequests.java   (with props)
>>>>> Modified:
>>>>>    ofbiz/trunk/framework/common/config/general.properties
>>>>>    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java
>>>>>    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
>>>>>
>>>>> Modified: ofbiz/trunk/framework/common/config/general.properties
>>>>> URL:
>>>>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/config/general.properties?rev=1391037&r1=1391036&r2=1391037&view=diff
>>>>> ==============================================================================
>>>>> --- ofbiz/trunk/framework/common/config/general.properties (original)
>>>>> +++ ofbiz/trunk/framework/common/config/general.properties Thu Sep 27 14:49:20 2012
>>>>> @@ -143,3 +143,6 @@ multitenant=N
>>>>> # -- Y if you use a cluster. Most of the time this should not be needed. Setting distributed-cache-clear-enabled="true" is
>>>>> enough
>>>>> # -- to guarantee no sequenceIds duplicates. See OFBIZ-2353 for details
>>>>> cluster=N
>>>>> +
>>>>> +# -- N if you want to use external requests (not in available in current controller), see OFBIZ-5037
>>>>> +throwRequestHandlerExceptionOnMissingLocalRequest=Y
>>>>> \ No newline at end of file
>>>>>
>>>>> Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java
>>>>> URL:
>>>>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java?rev=1391037&r1=1391036&r2=1391037&view=diff
>>>>> ==============================================================================
>>>>> --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java (original)
>>>>> +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java Thu Sep 27 14:49:20 2012
>>>>> @@ -225,6 +225,9 @@ public class ControlServlet extends Http
>>>>>                 request.setAttribute("_ERROR_MESSAGE_", encoder.encode(throwable.toString()));
>>>>>                 errorPage = requestHandler.getDefaultErrorPage(request);
>>>>>             }
>>>>> +         } catch (RequestHandlerExceptionAllowExternalRequests e) {
>>>>> +              errorPage = requestHandler.getDefaultErrorPage(request);
>>>>> +              Debug.logInfo("Going to external page: " + request.getPathInfo(), module);
>>>>>         } catch (Exception e) {
>>>>>             Debug.logError(e, "Error in request handler: ", module);
>>>>>             StringUtil.HtmlEncoder encoder = new StringUtil.HtmlEncoder();
>>>>>
>>>>> Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
>>>>> URL:
>>>>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java?rev=1391037&r1=1391036&r2=1391037&view=diff
>>>>> ==============================================================================
>>>>> --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java (original)
>>>>> +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java Thu Sep 27 14:49:20 2012
>>>>> @@ -65,6 +65,8 @@ import org.ofbiz.webapp.website.WebSiteW
>>>>> public class RequestHandler {
>>>>>       public static final String module = RequestHandler.class.getName();
>>>>> +    private static final Boolean THROW_REQUEST_HANDLER_EXCEPTION_ON_MISSING_LOCAL_REQUEST =
>>>>> +        UtilProperties.propertyValueEqualsIgnoreCase("general.properties", 
>>>>> "throwRequestHandlerExceptionOnMissingLocalRequest",
>>>>> "Y");
>>>>>       public static RequestHandler getRequestHandler(ServletContext servletContext) {
>>>>>         RequestHandler rh = (RequestHandler) servletContext.getAttribute("_REQUEST_HANDLER_");
>>>>> @@ -96,7 +98,7 @@ public class RequestHandler {
>>>>>         return ConfigXMLReader.getControllerConfig(this.controllerConfigURL);
>>>>>     }
>>>>> -    public void doRequest(HttpServletRequest request, HttpServletResponse response, String requestUri) throws
>>>>> RequestHandlerException {
>>>>> +    public void doRequest(HttpServletRequest request, HttpServletResponse response, String requestUri) throws
>>>>> RequestHandlerException, RequestHandlerExceptionAllowExternalRequests {
>>>>>         HttpSession session = request.getSession();
>>>>>         Delegator delegator = (Delegator) request.getAttribute("delegator");
>>>>>         GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
>>>>> @@ -104,7 +106,7 @@ public class RequestHandler {
>>>>>     }
>>>>>       public void doRequest(HttpServletRequest request, HttpServletResponse response, String chain,
>>>>> -            GenericValue userLogin, Delegator delegator) throws RequestHandlerException {
>>>>> +            GenericValue userLogin, Delegator delegator) throws RequestHandlerException,
>>>>> RequestHandlerExceptionAllowExternalRequests {
>>>>>           long startTime = System.currentTimeMillis();
>>>>>         HttpSession session = request.getSession();
>>>>> @@ -152,10 +154,13 @@ public class RequestHandler {
>>>>>             }
>>>>>         }
>>>>> -        // still not found so stop
>>>>> +        // if no matching request is found in the controller, depending on
>>>>> THROW_REQUEST_HANDLER_EXCEPTION_ON_MISSING_LOCAL_REQUEST
>>>>> +        //  we throw a RequestHandlerException or RequestHandlerExceptionAllowExternalRequests
>>>>>         if (requestMap == null) {
>>>>> -            throw new RequestHandlerException(requestMissingErrorMessage);
>>>>> -        }
>>>>> +            if (THROW_REQUEST_HANDLER_EXCEPTION_ON_MISSING_LOCAL_REQUEST) throw new
>>>>> RequestHandlerException(requestMissingErrorMessage);
>>>>> +            else throw new RequestHandlerExceptionAllowExternalRequests();
>>>>> +         }
>>>>> +
>>>>>         String eventReturn = null;
>>>>>         if (requestMap.metrics != null && requestMap.metrics.getThreshold() != 0.0 && requestMap.metrics.getTotalEvents() > 3
>>>>> && requestMap.metrics.getThreshold() < requestMap.metrics.getServiceRate()) {
>>>>>             eventReturn = "threshold-exceeded";
>>>>>
>>>>> Added: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandlerExceptionAllowExternalRequests.java
>>>>> URL:
>>>>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandlerExceptionAllowExternalRequests.java?rev=1391037&view=auto
>>>>> ==============================================================================
>>>>> --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandlerExceptionAllowExternalRequests.java (added)
>>>>> +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandlerExceptionAllowExternalRequests.java Thu Sep 27
>>>>> 14:49:20 2012
>>>>> @@ -0,0 +1,39 @@
>>>>> +/*******************************************************************************
>>>>> + * Licensed to the Apache Software Foundation (ASF) under one
>>>>> + * or more contributor license agreements.  See the NOTICE file
>>>>> + * distributed with this work for additional information
>>>>> + * regarding copyright ownership.  The ASF licenses this file
>>>>> + * to you under the Apache License, Version 2.0 (the
>>>>> + * "License"); you may not use this file except in compliance
>>>>> + * with the License.  You may obtain a copy of the License at
>>>>> + *
>>>>> + * http://www.apache.org/licenses/LICENSE-2.0
>>>>> + *
>>>>> + * Unless required by applicable law or agreed to in writing,
>>>>> + * software distributed under the License is distributed on an
>>>>> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>>>>> + * KIND, either express or implied.  See the License for the
>>>>> + * specific language governing permissions and limitations
>>>>> + * under the License.
>>>>> + *******************************************************************************/
>>>>> +package org.ofbiz.webapp.control;
>>>>> +
>>>>> +/**
>>>>> + * RequestHandlerExceptionAllowExternalRequests
>>>>> + */
>>>>> +@SuppressWarnings("serial")
>>>>> +public class RequestHandlerExceptionAllowExternalRequests extends org.ofbiz.base.util.GeneralException {
>>>>> +
>>>>> +    public RequestHandlerExceptionAllowExternalRequests(String str, Throwable t) {
>>>>> +        super(str, t);
>>>>> +    }
>>>>> +
>>>>> +    public RequestHandlerExceptionAllowExternalRequests(String str) {
>>>>> +        super(str);
>>>>> +    }
>>>>> +
>>>>> +    public RequestHandlerExceptionAllowExternalRequests() {
>>>>> +        super();
>>>>> +    }
>>>>> +}
>>>>> +
>>>>>
>>>>> Propchange: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandlerExceptionAllowExternalRequests.java
>>>>> ------------------------------------------------------------------------------
>>>>>    svn:eol-style = native
>>>>>
>>>>> Propchange: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandlerExceptionAllowExternalRequests.java
>>>>> ------------------------------------------------------------------------------
>>>>>    svn:keywords = Date Rev Author URL Id
>>>>>
>>>>> Propchange: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandlerExceptionAllowExternalRequests.java
>>>>> ------------------------------------------------------------------------------
>>>>>    svn:mime-type = text/plain
>>>>>
>>>>>
>>>>
>>>
>>>
>
>