FULL PRODUCT VERSION :
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-0ubuntu1.16.10.2-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Lubuntu 16.10 64 bit with latest updates. Uname -a: Linux 4.8.0-59-generic #64-Ubuntu SMP Thu Jun 29 19:38:34 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
The java.net.URI returned by com.sun.net.httpserver.HttpExchange.getRequestURI() always returns null for getFragment() and getRawFragment() even if the request path contained a fragment.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Make a class that implements com.sun.net.httpserver.HttpHandler. Make a member of class com.sun.net.httpserver.HttpServer. Initialize this member with HttpServer.create() somewhere (constructor of the class, starter method) with a port, followed by a call of createContext("/endpoint", this). In the overridden method public void handle(HttpExchange exchange), do System.out.println(exchange.getRequestURI().getFragment()). Now send a request to the server in the browser with the URL http://localhost:port/endpoint#fragment¶m.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Console prints "fragment¶m".
ACTUAL -
Console prints "null".
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpServer;
import java.net.InetSocketAddress;
import java.io.IOException;
public class Server implements HttpHandler
{
public static void main(String[] args)
{
Server server = new Server();
// Open http://localhost:42342/endpoint#fragment¶m in the browser now.
}
public Server()
{
try
{
this.server = HttpServer.create(new InetSocketAddress(42342), 0);
this.server.createContext("/endpoint", this);
this.server.start();
}
catch (IOException ex)
{
this.server.stop(0);
this.server = null;
}
}
@Override
public void handle(HttpExchange exchange)
{
System.out.println(exchange.getRequestURI().getFragment());
}
protected static HttpServer server = null;
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use another server library, change the API that provides data in the fragment (doesn't work if it is an external API the developer doesn't have control over), use JavaScript in a HTML response that extracts the fragment and provides it as query parameters in a redirect, extract fragment data manually (copy/paste).
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-0ubuntu1.16.10.2-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Lubuntu 16.10 64 bit with latest updates. Uname -a: Linux 4.8.0-59-generic #64-Ubuntu SMP Thu Jun 29 19:38:34 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
The java.net.URI returned by com.sun.net.httpserver.HttpExchange.getRequestURI() always returns null for getFragment() and getRawFragment() even if the request path contained a fragment.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Make a class that implements com.sun.net.httpserver.HttpHandler. Make a member of class com.sun.net.httpserver.HttpServer. Initialize this member with HttpServer.create() somewhere (constructor of the class, starter method) with a port, followed by a call of createContext("/endpoint", this). In the overridden method public void handle(HttpExchange exchange), do System.out.println(exchange.getRequestURI().getFragment()). Now send a request to the server in the browser with the URL http://localhost:port/endpoint#fragment¶m.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Console prints "fragment¶m".
ACTUAL -
Console prints "null".
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpServer;
import java.net.InetSocketAddress;
import java.io.IOException;
public class Server implements HttpHandler
{
public static void main(String[] args)
{
Server server = new Server();
// Open http://localhost:42342/endpoint#fragment¶m in the browser now.
}
public Server()
{
try
{
this.server = HttpServer.create(new InetSocketAddress(42342), 0);
this.server.createContext("/endpoint", this);
this.server.start();
}
catch (IOException ex)
{
this.server.stop(0);
this.server = null;
}
}
@Override
public void handle(HttpExchange exchange)
{
System.out.println(exchange.getRequestURI().getFragment());
}
protected static HttpServer server = null;
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use another server library, change the API that provides data in the fragment (doesn't work if it is an external API the developer doesn't have control over), use JavaScript in a HTML response that extracts the fragment and provides it as query parameters in a redirect, extract fragment data manually (copy/paste).