That chunk of code is for compensating for a very specific use case.

One where the request path matches the declared contextPath exactly, is not
a root context, and you don't allow null pathInfo values.

See:
http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/server/handler/ContextHandler.html#setAllowNullPathInfo(boolean)
Default value for allowNullPathInfo is false.
(Internal jetty handlers like MovedContextHandler actually set this to true)

Example 1:

  ContextHandler : contextPath = "/foo"
  Request           : path = "/foo"

Without that logic, this would result in a request.getPathInfo() of null.
Which is allowed per the servlet spec, but a shocking number of libraries
choke on.
That logic redirects the incoming request to "/foo/", which forces the
pathInfo to be "/"
Since allowNullPathInfo is internally defaulting to false, this redirect
will always happen in this limited usecase for all servlet spec requests.

Example 2:

  ContextHandler : contextPath = "/foo"
  Request           : path = "/foo/index.bar"

This request path is not the same as the declared contextPath so it would
not redirect.
This is the use case for your initial question too.



--
Joakim Erdfelt <[email protected]>
webtide.com <http://www.webtide.com/> - intalio.com/jetty
Expert advice, services and support from from the Jetty & CometD experts
eclipse.org/jetty - cometd.org

On Mon, Sep 22, 2014 at 1:50 PM, Dunn, Barclay <[email protected]>
wrote:

