HttpConnection stops reading from Servlet

Hi,
I've developed a servlet which delivers some xml (soap) infos:
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/xml");
response.setHeader("charset","utf-8");
PrintWriter out = response.getWriter();
String xml="<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><addNumbersResponse xmlns=\"http://tempuri.org/\"><addNumbersResult>105</addNumbersResult></addNumbersResponse></soap:Body></soap:Envelope>";
out.println(xml.toString());
and then there is a MIDP Client that should read the XML file:
HttpConnection c = (HttpConnection)Connector.open(getUrl);
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("Content-Type","text/xml");
InputStream is = c.openInputStream();
StringBuffer sb=new StringBuffer();
int read;
while ( (read=is.read())!=-1) {
System.out.print((char)read);
sb.append((char)read);
} while (read!=-1);
The thing that's driving me mad is that read stops (and -1 is correctly in read), but it's only ~230 chars that have been read: It stops after "<addNumbersResponse xmlns=\"http://temp".
A J2SE client gets the complete XML-file with no errors.
Does anyone have an idea what could go wrong here?
Thanks a lot,
Steve

Hi,
I do have the same problem,
i am also sending a xml from the server,
but it gets cut inbetween in 240 to 250 bytes,
how to slove this,
how to get the whole xml from the server to j2me client,
any solution,
what to do on server side and what to modify on client site,,
thanks in advance,
Nazeer

