0

I try to create a session connecting an Android phone to a Java backend.

For this I call an url looking like this: https://sub.domain.com/path-web/rest/user/init

HTTP/1.1 302 Found
Location: https://path.domain.com;jsessionid=SOMEID.frontend2
Content-Type: text/plain; charset=UTF-8
Content-Length: 0
Connection: close
Set-Cookie: JSESSIONID=SOMEID.frontend2;
Path=/; Secure; HttpOnly
Date: Fri, 24 Oct 2014 08:32:17 GMT

This causes my http library, in this case okhttp to try to follow the redirection to https://path.domain.com;jsessionid=SOMEID.frontend2.

This now fails because parsing this url with java.net.URI produces an URI with a null host. Also Chrome want open the url at it is.

Is the url created wrong from the backend or is the parsing of the url wrong in java.net.URI?

What can I do to work with urls like that?

Janusz
  • 187,060
  • 113
  • 301
  • 369
  • 1
    Interesting related topics: [here](http://stackoverflow.com/questions/18830192/url-semicolon-instead-of-question-mark) and [here](http://stackoverflow.com/questions/3481664/semicolon-as-url-query-separator). I'd say probably weird implementation server-side? – Mena Oct 24 '14 at 09:53
  • I would suggest a wrong URI? I think the correct redirect should be https://path.domain.com?jsessionid=SOMEID.frontend2 – Christopher Oct 24 '14 at 09:54
  • @Christopher strangely enough the semi-colon seems to be a valid, albeit weird replacement for the GET syntax delimiters (`?` and following `&`). – Mena Oct 24 '14 at 09:58
  • 1
    http://www.skorks.com/2010/05/what-every-developer-should-know-about-urls/ says that the parameter notion with semicolons is valid only in the path segment. For that there is a / missing after .com to start the path segment. – Janusz Oct 24 '14 at 10:03
  • 1
    The ;jsessionid sufix is normal: the server appends it to be able to track sessions even if the browser doesn't accept cookies. But the original path to which the server redirects (before the server appends `;jsessionid`) should probably be `https://path.domain.com/`, and not `https://path.domain.com`. – JB Nizet Oct 24 '14 at 10:04

1 Answers1

0

As described in the comments. The url is not valid and therefore not parsed from java.net.URI.

Janusz
  • 187,060
  • 113
  • 301
  • 369