Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #23164 > unrolled thread
| Started by | musart <marcos.barandun@gmail.com> |
|---|---|
| First post | 2013-03-30 14:22 -0700 |
| Last post | 2013-04-05 09:11 -0700 |
| Articles | 11 — 7 participants |
Back to article view | Back to comp.lang.java.programmer
JAVA Networking: Code with getInputStream() was compatible with Java 1.6, is but anymore with 1.7 musart <marcos.barandun@gmail.com> - 2013-03-30 14:22 -0700
Re: JAVA Networking: Code with getInputStream() was compatible with Java 1.6, is but anymore with 1.7 Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-03-30 19:38 -0700
Re: JAVA Networking: Code with getInputStream() was compatible with Java 1.6, is but anymore with 1.7 marcos.barandun@gmail.com - 2013-03-31 01:37 -0700
Re: JAVA Networking: Code with getInputStream() was compatible with Java 1.6, is but anymore with 1.7 Roedy Green <see_website@mindprod.com.invalid> - 2013-04-01 12:50 -0700
Re: JAVA Networking: Code with getInputStream() was compatible with Java 1.6, is but anymore with 1.7 Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2013-03-31 09:57 -0700
Re: JAVA Networking: Code with getInputStream() was compatible with Java 1.6, is but anymore with 1.7 marcos.barandun@gmail.com - 2013-03-31 11:40 -0700
Re: JAVA Networking: Code with getInputStream() was compatible with Java 1.6, is but anymore with 1.7 Steven Simpson <ss@domain.invalid> - 2013-03-31 00:00 +0000
Re: JAVA Networking: Code with getInputStream() was compatible with Java 1.6, is but anymore with 1.7 Steven Simpson <ss@domain.invalid> - 2013-03-31 09:27 +0100
Re: JAVA Networking: Code with getInputStream() was compatible with Java 1.6, is but anymore with 1.7 musart <marcos.barandun@gmail.com> - 2013-04-02 14:08 -0700
Re: JAVA Networking: Code with getInputStream() was compatible with Java 1.6, is but anymore with 1.7 Steven Simpson <ss@domain.invalid> - 2013-04-03 09:05 +0100
Re: JAVA Networking: Code with getInputStream() was compatible with Java 1.6, is but anymore with 1.7 jorge <negrin1969@gmail.com> - 2013-04-05 09:11 -0700
| From | musart <marcos.barandun@gmail.com> |
|---|---|
| Date | 2013-03-30 14:22 -0700 |
| Subject | JAVA Networking: Code with getInputStream() was compatible with Java 1.6, is but anymore with 1.7 |
| Message-ID | <042eb983-7952-46e4-8002-2eb5c8ff9323@googlegroups.com> |
Hello Everybody...
I have a piece of software which establishes a communication between a PC and a machine, which used to work in Java 1.6, but doesn't anymore in 1.7. The IOException --> "Invalid Http response" is what I get as soon as the getInputStream() method is called. It seems like the method had been improved an is much more sensitive, meaning that responseCode=-1 result is not specifically checked in Java 1.6.
Assited with Wireshark I checked if both versions (1.6 & 1.7) sent and received same Ethernet frames, and so did both.
I can only resolve this from the PC (client) side...that means no posibility to edit or change the Server code.
I would apreciate any help on how to modify or implement something new to make the code compatible for ver. 1.7 as Im not a former programmer... Thanks
1. get is called
2. return readResponse(..) is called
3. getInputStream() --> IOException
4. catch (Exception e) {System.out.println("error sending get request " + getURL() + " string: " + requestString); return Error.ethernetException; //TODO
Code:
private String get(String requestString)/* throws ComunicationException*/ {
HttpURLConnection httpURLConnection = null;
OutputStream out = null;
try {
String encodedRequestString = URLEncoder.encode(requestString, "iso-8859-1");
String path = getURL().getPath();
if (!path.endsWith("/")) path = path + "/";
path = path + encodedRequestString;
URL fullURL = new URL(getURL().getProtocol(), getURL().getHost(), getURL().getPort(), path);
httpURLConnection = (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 != null) {
try {
out.close();
} catch (Throwable t) {
System.out.println("GET: out.close(), Class: Client");
}
}
if (httpURLConnection != 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 IOException {
if (connection == null) throw new IllegalStateException("connection must not be null");
connection.connect();
int status = connection.getResponseCode();
System.out.println(status);
// InputStream aaa = connection.getInputStream();
Reader reader = null;
try {
reader = new InputStreamReader(connection.getInputStream(), "iso-8859-1");
int readBufferSize = connection.getContentLength();
if (readBufferSize < 0) {
// use default buffer size
readBufferSize = DEFAULT_READ_BUFFER_SIZE;
}
// if content length was set, read will be done in a single
// iteration because buffer fits...
StringBuffer response = new StringBuffer();
char[] readBuffer = new char[readBufferSize];
int len;
while ((len = reader.read(readBuffer)) > 0) {
response.append(new String(readBuffer, 0, len));
}
return response.toString();
} catch (IOException ioe) {
throw ioe;
} finally {
if (reader != null) {
try {
reader.close();
} catch (Throwable t) {
System.out.println("readResponse: reader.close(), Class: Client");
//log
}
}
}
}
/**
*
* @return the url
*/
public URL getURL() {
return url;
}
}
[toc] | [next] | [standalone]
| From | Daniel Pitts <newsgroup.nospam@virtualinfinity.net> |
|---|---|
| Date | 2013-03-30 19:38 -0700 |
| Message-ID | <ukN5t.74123$mC2.17537@newsfe29.iad> |
| In reply to | #23164 |
On 3/30/13 2:22 PM, musart wrote:
> Hello Everybody...
>
> I have a piece of software which establishes a communication between a PC and a machine, which used to work in Java 1.6, but doesn't anymore in 1.7. The IOException --> "Invalid Http response" is what I get as soon as the getInputStream() method is called. It seems like the method had been improved an is much more sensitive, meaning that responseCode=-1 result is not specifically checked in Java 1.6.
>
> Assited with Wireshark I checked if both versions (1.6 & 1.7) sent and received same Ethernet frames, and so did both.
>
> I can only resolve this from the PC (client) side...that means no posibility to edit or change the Server code.
>
> I would apreciate any help on how to modify or implement something new to make the code compatible for ver. 1.7 as Im not a former programmer... Thanks
>
> 1. get is called
> 2. return readResponse(..) is called
> 3. getInputStream() --> IOException
> 4. catch (Exception e) {System.out.println("error sending get request " + getURL() + " string: " + requestString); return Error.ethernetException; //TODO
does the "status" variable print out? It would if you made it to the
getInputStream call. What is its value? Is it a valid HTTP value? If
not, then the server is doing it wrong and you can insist that is the
case. Broken server is broken.
[toc] | [prev] | [next] | [standalone]
| From | marcos.barandun@gmail.com |
|---|---|
| Date | 2013-03-31 01:37 -0700 |
| Message-ID | <5bd3b330-86de-461e-8e4d-59c464c77a1a@googlegroups.com> |
| In reply to | #23164 |
Status variable (int status = connection.getResponseCode()) is always -1 as seen by the console output either with Java 1.6 or 1.7, but with Java 1.6 the Client-Server communication works fine. console output with Java 1.7: -1 error sending get request http://192.168.1.127:80/ string: *APPLETCOMMINFO_ strResponse: Ethernet Exception console output with Java 1.6: -1 nullsun.net.www.protocol.http.HttpURLConnection$HttpInputStream@6f0ffb38 strResponse: *APPLETCOMMINFO084049051048054050048048051049055032084053048049032032032032050048048050049051101000_ default curser ether action: 4 -1 nullsun.net.www.protocol.http.HttpURLConnection$HttpInputStream@2be2befa strResponse: *APPLETCOMMINFO084049051048054050048048051049055032084053048049032032032032050048048050049051101000_ default curser ether action: 0 -1 nullsun.net.www.protocol.http.HttpURLConnection$HttpInputStream@7e859a68 strResponse: *APPLETCOMMRDKP+1.00000+00+1.00000+00+1.00000+00+1.00000+00+1.00000+00+1.00000+00+1.00000+00+1.00000+00+3.50000+01+5.00000-01+3.50000+01+5.00000-01+3.50000+00+1.00000+02+1.00000+02+1.00000+02+1.00000+02+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+0000001000020000800192000000000000001000020000800192000000000000001000020000800192000000000000001000020000800192000000000000000000000000000000000000000100100100100200200200200300300300300000000000000100100100100000000000000000000000001301301301301401401401404905705604903203203203219216800112725525525500000000000000000100008000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111000000000000000000000000000000100200100210000000000000000001110000000000000000000000000000000000000000000000000000001111111111000111110000063805_ default curser ether action: 0 -1 nullsun.net.www.protocol.http.HttpURLConnection$HttpInputStream@1fe903d5 strResponse: *APPLETCOMMRDPP+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+3.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+2.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+5.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+4.00000+02+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.50000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+2.00000+01+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+1.00000+02+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+5.00000+01+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+2.00000+03+2.00000+03+2.00000+03+2.00000+03+2.00000+03+2.00000+03+2.00000+03+2.00000+03+0.00000+00+0.00000+00+0.00000+00+0.00000+00+1.00000+02+1.00000+02+1.00000+02+1.00000+02+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+00+0.00000+000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000320320320320320320320320320320320320320320320320490570550550320320320320000127981_ default curser ether action: 0 true
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2013-04-01 12:50 -0700 |
| Message-ID | <g1pjl85snvb42d73816iff3bfnmn0m85ht@4ax.com> |
| In reply to | #23167 |
On Sun, 31 Mar 2013 01:37:20 -0700 (PDT), marcos.barandun@gmail.com wrote, quoted or indirectly quoted someone who said : >Status variable (int status =3D connection.getResponseCode()) is always -1 = -1 is what happens when you get no response whatsoever. Try cranking up the timeout. Retry. Check that DNS is working. Try probe using IP. Make sure this is not redirected to https: If so anything not kosher with cert or list of CAs in cacerts will derail you. -- Roedy Green Canadian Mind Products http://mindprod.com Motors make noise, and that tells you about the feelings and attitudes that went into it. Something was more important than sensory pleasure -- nobody would invent a chair or dish that smelled bad or that made horrible noises -- why were motors invented noisy? How could they possibly be considered complete or successful inventions with this glaring defect? Unless, of course, the aggressive, hostile, assaultive sound actually served to express some impulse of the owner. ~ Philip Slater (born: 1927 age: 85) The Wayward Gate: Science and the Supernatural
[toc] | [prev] | [next] | [standalone]
| From | Kevin McMurtrie <mcmurtrie@pixelmemory.us> |
|---|---|
| Date | 2013-03-31 09:57 -0700 |
| Message-ID | <51586b17$0$52772$742ec2ed@news.sonic.net> |
| In reply to | #23164 |
Post the received header here. -- I will not see posts from Google because I must filter them as spam
[toc] | [prev] | [next] | [standalone]
| From | marcos.barandun@gmail.com |
|---|---|
| Date | 2013-03-31 11:40 -0700 |
| Message-ID | <00f7a568-f0d5-4b23-8909-8ebb1bc98d73@googlegroups.com> |
| In reply to | #23164 |
HEADER CAPTURED WITH WIRESHARK (WITH BOTH JRE 1.6 & 1.7 I send and receive the same) SENT: GET /*APPLETCOMMINFO_ HTTP/1.1 Cache-Control: no-cache Pragma: no-cache User-Agent: Java/1.6.0_43 Host: 192.168.1.127 Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 Connection: keep-alive RECEIVED: *APPLETCOMMINFO08404905104805405004804805104905503 2084053048049032032032032050048048050049051101000_
[toc] | [prev] | [next] | [standalone]
| From | Steven Simpson <ss@domain.invalid> |
|---|---|
| Date | 2013-03-31 00:00 +0000 |
| Message-ID | <2tak2a-35n.ln1@s.simpson148.btinternet.com> |
| In reply to | #23164 |
On 30/03/13 21:22, musart wrote: > I have a piece of software which establishes a communication between a PC and a machine, which used to work in Java 1.6, but doesn't anymore in 1.7. The IOException --> "Invalid Http response" is what I get as soon as the getInputStream() method is called. It seems like the method had been improved an is much more sensitive, meaning that responseCode=-1 result is not specifically checked in Java 1.6. > > Assited with Wireshark I checked if both versions (1.6 & 1.7) sent and received same Ethernet frames, and so did both. Get the menu on one of the HTTP-carrying frames, and select "Follow TCP Stream". What is the result? Does it look like a proper HTTP exchange? I would suggest calling getErrorStream() if you get an exception from getInputStream(), but if the response does not appear to be valid HTTP, I can't predict what getErrorStream() will actually give you. -- ss at comp dot lancs dot ac dot uk
[toc] | [prev] | [next] | [standalone]
| From | Steven Simpson <ss@domain.invalid> |
|---|---|
| Date | 2013-03-31 09:27 +0100 |
| Message-ID | <ok8l2a-3lp.ln1@s.simpson148.btinternet.com> |
| In reply to | #23170 |
On 31/03/13 00:00, Steven Simpson wrote: > I would suggest calling getErrorStream() if you get an exception from > getInputStream(), but if the response does not appear to be valid > HTTP, I can't predict what getErrorStream() will actually give you. Of course I can; it's null if "the server sent no useful data". <http://docs.oracle.com/javase/7/docs/api/java/net/HttpURLConnection.html#getErrorStream%28%29> -- ss at comp dot lancs dot ac dot uk
[toc] | [prev] | [next] | [standalone]
| From | musart <marcos.barandun@gmail.com> |
|---|---|
| Date | 2013-04-02 14:08 -0700 |
| Message-ID | <39a63e36-df8f-461f-a014-ab598e76bf9f@googlegroups.com> |
| In reply to | #23164 |
It worked
[toc] | [prev] | [next] | [standalone]
| From | Steven Simpson <ss@domain.invalid> |
|---|---|
| Date | 2013-04-03 09:05 +0100 |
| Message-ID | <ne4t2a-i7a.ln1@s.simpson148.btinternet.com> |
| In reply to | #23194 |
On 02/04/13 22:08, musart wrote: > It worked What worked? The information you gave suggested that the server was at fault for not obeying HTTP, yet fixing the server was not an option for you. Did you drop HttpURLConnection and HTTP altogether? Did getErrorStream provide the response despite its promise of returning null if the server sent "no useful data"? Did the problem suddenly de-materialize? -- ss at comp dot lancs dot ac dot uk
[toc] | [prev] | [next] | [standalone]
| From | jorge <negrin1969@gmail.com> |
|---|---|
| Date | 2013-04-05 09:11 -0700 |
| Message-ID | <55e367bf-401e-45a7-97ca-2444926d9163@googlegroups.com> |
| In reply to | #23164 |
Patético tio ni puta idea de informática, dedíacate a otra cosa imbécil que bastante verguenza ajena estás dando. Patético Pathetic guy fucking clue about computers, another thing dedíacate moron who embarrassed enough're giving. pathetic Pathetic guy fucking Ahnung über Computer, dedíacate andere Sache Idiot, die enough're geben verlegen. armselig
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web