X-Received: by 10.66.191.130 with SMTP id gy2mr1430834pac.19.1364678538667; Sat, 30 Mar 2013 14:22:18 -0700 (PDT) X-Received: by 10.49.3.129 with SMTP id c1mr450279qec.40.1364678538253; Sat, 30 Mar 2013 14:22:18 -0700 (PDT) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news.linkpendium.com!news.linkpendium.com!news.snarked.org!newsfeed.news.ucla.edu!usenet.stanford.edu!jn4no32051144pbb.1!news-out.google.com!q9ni26023pba.1!nntp.google.com!jn4no32051139pbb.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.programmer Date: Sat, 30 Mar 2013 14:22:18 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=149.126.45.147; posting-account=swPswAoAAAATb0aX0lbfJoG_e9Lqjd7I NNTP-Posting-Host: 149.126.45.147 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <042eb983-7952-46e4-8002-2eb5c8ff9323@googlegroups.com> Subject: JAVA Networking: Code with getInputStream() was compatible with Java 1.6, is but anymore with 1.7 From: musart Injection-Date: Sat, 30 Mar 2013 21:22:18 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: csiph.com comp.lang.java.programmer:23164 Hello Everybody... I have a piece of software which establishes a communication between a PC a= nd a machine, which used to work in Java 1.6, but doesn't anymore in 1.7. T= he IOException --> "Invalid Http response" is what I get as soon as the get= InputStream() method is called. It seems like the method had been improved = an is much more sensitive, meaning that responseCode=3D-1 result is not spe= cifically checked in Java 1.6. Assited with Wireshark I checked if both versions (1.6 & 1.7) sent and rece= ived same Ethernet frames, and so did both. I can only resolve this from the PC (client) side...that means no posibilit= y to edit or change the Server code. I would apreciate any help on how to modify or implement something new to m= ake the code compatible for ver. 1.7 as Im not a former programmer... Thank= s 1. get is called 2. return readResponse(..) is called 3. getInputStream() --> IOException 4. catch (Exception e) {System.out.println("error sending get request " + g= etURL() + " string: " + requestString); return Error.ethernetException; //T= ODO Code: private String get(String requestString)/* throws ComunicationException*/ { HttpURLConnection httpURLConnection =3D null; OutputStream out =3D null; try { String encodedRequestString =3D URLEncoder.encode(requestString, "iso-8859-= 1"); String path =3D getURL().getPath(); if (!path.endsWith("/")) path =3D path + "/"; path =3D path + encodedRequestString; URL fullURL =3D new URL(getURL().getProtocol(), getURL().getHost(), getURL(= ).getPort(), path); httpURLConnection =3D (HttpURLConnection)fullURL.openConnection(); httpURLConnection.setRequestMethod("GET"); httpURLConnection.setDoOutput(false); httpURLConnection.setDoInput(true); httpURLConnection.setUseCaches(false); // Set timeout at 5s httpURLConnection.setConnectTimeout(m_nTimeOut); httpURLConnection.setReadTimeout(m_nTimeOut); return readResponse(httpURLConnection); } catch (Exception e) { System.out.println("error sending get request " + getURL() + " string: " + = requestString); return Error.ethernetException; //TODO } finally { if (out !=3D null) { try { out.close(); } catch (Throwable t) { System.out.println("GET: out.close(), Class: Client"); } } if (httpURLConnection !=3D null) { try { httpURLConnection.disconnect(); } catch (Throwable t) { System.out.println("GET: httpURLConnection.disconnect(), Class: Client"); } } } } /** * Reads the response from the server into a string. * The content length header must be set! * @param connection * @return * @throws IOException */ private String readResponse(HttpURLConnection connection) throws IOExceptio= n { if (connection =3D=3D null) throw new IllegalStateException("connection mus= t not be null"); connection.connect(); int status =3D connection.getResponseCode(); System.out.println(status); // InputStream aaa =3D connection.getInputStream(); Reader reader =3D null; try { reader =3D new InputStreamReader(connection.getInputStream(), "iso-8859-1")= ; int readBufferSize =3D connection.getContentLength(); if (readBufferSize < 0) { // use default buffer size readBufferSize =3D DEFAULT_READ_BUFFER_SIZE; } // if content length was set, read will be done in a single // iteration because buffer fits... StringBuffer response =3D new StringBuffer(); char[] readBuffer =3D new char[readBufferSize]; int len; while ((len =3D reader.read(readBuffer)) > 0) { response.append(new String(readBuffer, 0, len)); } return response.toString(); } catch (IOException ioe) { throw ioe; } finally { if (reader !=3D null) { try { reader.close(); } catch (Throwable t) { System.out.println("readResponse: reader.close(), Class: Client"); //log } } } } /** * * @return the url */ public URL getURL() { return url; } }