>  Oops! Below I wrote ContextServer but I meant ContextHandler. Just
> confirming it's not ContextHandler doing this:
>
>              // context request must end with /
>             baseRequest.setHandled(true);
>             if (baseRequest.getQueryString() != null)
>
> response.sendRedirect(URIUtil.addPaths(baseRequest.getRequestURI(),URIUtil.SLASH)
> + "?" + baseRequest.getQueryString());
>             else
>
> response.sendRedirect(URIUtil.addPaths(baseRequest.getRequestURI(),URIUtil.SLASH));
>             return false;
>
>  (that is from jetty-server-9.2.2.v20140723,
> ContextHandler.checkContext(), lines 948-951)
>
>  A look at the URIUtil.addPaths() code suggests I would see a / after the
> .do, if this were happening, and I am not, but I would appreciate someone
> more familiar with the Jetty code to confirm.
>
>  Barclay
>
>
>   From: Joakim Erdfelt <[email protected]>
> Reply-To: JETTY user mailing list <[email protected]>
> Date: Monday, September 22, 2014 at 3:48 PM
> To: JETTY user mailing list <[email protected]>
> Subject: Re: [jetty-users] 302 Redirect loop prevents user from reaching
> login success page
>
>   Your pasted jetty configuration shows no jetty specific redirect
> implementation.
>
>  Perhaps its the library you are using in your webapp causing this
> redirect loop.
> Based on the "action.do", I'd assume you have struts in use.
>
>  You should look into the struts library and its configuration to see how
> it does its redirect logic.
>
>
>  --
> Joakim Erdfelt <[email protected]>
> webtide.com
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__www.webtide.com_&d=AAMFaQ&c=r30hyXAdWe8oret4PlAIyA&r=SBmXB9sPseJz0sZ0KIFqDD2Nqm1s7mFZpe0jYV7fDI4&m=L4XtH2v6zDkT3_7iT236vzssP8dH2eZnLdRB8KKzAuM&s=-V_EzCSShfWW3PFd25RtOmIjlagZfekrDQgwX99uExM&e=>
>  -
> intalio.com/jetty
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__intalio.com_jetty&d=AAMFaQ&c=r30hyXAdWe8oret4PlAIyA&r=SBmXB9sPseJz0sZ0KIFqDD2Nqm1s7mFZpe0jYV7fDI4&m=L4XtH2v6zDkT3_7iT236vzssP8dH2eZnLdRB8KKzAuM&s=scTZnGmPHXfxj7esD7mph4dJUO82xT2NWsf_1xckQqk&e=>
> Expert advice, services and support from from the Jetty & CometD experts
> eclipse.org/jetty
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__eclipse.org_jetty_&d=AAMFaQ&c=r30hyXAdWe8oret4PlAIyA&r=SBmXB9sPseJz0sZ0KIFqDD2Nqm1s7mFZpe0jYV7fDI4&m=L4XtH2v6zDkT3_7iT236vzssP8dH2eZnLdRB8KKzAuM&s=FYdTNFuVuUzE4GG_FmMIpbkS_Hnl6pksDLwL-ycd4yQ&e=>
>  - cometd.org
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__cometd.org_&d=AAMFaQ&c=r30hyXAdWe8oret4PlAIyA&r=SBmXB9sPseJz0sZ0KIFqDD2Nqm1s7mFZpe0jYV7fDI4&m=L4XtH2v6zDkT3_7iT236vzssP8dH2eZnLdRB8KKzAuM&s=VHfXWbMioCb8_82gq1jzYkSCtVdEyVT4BAmmvyXK3mg&e=>
>
> On Mon, Sep 22, 2014 at 11:26 AM, Dunn, Barclay <[email protected]>
> wrote:
>
>>  Hi list,
>>
>>  I am having an issue with embedded Jetty that I can't resolve. I am
>> getting a redirect after login, but only on the test server, not on my
>> local box. It happens when the user logs in; the next page gets served with
>> a 302 redirect header with the location of itself (over and over, so there
>> is a redirect loop).
>>
>>  However, when I am running the app *locally*, after the user logs in
>> the next page gets served with a 200 header (no redirect). I've done some
>> initial searching online to see if anyone's had this behavior with embedded
>> jetty, but so far haven't found anything. The exact same code gives a 302
>> on va-mexp-devci-www101 that gives a 200 on my local.
>>
>>  I read that ContextServer can give this type of behavior if there's no
>> slash at the end of the URL, but it doesn't look like it would turn into a
>> redirect loop. The URL that my user goes to after login is "
>> http://servername:8080/admin/index.do?multisiteId=merchant&redirected=y&lastFormName=loginForm
>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__servername-3A8080_admin_index.do-3FmultisiteId-3Dmerchant-26redirected-3Dy-26lastFormName-3DloginForm&d=AAMFaQ&c=r30hyXAdWe8oret4PlAIyA&r=SBmXB9sPseJz0sZ0KIFqDD2Nqm1s7mFZpe0jYV7fDI4&m=L4XtH2v6zDkT3_7iT236vzssP8dH2eZnLdRB8KKzAuM&s=EWreFvblx_MDQn8PVNL6wgZ_w8U-9QrNgHAjZG686pw&e=>",
>> and the URL that they are getting redirected to infinitely is the exact
>> same URL, not added slash at the end.
>>
>>  Here is my code:
>>
>>      public static void main(String[] args) throws Exception {
>>
>>          Server server = new Server();
>>
>>          // PARSE JSON INPUT
>>         MEXPJsonProps mexpJsonProps =
>> ConfigurationManager.parseJsonInput(args[1]);
>>
>>          // CREATE CONNECTORS
>>         Map<String, Object> httpProps = mexpJsonProps.getHttp();
>>         HttpConfiguration httpConfiguration = new HttpConfiguration();
>>         httpConfiguration.setSecureScheme("https");
>>         httpConfiguration.setSecurePort(8443);
>>         int outputBufferSize = httpProps.get("outputBufferSize")
>> instanceof Double
>>                 ?
>> Double.class.cast(httpProps.get("outputBufferSize")).intValue()
>>                 : (Integer) httpProps.get("outputBufferSize");
>>         httpConfiguration.setOutputBufferSize(outputBufferSize);
>>
>>  // port = 8080
>>         ServerConnector http = new ServerConnector(server,new
>> HttpConnectionFactory(httpConfiguration));
>>         int port = httpProps.get("port") instanceof Double
>>                 ? Double.class.cast(httpProps.get("port")).intValue()
>>                 : (Integer) httpProps.get("port");
>>         http.setPort(port);
>>         int idleTimeout = httpProps.get("idleTimeout") instanceof Double
>>                 ?
>> Double.class.cast(httpProps.get("idleTimeout")).intValue()
>>                 : (Integer) httpProps.get("idleTimeout");
>>         http.setIdleTimeout(idleTimeout);
>>
>>  // adminPort = 8081
>>         ServerConnector httpAdmin = new ServerConnector(server,new
>> HttpConnectionFactory(httpConfiguration));
>>         int adminPort = httpProps.get("adminPort") instanceof Double
>>                 ? Double.class.cast(httpProps.get("adminPort")).intValue()
>>                 : (Integer) httpProps.get("adminPort");
>>         httpAdmin.setPort(adminPort);
>>         httpAdmin.setIdleTimeout(idleTimeout);
>>
>>          // set the connectors
>>         server.setConnectors(new Connector[] { http, httpAdmin });
>>
>>          Map<String, String> localConfiguration =
>> mexpJsonProps.getLocalConfiguration();
>>
>>          // CREATE CONTEXT
>>         WebAppContext context = new WebAppContext();
>>         context.setContextPath("/");
>>
>>          ProtectionDomain domain =
>> JettyWebApp.class.getProtectionDomain();
>>         URL location = domain.getCodeSource().getLocation();
>>         context.setWar(location.toExternalForm());
>>
>>          context.setDescriptor(location.toExternalForm() +
>> "/WEB-INF/web.xml");
>>
>>          // SET UP JSP CONFIGS
>>         File scratchDir = new
>> File(localConfiguration.get("resourceRoot"));
>>         context.setTempDirectory(scratchDir);
>>         context.setPersistTempDirectory(true);
>>         // Set JSP to use Standard JavaC always
>>         System.setProperty("org.apache.jasper.compiler.disablejsr199",
>> "false");
>>
>>          // Set the handler
>>         server.setHandler(context);
>>
>>          server.start();
>>         server.join();
>>     }
>>
>>  Thanks for your thoughts.
>>
>>  Barclay
>>
>>
>> _______________________________________________
>> jetty-users mailing list
>> [email protected]
>> To change your delivery options, retrieve your password, or unsubscribe
>> from this list, visit
>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>> <https://urldefense.proofpoint.com/v2/url?u=https-3A__dev.eclipse.org_mailman_listinfo_jetty-2Dusers&d=AAMFaQ&c=r30hyXAdWe8oret4PlAIyA&r=SBmXB9sPseJz0sZ0KIFqDD2Nqm1s7mFZpe0jYV7fDI4&m=L4XtH2v6zDkT3_7iT236vzssP8dH2eZnLdRB8KKzAuM&s=WXb59HnvJtlJIUahSipaRNEvSLt5zvOe8qZh8HCqwxo&e=>
>>
>
>
> _______________________________________________
> jetty-users mailing list
> [email protected]
> To change your delivery options, retrieve your password, or unsubscribe
> from this list, visit
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
_______________________________________________
jetty-users mailing list
[email protected]
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users

Reply via email to