Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

URLConnection.setRequestProperty no longer works in 1.6.0_22?

452196Oct 29 2010 — edited Feb 19 2011
Anyone else having a problem? A program on one of our user's machines suddenly no longer works, and it looks like it's because their JRE has updated itself.

The program makes a request to a server using a digitally signed, serialized object thusly:
        SignedObject so = new SignedObject(request, codeKey, signer);
        
        HttpURLConnection con = (HttpURLConnection)url.openConnection();
        con.setRequestProperty("Content-Transfer-Encoding", "gzip");
        con.setRequestMethod("POST");
        con.setDoInput(true);
        con.setDoOutput(true);

        ObjectOutputStream out = new ObjectOutputStream(new GZIPOutputStream(con.getOutputStream()));
        out.writeObject(so);
        out.close();
This interaction has been untouched for some years now. The Servlet handling the request does:
            InputStream is = request.getInputStream();
            String coding = request.getHeader("Content-Transfer-Encoding");
            if (coding != null && coding.trim().equalsIgnoreCase("gzip")) {
                is = new GZIPInputStream(is);
                log.debug("Request will be de-zipped");
            }
            ObjectInputStream ois = new ObjectInputStream(is);
            Object o = ois.readObject();
            ois.close();
Suddenly the user was getting error 400 (invalid request) The server was throwing java.io.StreamCorruptedException: invalid stream header: 1F8B0800

After a lot of head scratching I noticed he was using rev 22, so I installed it on my own machine and I get the error too. It appears that the Content-Transfer-Encoding header is simply not happening any more. The coding variable in the server is now null. Debugging the sending code calling setRequestProperty no longer adds an entry to the requests field of HttpURLConnection. 1F8B0800 is the "magic number" of a gzip file.

What's going on? This is the second release in a row that's broken existing code (the first by adding a restriction to LDAP search field names).

Later:

I've constructed an SSCE and submitted a bug report on this one. We'll see if anything happens. I'm concerned that pre-release regression testing isn't what it was under Sun.

Edited by: malcolmmc on 29-Oct-2010 20:02

Comments

Did you look at the release notes?
452196
No, Since I didn't particularly intend to install the upgrade myself, but I have now and nothing seems relevant.

This is a moderately significant piece of functionality, and they have no business changing it in a minor bug fix release.

By the way, when constructing my example I first accidentally put in the header key without the hyphens and that did get through.

1/11:

My [bug report|http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6996110] has now been entered:


The work around suggested is to add -Dsun.net.http.allowRestrictedHeaders=true which implies that this was a deliberate change. Google turns up no results for this flag suggesting this is the first public documentation of it.

So this is, indeed, a deliberate change which is not backward compatible, not highlighted in the release notes and made on a minor revision.

Edited by: malcolmmc on 01-Nov-2010 09:12
YoungWinston
malcolmmc wrote:
The work around suggested is to add -Dsun.net.http.allowRestrictedHeaders=true which implies that this was a deliberate change. Google turns up no results for this flag suggesting this is the first public documentation of it.

So this is, indeed, a deliberate change which is not backward compatible, not highlighted in the release notes and made on a minor revision.
Oooof. Welcome to Oracle, eh? The only question I'd have is whether this is a flag that perhaps should always have been there, given what you're doing; but that only now is mandatory.

Winston
824988
How would I set sun.net.http.allowRestrictedHeaders=true to work around this bug. As you note this field is not documented anywhere and I'm not sure what to do with the information.
I tried passing it as an argument to my program but that seemed to have no effect.

Any help on making this workaround useful for developers is appreciated.
452196
You can either put it on the java command line as -Dsun.net.http.allowRestrictedHeaders=true or you can use System.setProperty("sun.net.http.allowRestrictedHeaders", "true") in the program.
452196
This bug report now seems to have been deleted! So much for democracy.
User_64CKJ
malcolmmc wrote:
This bug report now seems to have been deleted! So much for democracy.
It was bad enough with Sun where some bug reports would never surface. :(
malcolmmc wrote:
This bug report now seems to have been deleted! So much for democracy.
Works for me.

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6996110
1 - 8
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 19 2011
Added on Oct 29 2010
8 comments
4,330 views