When using URLConnection read input stream error
hi,
In my applet I build a URLConnection, it connect a jsp file. In my jsp file I refer to a javaBean. I send two objects of request and response in jsp to javaBean. In javabean return output stream to URLConnect. At that time a error happened.WHY???(Applet-JSP-JAVABean)
Thanks.
My main code:
APPLET:(TestApplet)
URL url = new URL("http://210.0.8.120/jsp/test.jsp";
URLConnection con;
con = url .openConnection();
con = servlet.openConnection();
con.setDoInput( true );
con.setDoOutput( true );
con.setUseCaches( false );
con.setRequestProperty( "Content-Type","text/plain" );
con.setAllowUserInteraction(false);
ObjectOutputStream out;
out = new ObjectOutputStream(con.getOutputStream());
Serializable[] data ={"test"};
out.writeObject( data );
out.flush();
out.close();
//until here are all rigth
ObjectInputStream in = new ObjectInputStream( con.getInputStream() );//happened error
JSP:
TestBean testBean = new TestBean ();
testBean .execute(request, response);
JAVABEAN:
public void execute( HttpServletRequest request,
HttpServletResponse response )
ObjectInputStream in = new ObjectInputStream( request.getInputStream() );
String direct = (String) in.readObject();
System.out.prinltn("direct");
ObjectOutputStream out = new ObjectOutputStream( response.getOutputStream() );
SerializableSerializable[] data ={"answer"};
out.writeObject( data );
out.flush();
out.close();
Error detail:
java.io.StreamCorruptedException: invalid stream header
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:729)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:251)
at TestApplet.postObjects(TestApplet.java:172)
you have to pay attention to the sequence of opening the streams.
The following example is: client sends a string to server, and servlet sends a response string back.
client side:
URL url = new URL( "http://152.8.113.149:8080/conn/servlet/test" );
URLConnection conn = url.openConnection();
System.out.println( "conn: " + conn );
conn.setDoOutput( true );
conn.setDoInput( true );
conn.setUseCaches( false );
conn.setDefaultUseCaches (false);
// send out a string
OutputStream out = conn.getOutputStream();
ObjectOutputStream oOut = new ObjectOutputStream( out );
oOut.writeObject( strSrc );
// receive a string
InputStream in = conn.getInputStream();
ObjectInputStream oIn = new ObjectInputStream( in );
String strDes = (String)oIn.readObject();server side
// open output stream
OutputStream out = res.getOutputStream();
ObjectOutputStream oOut = new ObjectOutputStream( out );
// open input stream and read from client
InputStream in = req.getInputStream();
ObjectInputStream oIn = new ObjectInputStream( in );
String s = (String)oIn.readObject();
System.out.println( s );
// write to client
oOut.writeObject( s + " back" ); I have the complete example at http://152.8.113.149/samples/app_servlet.html
don't forget to give me the duke dollars.
Similar Messages
-
Problem reading input stream of urlconnection within portal
Hi,
This may be a generic server issue rather than portal but since it's my portal app that's displaying the problem I'll post it here.
Part of my Portal attempts to POST to a remote server to retrieve some search results.
In environments A & B (both standalone instances) this works fine.
In environment C this works on the managed instances in the cluster but not the admin instance.
In environment D (again standalone) it fails, but if I add a managed instance it works from the managed instance.
The problem I'm seeing is that I get a stuck thread and the thread dump shows it is blocked attempting to read the resulting input from a urlconnection. (Using a buffered input stream).
I've copied the code to a standalone class that runs fine from the same server(s). I've pasted this code below, the contents of the test() method were copied directly from my webapp (urls changed here for clarity).
Does anyone know of any securitymanager issues that may cause this?
Or anything else for that matter?
Code sample:
package src.samples;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class POSTTest {
public static boolean test()
URL url = null;
try {
url = new URL
("http://hostx:80/myapp/search.html");
catch (MalformedURLException e)
e.printStackTrace();
return false;
URLConnection urlConn;
DataOutputStream printout;
BufferedReader input;
urlConn = null;
try {
urlConn = url.openConnection();
catch (IOException e)
e.printStackTrace();
return false;
// Let the run-time system (RTS) know that we want input.
urlConn.setDoInput (true);
// Let the RTS know that we want to do output.
urlConn.setDoOutput (true);
// No caching, we want the real thing.
urlConn.setUseCaches (false);
// Specify the content type.
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
// Send POST output (this is a POST because we write then read as per the JDK Javadoc)
printout = null;
String body = "";
try {
System.out.println("url=" + url.toString());
printout = new DataOutputStream (urlConn.getOutputStream ());
String content = "param1=A¶m2=B¶m3=C¶m4=D¶m5=E";
System.out.println("urlParams= " + content);
printout.writeBytes (content);
System.out.println("written parameters");
printout.flush ();
System.out.println("flushed parameters");
printout.close ();
System.out.println("closed parameter stream");
// <b>Get response data - this is where it blocks indefinitely</b>
input = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
System.out.println("got input");
String str;
while (null != ((str = input.readLine()))) {
body = body + str + "\n";
System.out.println("read input:");
System.out.println(body);
input.close ();
System.out.println("closed input stream");
catch (IOException e) {
System.out.println("IOException caught: read failed");
e.printStackTrace();
return false;
return true;
* @param args
public static void main(String[] args) {
System.out.println("Test result= " + test());In your recuperar() method, read the FTP input stream into a byte array. (You can do that by copying it to a ByteArrayOutputStream and then getting the byte array from that object.) Then, return a ByteArrayInputStream based on those bytes. After you call completePendingCommand(), of course.
That's one way.
PC² -
I cannot open pdf files from one supplier when using Adobe Reader but I can using another Viewer
I cannot open pdf files from one supplier when using Adobe Reader but I can open it if using Google PDF viewer or another viewer. The Adobe reader gives the error "There was an error opening this document. The file is damaged and could not be repaired" when I try to open the file. The version of Adobe Reader is 10.1.7, however I have tried other versions and they all fail the same way. I have tested on a number of different PC's in different networks and all fail using Adobe Reader but work using alternate viewer. Also the PC's will open a PDF from any other source.
Newer Reader versions are more strict than older versions (and other PDF viewers). If certain minimum requirements are not met, Reader will tell you that the PDF is damaged. This can happen when a document was created with software that does not adhere to PDF standards, or when the file was damaged during a download or email transmission.
You should contact the creator of these PDFs. -
Can Data Be Written To A Called PDF When Using Adobe Reader 9?
Can data be written and saved to another called pdf when using Adobe READER 9?
You'll have to expand on your description for a full answer - but all things considered, it would be possible.
If the "called" (this is one of the things you need to clarify - do you mean a PDF opened via the JavaScript openDoc method?) PDF discloses itself, then the "calling" PDF can execute an importXFDF or similar call on that PDF as long as they are Reader Extended.
Past that, you'll need to give us more information on exactly what you're trying to do. -
Adobe is slow when using the reader
adobe is slow when using the reader; It is very slow when I give to another person
I am working in Windows 7.
I have a pdf with 1900 pages of maps. I am using adobe acrobat 10 standard and sampling adobe acrobat xI pro. When I click on links moving from each map takes about 8 secs. when I save the file and give to someone that is just using adobe reader the process takes 20 to 30 seconds to move. -
When using Adobe Reader 11 and entering info on a US government form, 2d Barcode is grayed
2d barcode greyed out when any info is entered into the form...
Hi Pat,
Thanks for the quick response...Here is the link to the document.
http://www.uscis.gov/files/form/i-864.pdf
I have tried several different things, including different computers, tried to open using Firefox / IE / Chrome (None of these even display the 2D barcode portion) and well as another PDF reader.
Basically when using Adobe Reader 11, I can see the 2D barcode normally, but when I even enter a single letter into any field, the 2D barcode is 'greyed' out.
I have searched on the forum and saw another similar post that was mentioning something about a 'license' issue, etc. As I am the end user, there is nothing that I can do in the modification to the file, as it is a protected file (i.e. I can only comlete and print this document).
Thanks for the help. -
JVM_recv in socket input stream error
I've opened a socket and I'm able to access the OutputStream. However, when I try to wrap a ObjectInputStream around the socket's InputStream, I get this error:
SocketException: Connection reset by peer: JVM_recv in socket input stream read.
What should I be looking for?
LarryHere's the code which appears to be relevant, with some commentary on what happens when it is run. Large portions of (hopefully) irrelevant code have been snipped.
Client:
COMMENT: Start a server using RMI. This appears to
COMMENT: succeed, since a message printed by this
COMMENT: server does appear.
try {
DistLrnRemoteData dlrd =
(DistLrnRemoteData)Naming.lookup(
"//"+personHost+
"/DistanceLearningData");
dlrd.activatePersonServer(); // Get server going
catch (Exception e) {
System.err.println(e);
COMMENT: This line is NOT printed, so apparently
COMMENT: there is no Exception.
System.err.println("Unable to initialize remote Person server");
e.printStackTrace(System.err);
Person result = new Person();
int count = 10;
boolean opened = false;
Socket gpsocket = null;
while (!opened) {
try {
COMMENT: The client attempts to open the socket
COMMENT: here. The server never seems to accept it,
COMMENT: but this call appears to succeed. There is
COMMENT: no Exception. The server is running code
COMMENT: from the class RemoteDataServer, so the
COMMENT: port should be the same. The testing was
COMMENT: done with a single host acting as both
COMMENT: client and server, so there isn't any firewall
COMMENT: or network outage problem.
gpsocket = new Socket(personHost,
RemoteDataServer.personReadPort);
opened = true;
catch (IOException ioe) {
count--;
if (count <= 0) {
COMMENT: This line is NOT printed, so apparently there
COMMENT: is no IOException when the Socket is
COMMENT: created. Nor does an UnknownHostException
COMMENT: or SecurityException stop the program.
System.err.println(ioe);
ioe.printStackTrace(System.err);
result = null;
return result;
try {
Thread.sleep(1000);
catch (InterruptedException ie) {
System.err.println(ie);
ie.printStackTrace(System.err);
// Read the serialized object
try {
COMMENT: No problem with the next line, which attempts
COMMENT: to access the OutputStream of the socket.
MyStringWriter msw = new MyStringWriter(
gpsocket.getOutputStream());
COMMENT: The next line causes the message.
ObjectInputStream ois =
new ObjectInputStream(gpsocket.getInputStream());
msw.write(personRealName);
// Now read the resulting Person.
try {
result = (Person)(ois.readObject());
catch (ClassNotFoundException cnfe) {
System.err.println(cnfe);
cnfe.printStackTrace(System.err);
System.exit(4);
catch (IOException ioe) {
System.err.println(ioe);
ioe.printStackTrace(System.err);
result = null;
Server:
public void activateFocusServer() throws java.rmi.RemoteException {
String [] cmd = new String[2];
cmd[0] = new String("java");
cmd[1] = new String("RemoteDataServer");
try {
COMMENT: FORTE's Output window shows a message
COMMENT: from this process
Process dbserver =
Runtime.getRuntime().exec(cmd); // Server will self-destruct
// after a timeout period
catch (IOException ioe) {
COMMENT: This message is never printed
System.err.println(ioe);
ioe.printStackTrace(System.err);
RemoteDataServer:
public RemoteDataServer() {
try {
...many different servers started here...
ServerSocket PersonReadSocket = new ServerSocket(personReadPort);
PersonReadListener prl = new PersonReadListener(PersonReadSocket);
prl.start();
catch (IOException ioe) {
COMMENT: This message is never printed.
System.err.println(ioe);
ioe.printStackTrace(System.err);
COMMENT: PersonReadListener is an inner class:
class PersonReadListener extends java.lang.Thread {
private Thread BaseThread;
private ServerSocket theSocket;
/** Creates an object to listen for PersonRead requests
* @param ss The server socket to listen with
public PersonReadListener(ServerSocket ss) {
theSocket = ss;
/** Initializes the thread to listen for PersonRead requests
public void start() {
BaseThread = new Thread(this);
BaseThread.start();
/** The code for the server to listen for PersonRead requests
public void run() {
while(true) {
try {
COMMENT: This code doesn't have access to System.err
COMMENT: so a file is created to print debugging output
PrintWriter debug = new PrintWriter(new FileWriter("person.debug"));
COMMENT: The next line IS printed, so the server gets
COMMENT: this far.
debug.println("Waiting for connection for person's name");
debug.close();
PersonReadClientConnection someone =
new PersonReadClientConnection(theSocket.accept());
COMMENT: If the previous "debug.close" line is
COMMENT: commented out and the next two lines are
COMMENT: uncommented, the next line is NOT
COMMENT: printed, so apparently the accept nevers
COMMENT: happens! Why does the accept fail, but
COMMENT: the client's socket creation succeed?
// debug.println("Accepted a connection");
// debug.close();
someone.start();
catch (IOException ioe) {
COMMENT: These lines are NOT printed
System.err.println(ioe);
ioe.printStackTrace(System.err); -
My function tried to parse a inputstream(xml format) but I keep getting exception: Exception org.xml.sax.SAXParseException: The root element is required in a well-formed document. I checked my XML format, it looks correct. Is there a way I can print out the input stream but still be able to parse it later with the sam input stream? Thanks.
public static final Document getDOMTree(InputStream input) throws Exception
try
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(input);
return doc;
} catch(DOMException de) {
System.out.println("parse error " +de);
throw new Exception(de.toString());
} catch(Exception e)
System.out.println("Exception " +e);
throw new Exception(e.toString());
}Here's a class that I use for viewing outputstreams in a similar way - you can either adjust it to work as an input stream, or do a quick web search on TeeInputStream - I suspect you'll find some code.
Cheers,
- K
* Copyright (c) 2001 Matthew Feldt. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided the copyright notice above is
* retained.
* THIS SOFTWARE IS PROVIDED ''AS IS'' AND WITHOUT ANY EXPRESSED OR
* IMPLIED WARRANTIES.
* TeeOutputStream.java
* Java Examples In A Nutshell Copyright (c) 2000 David Flanagan
* Exercise 3-7:
* Write a subclass of OutputStream named TeeOutputStream that acts like a T
* joint in a pipe; the stream sends its output to two different output streams,
* specified when the TeeOutputStream is created. Write a simple test program
* that uses two TeeOutputStream objects to send text read from System.in to
* System.out and to two different test files.
* @author Matthew Feldt <[email protected]>
* @version 1.0, 02/12/2001 08:23
import java.io.*;
public class TeeOutputStream extends OutputStream {
OutputStream ostream1, ostream2;
/** sole TeeOutputStream constructor */
public TeeOutputStream(OutputStream o1, OutputStream o2) throws IOException {
ostream1 = o1;
ostream2 = o2;
public void close() throws IOException {
ostream1.close();
ostream2.close();
public void flush() throws IOException {
ostream1.flush();
ostream2.flush();
public void write(int b) throws IOException {
byte[] buf = new byte[1];
buf[0] = (byte)b;
write(buf, 0, 1);
public void write(byte[] b, int off, int len) throws IOException {
ostream1.write(b, off, len);
ostream2.write(b, off, len);
/** test class */
static class Test {
public static void main (String args[]) {
final String f1 = "tee1.out", f2 = "tee2.out";
int ch;
try {
// create a TeeOutputStream with System.out and a file
// as output streams
TeeOutputStream t1 = new TeeOutputStream(
System.out, new FileOutputStream(f1));
// create a TeeOutputStream with t1 and a second file as
// output streams
TeeOutputStream tee = new TeeOutputStream(
t1, new FileOutputStream(f2));
// read characters from System.in and write to the tee
while ((ch = System.in.read()) != -1) {
tee.write(ch);
tee.close(); // close the tee
} catch(FileNotFoundException e) {
System.err.println(e.getMessage());
} catch(IOException e) {
System.err.println(e.getMessage());
} -
Unexpected end of ZLIB input stream error while compiling
Hello
I am getting errors when i run RMIC and JAR apps in the same window, i've tried to close and open the input stream in between, tried delaying between the two , tried /I paramaeter, any one ?
Rmic stage pass OK
but i get Unexpected end of ZLIB input stream exception i some of the file on the jar stage :
Main batch :
start /B %SWIFT_LOCAL_HOME%\scripts\rmicAll.bat
start /B %SWIFT_LOCAL_HOME%\scripts\create_jar.bat
Jar exception :
adding: CVS/(in = 0) (out= 0)(stored 0%)
adding: CVS/Entries(in = 383) (out= 168)(deflated 56%)
adding: CVS/Repository(in = 13) (out= 15)(deflated -15%)
adding: CVS/Root(in = 60) (out= 60)(deflated 0%)
java.io.EOFException: Unexpected end of ZLIB input stream
at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:223)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:141)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:146)
at sun.tools.jar.Main.update(Main.java:508)
at sun.tools.jar.Main.run(Main.java:184)
at sun.tools.jar.Main.main(Main.java:1022)
C:\Eclipse_Workspace\Swift\scripts>date /T 1>>C:\Eclipse_Workspace\Swift\swift_build.txt
C:\Eclipse_Workspace\Swift\scripts>time /T 1>>C:\Eclipse_Workspace\Swift\swift_build.txt
C:\Eclipse_Workspace\Swift\scripts>echo Swift.jar Build Time : 1>C:\Eclipse_Workspace\Swift\swift_build.txt
C:\Eclipse_Workspace\Swift\scripts>"C:\Program Files\Java\jdk1.6.0_02\bin\jar" -uvf C:\Eclipse_Workspace\Swift\jars\swift.jar -C C:\Eclipse_Workspace\Swift swift_build.txt
java.io.EOFException: Unexpected end of ZLIB input stream
at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:223)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:141)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:146)
at sun.tools.jar.Main.update(Main.java:508)
at sun.tools.jar.Main.run(Main.java:184)
at sun.tools.jar.Main.main(Main.java:1022)You seem to be adding the contents of CVS directories to the jar file. CVS directories contain internal information used by CVS. This suggests to me that you are either deliberately doing something really really strange, or you are doing something stupid out of ignorance.
The CVS directories suggest you are making a jar from your source code. Generally you compile the source code 'tree' and place the output (.class files etc) in another tree and create the jar from that second tree.
And PaulMiner is correct, you'll definitely need to change 'start' to 'call'. Do that first, then take a look at what is source code, and what it is that you want in your jar file and make sure it is all sensible, I suspect it isn't. -
URLConnections and Input Streams
I am trying to get a jar file I have up on a web server.
First I make a connection to the server requesting the file..that works fine.
Second i want to use an input stream to bring in the file so i can read its contents.
The problem lies in using the InputStream to read a URL connection.
I have tried using the JarInputStream but that wont work.
Do I need to take my URLConnection and convert it to an object or data type that I am not aware of?
URL url = new URL("http://www.domain.com/myfile.jar");
URLConnection conn = url.openConnection();
JarFile in = new JarFile(new BufferedReader(new InputStreamReader(conn)));
Any ideas fellas?At this point that is all I want to do. Just download the file.
Thats where I am having trouble.
Once I get it downloaded it should be fine.
Should I maybe write the input of the file coming off the server to input of a new file? -
Reading input stream over the tcp socket in unix
I have a program that reads data from input stream from the socket. If the data is over 1500 bytes it is sent in multiple TCP packets. Whats weird is, if I run the program in windows environment it waits till it receives all the packets but when I run the same program in unix environment it only reads the first packet and go further without waiting for all the TCP packets!!
The line that reads from input stream is
datalen = inStr.read(byteBuffer);is there anyway I can make it wait till it receives all the packets on unix system? I do not understand why it works fine for windows in this case but not for unix.
I'll appreciate any help..
ThanksWhen the network is busy there can be any amount of dleay between packets. If this is ever 100 ms , then this will break.
If you send more than one packet per 100 ms you will get two packets at once which will look like one longer packet. Unless you check for this the second packet may get ignored.
The safe way is to send the packet size before sending the packet. Then on the client read the packet to the correct length. Otherwise you will have a program which just happens to work rather than one which will always work. -
How to make use of the Input Stream
Hai,
I want to read input from the user for non-character type through Keyboard as the standard input device. How can I read the non-character type. I tried the following method, but not succeeded. The input data may be of type double or int. Can anyone help me.
DataInputStream num=new DataInputStream(System.in);
Double Vig_Fair_Value=num.read();
Thanks,
SennatYou read the characters the user types, eg. "15" into a string using a BufferedReader, you then convert them to a number here's an method to do it for integers
public static int inInt()
BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
String s = "";try{s = inp.readLine();}catch(Exception e){}
return toInt(s,0); // make integer, default 0
public static int toInt(String s, int er)
int i;
try{i = new Integer(s).intValue();}
catch(NumberFormatException exc){i =er;}
return i; -
LaTeX table rules disappear when using Adobe Reader
Hi,
I created a PDF document using LaTeX and used the LaTeX command \cellcolor to create colored cells in tables. When I view the document with the Adobe Reader some table rules of colored cells dissapear. This is not the case when using Preview on a Mac. The lines become visible when I zoom into the document (>300%) and when I print from Adobe Reader. Hence, it seems to be a problem with the rendering that Adobe Reader does. According to various disscussions on the internet many people seem to have similar problems. However, nobody provided a good solution for it.
Any suggestions to solve the problem?
Thanks in advance,
Sebastian
Adobe Reader screen shot:
Preview screen shot:I am not quite sure if it is a problem with the pdf generator since the problem is not present when using other pdf viewers or when zooming in with Adobe Reader. It might be a problem of the Adobe Reader.
-
Firefox crashes when using adobe reader retriving pdf files
For instance when I tried to get a pdf file from the IRS web site using adobe reader firefox crashes it also does the same thing on other sites with pdf files what would be the problem and how could I resolve this issue.
Hi roy6640,
Have you looked at the Knowledge Base articles [[Troubleshooting plugins]] or [[Using the Adobe Reader plugin with Firefox]]? There is some good information in there. You may want to try reinstalling the plugin as well or updating it if it is out of date.
Hopefully this helps! -
Skip TOC when using screen reader
In Captivate 5.5, can the table of contents be skipped over when using a screen reader? This is for 508 compliance. With the TOC enabled, the user has to go through each item in it before reaching the actual content.
Never seen anything like that. If that happened to me I would update the graphics driver to the latest available version; see http://forums.adobe.com/thread/945765
Maybe you are looking for
-
Different number of Business service endpoint for prod/non prod env in OSB
Hi, I have a scenario in my project. We have 2 managed servers in all non production environment and 4 servers in production environment. In non production environments, have added 2 end point uri in the business service. If we create customization f
-
I now have 2 IPOD touches , 1 8 GB,1 32G plus an IPAD 2 that I've been having syncing issues with. my Dell D830 Latitude w/windows XP. I use outlook calendar and contacts, and the syncing is not completely syncing the outlook information. Help?
-
Let's say I have an object type "pair" with elements "name" and "value". I create a nested table type "pairtable" of type "pair". Then I create a view, "view", that has a column "nametable". The values in "nametable" are the result of a function that
-
No 3g on ipad 2 after iOS 5 update
Hi, after updating my ipad 2 to ios 5 i've noticed it doesn't get 3g although having the right apn settings. i tried the sim card in my iphone 4 and 3g worked fine , but it only reads edge in the ipad 2. this happened after i updated to ios5. Help Pl
-
Lost my desktop shortcut when downloading new version.How do I creat another one?
My desktop shortcut to iTunes (music, store, etc.) was lost when I downloaded a newer version of iTunes. I can't figure out hot to create another one. When I try to access iTunes using Windows Explorer it takes me to the new download page. Can you he