Similar Messages

  • Applet can not read from servlet because of java.io.EOFException

    Hi all,
    i try to communicate my applet with a servlet. i examine lots of codes from internet and i did lots of things to get a working sample but i couldn't sucess on this work for 2 days so if anyone can help me i will be very happy.
    Anyway, here is the code snippets :
    1- Applet side code to send data (serializabed object) to servlet :
       // Opening connection...
       URL urlServlet = new URL("http", "81.214.190.3", 8080, "/pwta/pwtax");
       URLConnection connection = urlServlet.openConnection();
       // Setting attributes...
       connection.setDoInput(true);
       connection.setDoOutput(true);
       connection.setUseCaches(false);
       connection.setDefaultUseCaches(false);
       connection.setRequestProperty("Content-Type",
                                                                  "application/octet-stream");
       OutputStream outputStream = connection.getOutputStream();
       ObjectOutputStream objectOutputStream = new ObjectOutputStream (outputStream);
       objectOutputStream.writeObject(islem);
       objectOutputStream.flush();
       objectOutputStream.close();
       // Receiving result from servlet...
      // Exception is thrown at line 71! Detail is written at bottom of message!
      InputStream inputStream = con.getInputStream(); // line 71 is here!!!
      ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
      returnValue = (Sonuc) objectInputStream.readObject();
      objectInputStream.close();
      inputStream.close();
    2- Server side code which read data and sendit after processing  to   applet  :
    // Reading requirement... Implementation is done in doPost() method!
        InputStream in = request.getInputStream();
        ObjectInputStream inputFromApplet = new ObjectInputStream(in);
        Islem islem = (Islem) inputFromApplet.readObject();
        inputFromApplet.close();
        // Doing the required job!
       setMapperAndDoTheJob(islem);
       // Writing the result to user...
       OutputStream outstr = response.getOutputStream();
       ObjectOutputStream oos = new ObjectOutputStream(outstr);
       oos.writeObject(sonuc);
       oos.flush();
       oos.close();
    //  *************************************************************************When i run my applet the following exception is thrown :
    java.io.EOFException
    at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
    at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
    at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
    at java.io.ObjectInputStream.<init>(Unknown Source)
    at tr.com.proksis.pwta.domain.PWTAProcessor.transferProcess(PWTAProcessor.java:71)
    Best Regards,
    eRoHaN

    get it working using a text transfer before you use and object transfer

  • Stop Reader from Opening pdfs in Firefox?

    I have had substantial problems with Adobe Reader too numerous to detail here.  Suffice it to say that, as a result, I have been forced to turn to an alternative pdf reader.  Even though all web browser options in Adobe Reader prefs are disabled, the other software is set as my defauld pdf viewer, and  disable the Adobe Reader plugin in Firefox, Adobe Reader continues to open pdfs from within Firefox.  (Disabling the plugin works for the current session, but resets when Firefox is restarted.)
    I like using Reader sometimes but unless I can figure out a way to prevent it from opening pdfs in Firefox, I will uninstall it entirely as my only option.  Does anybody have a suggestion as to how I can prevent Reader from opening documents in Firefox?
    Thanks for your help.

    If you are clicking on links which point to PDFs on the web, then Reader will be used to render the PDF using your default browser.
    If you do not wish to view the PDFs on the browser, and want to view them via the application please do the following:
    1. Launch Adobe Reader and goto Edit > Preferences
    2. Navigate to the Internet panel on the left, and uncheck the option to "Diaplay PDF in browser"
    3. Close Adobe Reader and try to launch a PDF link again. You will now be prompted to Save the PDF to your local disk which can then be opened via the application.
    Hope this helps
    Ankit

  • Reading from servlets (where from)

    Hi i would like to read in a text file from my servlet, but i do not know where i should place the file i whish to read in. please could you tell me where i need to place the file to get it to read in and anthing special i need to do to get it to read in.

    The first reply can be used without packages.However you should put your servlet in a package. In
    fact for the servlet containers (Tomcat etc.) that are
    being produced today, you must put your servlet in a
    package.But the text file the servlet reads doesn't have to be in a package.

  • I rent a movie on iTune, dowloading on my ipad2, the movie stop reading from chapter 10, and an alert inform me when i try to Start the movie that i cannot read it. What is the issue for solve this problem?

    I rent a movie on iTunes stores, downloading it to my iPad2, but during the movie, the reading stop from capter 10 to End. I try to restart it, but an alert message inform me that i cannot read the movie. What is the issue for solve this problem? The movie is still located on apps movie, but i cannot read it. Please help.

    Having the same problem. Watched 25 minutes of a rental and it stopped with the message"unable to load video"
    Using current version IPad mini.
    Ios7 is  HUGH PIECE OF CRAP!!!!

  • How can I stop Reader from opening dozens of attachments?

    Starting this morning, when I went to open a .pdf on my Macbook Pro, Reader opened dozens of attachments from many other emails in my inbox, going back weeks.  I've re-booted and tried again, but same as before.  If I use "Preview" on the Mac, it doesn't do that.  What have I done wrong?  Thanks in advance for any good suggestions!

    You can have infinite tabs opening if you have selected Firefox as the application to handle a file if you get an ''Open with'' download window.<br />
    Firefox should not be selected as the application to handle a file and you have to remove the action that is associated with that file type.<br />
    You can delete [http://kb.mozillazine.org/mimeTypes.rdf mimeTypes.rdf] in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Profile Folder] to reset all actions or set the offending action in Tools > Options > Applications to 'Always Ask'<br />
    See http://kb.mozillazine.org/File_types_and_download_actions ("File handling in Firefox 3 and SeaMonkey 2" and "Reset Download Actions")
    * [[Firefox keeps opening many tabs or windows]]

  • Stop reader from launching when I create a PDF with PDFWriter

    I've been using PDFWriter from an old (licensed) version of Adobe 4.0 in conjunction with AutoCAD and other sotware for several years (the full version is still installed on my machine), but yesterday afternoon, every time I created a PDF using it (as a printer device), Adobe Reader X started launching automatically with the created file in it and slowing down whatever application I was "printing" from (even just printing a Test Page from the properties dialogue box accessed from the printer window).  Thinking it was the result of an automatic update, I uninstalled that version and installed an older version of Adobe Reader (9.5.x), but the result is still the same.  I'm unable to locate any stand alone monitor that might've installed itself in conjunction with version X (or an update), and I cannot find any settings in the PDFWriter properties, nor in version 4.0 of Adobe or the version of Reader I'm running.  I could not find any startup items I could identify as Adobe-related.
    Does anybody know how to disable this feature or turn off what I'm calling a PDF Monitor?

    Actually, I went back to the help file for the full version of Acrobat I'm using and found out there's a checkbox at the bottom of the Save As dialogue box that pops up when sending the output through PDFWriter.  Somehow it had gotten checked, and since I'd never NEEDED that feature, I never paid any attention to it LOL.   Thanks anyway.  I thought there might've been a monitor installed with a Reader update that had Explorer integration and watched for creation of a certain file type (PDF in this case) since it started so out-of-the-blue.
    Thanks

  • Stop reading file for user prompt

    Reading from file and writing to binary tree, I need to implement input check. Say if word in the file is not in the tree, I want to prompt user to correct or skip this input.
    The problem is that I'm using GUI (frame with couple of buttons and text field) and I want user to click one of the buttons in order to respond to the request, and stop reading from file unless response is received.... Any ideas how to do this?

    Check out the javadocs on BufferedReader. You should be able to read in a line at a time store it in a buffer and search it for whatever your looking for.There is also a mark method which will let you store your current offset in the file and return to it. Then you can use JOptionPane to display a Yes/No dialog box to prompt the user if the word can be skipped. BufferedReader also has a skip method that will allow you to specify how many chars to skip.
    Hope this helps
    Justin

  • Unable to read http response from servlet (on nokia 6630 device)

    I am sending a http GET request to a servlet for getting some response. Though I am able to obtain the response when I run my j2me app on sony phone I am not able to get any response in case of nokia. On being asked for the APN on nokia I do select the correct one and my settings are correct too. Moreover I am able to connect to the servlet without any problems from my nokia device. However when I tried to read from the Input stream the value returned by read() is -1.
    The code works fine on emulator also. Here is the code snippet being used by me. Plz help me solve this problem. Your response shall be definitely appreciated by me.
    Code in servlet:
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {       
            String t_username = request.getParameter("user");
            String t_password = request.getParameter("pass");
            URL url = new URL("http://somehost:80/query.cgi?serv=s1&user=" + t_username + "&pass=" + t_password);
            HttpURLConnection head = (HttpURLConnection)url.openConnection();
            head.connect();
            int contentLen = head.getContentLength();
            System.out.println("content length = " + contentLen); //here I get some content length value as expected
            BufferedReader in = new BufferedReader(new InputStreamReader(head.getInputStream()));
            StringBuffer sb = new StringBuffer(contentLen);
            String data = null;
            final String NEWLINE = "\r\n"; //acts as delimiter for parsing response later in my j2me code
            while((data = in.readLine()) != null)
                sb.append(data).append(NEWLINE);
            sb.append(NEWLINE);
            in.close();
            PrintWriter out = response.getWriter();
            out.print(sb.toString());
            out.flush();
            out.close();
            head.disconnect();
        }Code in J2ME:
    public static byte[] readFromHttpConnection(String p_URL) throws ConnectionNotFoundException, IOException {
            if(p_URL.startsWith("http://") || p_URL.startsWith("https://")) {
                HttpConnection c = null;
                DataInputStream dis = null;   //tried using InputStream also...still value returned by read() is -1
                c = (HttpConnection)Connector.open(p_URL);
                c.setRequestMethod(HttpConnection.GET);
                c.setRequestProperty("Content-Type", "application/octet-stream");
                dis = c.openDataInputStream();   //able to open this stream
                int len = (int)c.getLength();    //here i get len as -1 for both sony and nokia
                byte[] t_data = null;
                if(len > 0)
                    t_data = new byte[len];
                    int offset = 0;
                    int numRead = 0;
                    while((numRead = dis.read(t_data, offset, t_data.length-offset)) > 0) {
                        offset += numRead;
                else //since i get content length as -1 for both sony and nokia, this block is executed, and though
                       //I am able to read data on sony on nokia read() returns value -1 from the start itself
                    ByteArrayOutputStream bs = new ByteArrayOutputStream();
                    int ch;
                    while((ch = dis.read()) != -1)
                        bs.write(ch);
                    t_data = bs.toByteArray();
                dis.close();
                c.close();
                dis = null;
                c = null;
                return t_data;
            return null;
        }Edited by: alprazolam on Oct 16, 2007 6:02 AM
    Edited by: alprazolam on Oct 16, 2007 6:04 AM
    Edited by: alprazolam on Oct 16, 2007 6:07 AM

    Strange, this should be fine. You might want to try a more efficient (and shorter and faster) read code:
    byte[] buffer = new byte[512];
    ByteArrayOutputStream  = new ByteArrayOutputStream();
    int b;
    while((b=dis.read(buffer))!=-1){
      bs.write(buffer,0,b);
    t_data = bs.toByteArray();No need to check for content length, and always fast. I hope this helps...

  • Using servlets to read from text file and insert data

    Hi,
    Can I use a servlet to read from a space delimited text file on the client computer and use that data to insert into a table in my database? I want to make it easy for my users to upload their data without having to have them use SQL*Loader. If so can someone give me a hint as how to get started? I appreciate it.
    Thanks,
    Colby

    Create a page for the user to upload the file to your webserver and send a message (containing the file location) to a server app that will open the file, parse it, and insert it into your database. Make sure you secure the page.
    or
    Have the user paste the file into a simple web form that submits to a servlet that parses the data and inserts it into your db.

  • How do I stop Serial "VISA Read" from giving me packets instead of available bytes.

    Dear Labvillians,
    Highlight:
    How do I stop serial "VISA read" from giving me packets instead of bytes?
    Background:
    I have a system that serially publishes 14 byte packets on a semi-regular interval.
    At busy times, the producer of these these packets queues the data, effectively producing super-packets in multiples of 14 bytes sometimes as large as 8 packets (112 bytes).
    My protocol handler has been designed to processes bytes, packets or super-packets.
    My application now has multiple devices and the order of message processing is critical to correct functionality.
    My observation is that the VISA read waits until the end of a packet/ super-packet before passing the data to the application code. (See Plot Below)
    My expectation is that VISA read should give me available bytes, and not get too smart for itself and wait for a packet.
    I have observed this on PXI, Embedded PC, cFP and most recently, cRIO
    I have experimented with the cRIO's Scan interface rate, which helps with reducing the packet backlog but doesn't resolve to sub-packet byte read.
    I understand that one solution is to Write FPGA code to handle it and pass the bytes through R/T-FIFO, and there are some great examples on this site.
    Unfortunately this doesn't help with non FPGA devices.
    I have also dabbled in event based serial reads but it is diabolical on vxWorks devices.
    Any Help is appreciated
    iTm - Senior Systems Engineer
    uses: LABVIEW 2012 SP1 x86 on Windows 7 x64. cFP, cRIO, PXI-RT
    Solved!
    Go to Solution.

    Sometimes Talking to yourself is helpful.
    I hope this is a useful Nugget for someone in the future
    iTm - Senior Systems Engineer
    uses: LABVIEW 2012 SP1 x86 on Windows 7 x64. cFP, cRIO, PXI-RT

  • I have ms exchange on my iphone 4s and when i read my email, it disappears. Where does it go and how do I stop this from happening?

    I recently aquired an iphone 4s due to the fact that our parent corporation requires us to use either a blackberry or iphone in order to have the protection needed to use their email. In MS Exchange, when I recieve an email, I read it once, then it's gone. Very frustrating as I need to keep those emails available. Where do they go and How do I stop this from happening?

    i actually got it figured out. I have multiple email accounts i have to use due to different corporate offices ( which can be a real headache at times). The exchange account is an active server used by Hilton and its an actual account. What was happening is my mail was getting kicked back to their server for storage. Once I contacted Hilton, they corrected it on their end. Thanks for trying to help out.

  • Has anyone noticed how easy it is to read a passcode that lights up with each key you press from across a room? Is there a way to stop keypad from lighting up on iPhone 4S, iOS 7?

    Has anyone noticed how easy it is to read a passcode that lights up with each key you press from across a room? Is there a way to stop keypad from lighting up on iPhone 4S, iOS 7.0.3?

    Has anyone noticed how easy it is to read a passcode that lights up with each key you press from across a room? Is there a way to stop keypad from lighting up on iPhone 4S, iOS 7.0.3?

  • Help: Servlet can't read from properties file

    I am working on a web application running in Tomcat on Linux.My java source file reads some parameters from a properties file (data.properties)in the same directory. This works well in a simple application. However, if it is used in the Tomcat environment, it can't be read by a servlet file (LoginServlet.java). I put both the "LoginServlet.class" and "data.properties" in the following directory: /webapps/myapp/WEB-INF/classes. When I run the web application in Tomcat, the error is "data.properties not found". What is the problem? Do I need to modify my "web.xml" and/or Tomcat's "server.xml"? If so, how to modify them?
    This web application contains a lot of serlets. So I don't want to hardcode the parameters into the servlet codes.
    Any info will be appreciated. Thanks in advance!:)

    Putting the properties file in webapps/myapp may or may not help.
    My assumption is that you are trying to open the file by brute force, with something like
    InputStream propis = new FileInputStream ("data.properties");
    Properties props = new Properties ( );
    props.load (propis);
    What you want is to have the class loader find a file in the same place as the class file, and give you back an input stream reading from that file, which you can then pass to the Properties.load(InputStream) method. This is called a "resource," and the way to do it is:
    InputStream propis = getServletContext().getResourceAsStream("data.properties");
    // remaining code as above
    This will cause the class loader for the servlet context (a/k/a the Web application) to find the file in the same manner as it might find a class, but instead of treating it as compiled JVM code, and loading it, it simply passes you back an InputStream from which you do whatever you want.
    Cheers!
    Jerry Oberle
    perl -e 'printf "mailto%cg%s%cearthlink%cnet\n", 58, "oberle", 64, 46;'

  • How do I stop Adobe Reader from crashing on my unprivileged user?

    I am running Windows 7 and I needed to create an unprivileged user on my computer. When I open a PDF file, it almost instantly crashes (I can view the document for about three seconds). If I simply open Adobe Reader without a PDF and click Edit -> Preferences, it crashes. If I open a PDF in any browser, it crashes.
    From what I have been able to surmise, it seems that Adobe Reader is trying to read the registry of my privileged user. I have tried uninstalling Adobe Reader, temporarily giving privileges to my unprivileged user, installing Adobe Reader on that user, and then remove the permissions, but the crash still occurs. The only way to stop Adobe Reader from crashing is to start the program as an administrator or change the account type to administrator. How do I stop Adobe Reader from crashing on my unprivileged user?

    It said "Adobe Reader has stopped working" soon after I opened it, but I was still able to scroll down the document. It was only once I pressed Close Program that it stopped working.
    Upon trying it a second time, it immediately stopped letting me scroll down when the program crashed. Here is the error log, I receive the exact same exception code every time:
    Application Error
    Faulting application name: AcroRd32.exe, version: 11.0.1.36, time stamp: 0x50d0b932
    Faulting module name: AcroRd32.exe, version: 11.0.1.36, time stamp: 0x50d0b932
    Exception code: 0x40000015
    Fault offset: 0x000b7e40
    Faulting process id: 0x104c
    Faulting application start time: 0x01ce02e04f2d96cc
    Faulting application path: C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe
    Faulting module path: C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe
    Report Id: 961d161d-6ed3-11e2-9fb2-001fbc09988e

Maybe you are looking for