You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Julian Reschke (JIRA)" <ji...@apache.org> on 2013/10/16 17:07:42 UTC
[jira] [Commented] (SLING-3175) Make MediaRange parser linient to
accept invalid Accept header generated by Oracle JDK HttpUrlConnection
[ https://issues.apache.org/jira/browse/SLING-3175?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13796860#comment-13796860 ]
Julian Reschke commented on SLING-3175:
---------------------------------------
Here's a test that demonstrates the Java problem:
{code}
package com.greenbytes.httptests;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.URL;
import java.net.URLConnection;
import sun.net.www.protocol.http.HttpURLConnection;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
public class JavaAcceptHeader {
public static void main(String[] args) throws IOException {
InetSocketAddress address = new InetSocketAddress(8000);
HttpServer httpServer = HttpServer.create(address, 0);
HttpHandler echoAccept = new HttpHandler() {
public void handle(HttpExchange exchange) throws IOException {
byte[] response = exchange.getRequestHeaders().get("Accept").toString().getBytes();
exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, response.length);
exchange.getResponseBody().write(response);
exchange.close();
}
};
httpServer.createContext("/", echoAccept);
httpServer.start();
URL url = new URL("http://localhost:8000/");
URLConnection conn = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
System.out.println(in.readLine());
httpServer.stop(0);
}
}
{code}
I have submitted a bug report to Oracle, let's see what happens.
> Make MediaRange parser linient to accept invalid Accept header generated by Oracle JDK HttpUrlConnection
> --------------------------------------------------------------------------------------------------------
>
> Key: SLING-3175
> URL: https://issues.apache.org/jira/browse/SLING-3175
> Project: Sling
> Issue Type: Improvement
> Components: Servlets
> Affects Versions: Servlets Post 2.3.2
> Reporter: Chetan Mehrotra
> Priority: Minor
> Attachments: SLING-3175.patch
>
>
> While making a call to Sling using Java URLConnection we get following exception [1]. The root cause is due to parsing of invalid {{Accept}} header being sent as part of request
> {noformat}
> Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
> {noformat}
> The problem here is that this header is added by JDK itself [0] and at times its not possible to change the request property of URLConnection created by third party library. Would be helpful to make Sling MediaRange parser more linient
> [0] http://hg.openjdk.java.net/jdk6/jdk6-gate/jdk/file/tip/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
> [1] 15.10.2013 16:51:01.646 *WARN* [10.40.247.115 [1381836061645] POST /rpc/protocol/model/rf HTTP/1.1] org.apache.sling.servlets.post.impl.helper.MediaRangeList Error registering media type *; q=.2 java.lang.ArrayIndexOutOfBoundsException: 1
> at org.apache.sling.servlets.post.impl.helper.MediaRangeList$MediaRange.setType(MediaRangeList.java:237)
> at org.apache.sling.servlets.post.impl.helper.MediaRangeList$MediaRange.<init>(MediaRangeList.java:191)
> at org.apache.sling.servlets.post.impl.helper.MediaRangeList.init(MediaRangeList.java:90)
> at org.apache.sling.servlets.post.impl.helper.MediaRangeList.<init>(MediaRangeList.java:56)
> at org.apache.sling.servlets.post.impl.SlingPostServlet.createPostResponse(SlingPostServlet.java:279)
> at org.apache.sling.servlets.post.impl.SlingPostServlet.doPost(SlingPostServlet.java:185)
--
This message was sent by Atlassian JIRA
(v6.1#6144)