java.net.ProtocolException: Bad Set-Cookie header

1.9k views Asked by At

The block of code for your reference is given below:

String hostname = "Hostname Value";
URI uri = new URI(hostname + "/solr/add/story/" + story.getId() + ".html");
final HTTPConnection con = new HTTPConnection(uri);
con.setAllowUserInteraction(false);
final HTTPResponse response = con.Get(uri.getPathAndQuery());

Here, while accessing the response i am getting below exception:

[ WARN] [com.thestreet.cms.integration.solr.SolrService] 12/02/2013 22:52:54-Unable                       
update front end search engine index with story 10446446 
java.net.ProtocolException: Bad Set-Cookie header: FV=OID-|PID-|MID-|PUC-|DATE-         
529D5595; path=/; expires=Tue, 01-Jan-2035 00:00:00 GMT; domain=.thestreet.com;,       
BRIS=C0.A8.41.91|529D55951FB74EF; path=/; expires=Tue, 01-Jan-2035 00:00:00 GMT;     
domain=.thestreet.com;, 
RGIS=-1386042773,192.168.65.145,BA42A8C0,1076F795713A21E010941898-    0-1386042773-; 
path=/; expires=Tue, 01-Jan-2035 00:00:00 GMT; domain=.thestreet.com;,     
JSESSIONID=8A8A377CF937F6184D3F4774CC6F4CBA; Version=1; Path="/"; HttpOnly 
No '=' found for token starting at position 432 
at HTTPClient.Cookie.parse(Cookie.java:243) 
at HTTPClient.CookieModule.handleCookie(CookieModule.java:454) 
at HTTPClient.CookieModule.responsePhase1Handler(CookieModule.java:403) 
at HTTPClient.HTTPResponse.handleResponse(HTTPResponse.java:724) 
at HTTPClient.HTTPResponse.getStatusCode(HTTPResponse.java:190) 
at com.thestreet.cms.integration.solr.SolrService$1.run(SolrService.java:450) 
at java.lang.Thread.run(Thread.java:722)

This seems to be caused by Httponly bit in the cookie header since its not in the form of key-value pair. Is there any way to avoid a cookie header or cookie check while reading the response? Please help.

Thanks in advance.

1

There are 1 answers

0
Sidharth On

The problem is your http request/response contains "HttpOnly" in its header. It appears to be that this value is not supported by application servers anymore. In order to fix this I wrote a workaround where "HttpOnly" is removed from the response on a server side.

String header = resp.getHeader("Set-Cookie");
if (header != null && header.endsWith("HttpOnly")) {
    resp.setHeader("Set-Cookie", header.substring(0, header.length() - 8));
}

But the best solution is to remove "HttpOnly" from the header on the http client side.