ServletInputStream

Hi,
I am facing a strange problem...
In one of my applications I am using Read method of ServletInputStream to read the byte data input passsed as HTTP Post request to a servlet.
The request is passed from a VB component.
The data passed is an image file and its information.
It works fine when the Web server and the VB component passing the request are on the same physical machine.
When thay are in different machines across a network, a portion of the byte data is lost.
The values returned by the getContentLength matches with the bytes sent from the VB component. But, when I am reading the data and writing into a file I am not getting the entire data.
Could the problem be with the way I am reading the data,or is it due to some problem in the network. ??

When errors like that are occurring, your best bet is to assume that your code is the problem.

Similar Messages

  • How to call jsp after reading from ServletInputStream?

              if the client submit a form including FILE type, I usually use ServletInputStream
              to read it and return next page by calling JSP file. but In weblogic6.0Sp1, the
              server will report a exception: One of the getParameter family of methods called
              after reading from the ServletInputStream(), can't mix these two!
              can anyone help me? thanx a lot.
              

    I've seen these messages in the WLS 5.1.0 logs when POSTing to servlets.
              All the reading is done in the servlet and then a JSP handles the view
              rendering. However, I don't actually call getParameter() or it's kin
              anywhere. I thought maybe something inside the JSP generated servlet is
              calling getParameter(), but I've looked at the generated code and can't find
              any calls. If I had a stack trace it would be easier to sort out.
              Is this a warning or an error? Is there a bad side effect. I imagine the
              getParameter() call would fail.
              Dave
              "dancy" <[email protected]> wrote in message
              news:3ac85201$[email protected]..
              >
              > if the client submit a form including FILE type, I usually use
              ServletInputStream
              > to read it and return next page by calling JSP file. but In
              weblogic6.0Sp1, the
              > server will report a exception: One of the getParameter family of methods
              called
              > after reading from the ServletInputStream(), can't mix these two!
              > can anyone help me? thanx a lot.
              

  • Can't get from ServletInputStream to ZipInputStream

    Here's a problem that's been bothering me:
    I'm trying to set up an import program where I submit a .zip file via POST to a servlet.
    I can submit the .zip and read its binary data just fine. I can also open a zip file that's on the server and parse it contents via java.util.zip and ZipImputStream.
    For some reason though, I can't go from point A to Point B.
    // works
    FileInputStream fis = new FileInputStream( "_test.zip" );
    ZipInputStream zisImportArchive = new ZipInputStream( fis );
    // works
    ServletInputStream sis = request.getInputStream();
    // doesn't work
    ZipInputStream zisImportArchive = new ZipInputStream( sis );
    I don't get any errors, but out.println( zisImportArchive); always returns "null" when it's made from the ServletInputStream.
    Has anyone run into anything like this before?

    Change iTunes Store Country on an iDevice
    1. Tap Settings;
    2. Tap iTunes & App Stores;
    3. Tap View Apple ID;
    4. Enter your user name and password;
    5. Tap Country/Region;
    6. Tap Change Country/Region;
    7. Select the region where you will be located;
    8. Tap Done.
    Also, see How to Change Your iTunes Store Account Location | eHow.com.

  • Unable to read from ServletInputStream

    My applica'n uses a JSP page thru which the user uploads a file .
    The JSP passes the form action to a servlet which reads in the Posted data thru ServletInputStream by doing a request.getInputStream()
    [ The form does contain enctype="multipart/form-data"  attribute..]
    Heres the code snippet :
    =============
    ByteArrayOutputStream barr=new ByteArrayOutputStream();
    ServletInputStream sis=request.getInputStream();
    int len=request.getContentLength();
    int i=0;
    while ( (c=sis.read()) != -1 && (i<len)) {
    barr.write(c);
    i++;
    barr.size() // --> this is returning 0
    =====
    THe prob is although the request.getContentLength() gives some poitive value( indicating that there is some data posted through the form) am unable to retrive the same throught the ServletInputStream obj
    All geeks out there ..plz help me put..
    Thnkx in advance.
    javedp

    I am also getting the same problem as u specfied......
    Plz help me I fu got any solution.....................
    Anybody plz help me to solve the problem....................
    I'l be verymuch thankful for the earliest response.............
    Plz..do this since,it is urgent...............

  • DOMParser halts when parse ServletInputStream

    Hello everyone,
    I am building a system with Web servlet and many clients. Since the clients can be written in C/C++, or Java applet, or simple HTML browser, I use XML to format the data so that the servelt can communicate with any types of clients.
    However, it looks to me the DOMParser can not proceed to parse the XML stream in a ServletInputStream. I appreciate anybody's help including Oracel's engineers'.
    Here is the sample code for java applet client.
    URL url = new URL(serverURL);
    HttpURLConnection conn =(HttpURLConnection)url.openConnection();
    conn.setRequestMethod("POST");
    conn.setRequestProperty("content-type","plain/text");
    conn.setDoInput(true);
    conn.setDoOutput(true);
    OutputStream out = conn.getOutputStream();
    PrintStream ps = new PrintStream(out);
    String str = "<test></test>";
    ps.print(str);
    ps.flush();
    out.close();
    InputStream in = conn.getInputStream();
    Since the client uses POST method, the servlet implements
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    ServletInputStream in = request.getInputStream();
    DOMParser parser = new DOMParser();
    parser.setValidationMode(false);
    parser.showWarnings(false);
    parser.parse( in );
    XMLDocument doc = parser.getDocument();
    The program halts at parser.parse(in). However, if I first read the content of the ServletInputStream and convert it into ByteArrayInputStream, the parser works, which leaves me suspect that ServletInputStream may have some problem.
    byte b[] = new byte[1024]; // assume XML data < 1024 bytes.
    int count = in.read(b);
    ByteArrayInputStream bin = new ByteArrayInputStream(b, 0, count);
    DOMParser parser = new DOMParser();
    parser.setValidationMode(false);
    parser.showWarnings(false);
    parser.parse( bin ); // This works!!!
    XMLDocument doc = parser.getDocument();
    Because most of the time I don't know the size of the ServletInputStream, it is a pain to convert it to ByteArrayInputStream.
    Please help!
    Jack
    null

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by liu9999:
    Im having the same issue, where the XMLparser class can not take a ServletInputStream even though it's an InputStream!!?*@#!!.
    In my case the ServletInputStream is sourced from the MSXML.send() method of the Microsoft XML parser v 2.0.
    Mysteriously, on my local laptop(different than the above machine) with Jrun running on port 8000, this error doesn't occur.
    As a side note, the XML stream produced by the microsoft method doesnt contain the xml header/description/version number in its xml document.
    Anyway, the workaround was to build a byte array with a length of (ServletInputStream's getContentLength() method), open a ByteArrayInputStream on the byte array and load the Oracle XML parser's parse method with the ByteArrayInputStream - like Jack did.
    This seems to be working for me for now. But an extra initialization of memory to work around this issue is not desirable.
    If anyone has any info on this "bug" please contact me at [email protected]
    Thank you, keep up the good work.
    <HR></BLOCKQUOTE>
    null

  • ServletInputStream error when reading more than once

    I have an application which needs to look at fields in a multipart request in several different places of the code. The first time I look at the request, it works just fine, but every time after that it doesn't. Here is a simplified example of what is happening:
    private ServletInputStream in;
    private HttpServletRequest request;
    private byte[] buff = new byte[100*1024];
    public Class class1  {
        public class1(HttpServletRequest req) {
            super();
            request = req;
            in = request.getInputStream();
            String line = readLine();
            System.out.println("Testing line1: " + line);
    private ServletInputStream in2;
    private HttpServletRequest request;
    private byte[] buff = new byte[100*1024];
    public Class class2  {
        public class2(HttpServletRequest req) {
            super();
            request = req;
            in2 = request.getInputStream();
            String line = readLine();
            System.out.println("Testing line2: " + line);
    }Not sure that it is relevant, but in case it is, my readLine() method looks like this:
    private String readLine() throws IOException {
        int len = 0;
        String line = null;
        len = in.readLine(buff,0,buff.length);
        if(len < 0) return null;
        line = new String(buff,0,len,"ISO-8859-1");
        return line;
    }The request is basically passed around so it is the same request object both times. The first one outputs the first line as expected. In the second one however, line is null.
    Interestingly enough, I found the following to be true also:
    private ServletInputStream in;
    private ServletInputStream in2;
    public Class class3 {
        public class3(HttpServletRequest request){
            super();
            in = request.getInputStream();
            if(in != null) {
                in.close();
            in = null;
            in2 = request.getInputStream();
            String line = in2.readLine();
            // IOException OCCURS HERE SAYING: Stream closed
    }The stream was closed on the first "in" but not on the second, so why would I be getting this????
    Help!!

    I am not completely sure what to do now. Basically, I have a multipart request for a fileupload. Towards the beginning of my servlet, I need to get the form parameters. This is working fine. But since you say that the getInputStream() will return the same instance regardless of where it is called from, I am in trouble when later on in the code I need to actually upload the file. To integrate this into my core java framework, there really isn't a way that I can get all the information I need at the beginning and use it later. Is there a way I can get the form parameters WITHOUT using the inputstream? Then, my inputstream could be called in my mapper for uploading the file. I haven't found another way to do this, as multipart requests are handled differently. Any suggestions at all?

  • ServletInputStream in Servlet Forwarding empty

    Please help me, i think i have a problem.
    After reading and checking "request"
    seem that the xml message soap included in "request" disappear.
    I have to forwarding it to another servlet.
    Is too late? I have lost it?
    Where is it ?
    I use the RequestDispatcher.forward() method for forwarding
    but (i'm sure) the second servlet receives the "request.getInputStream()" empty.
    Who can help me?
    Thanks in advance
    my code :
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    ServletInputStream in = request.getInputStream();
    byte[] fre=null;
    String xml="";     
    while (in.available()>0) {
    try {
    fre = new byte[in.available()];
    in.read(fre);
    xml = xml + new String(fre);
    } catch (Exception exc) {
    exc.printStackTrace();
    if (ckeck(xml)) {     
    request.getRequestDispatcher("myservlet2").forward(request,response);
    }

    You have already read the input stream. Once read, and it gets read, it can not be re-read. If you want the information in both places, read it in the first servlet and store it in a scope that the other servlet can read (like as a request attribute:
      byte[] fre=null;
      String xml="";
      while (in.available()>0) {
        try {
          fre = new byte[in.available()];
          in.read(fre);
          xml = xml + new String(fre);
        } catch (Exception exc) {
          exc.printStackTrace();
      request.setAttribute("xml", xml);
      if (ckeck(xml)) {
        request.getRequestDispatcher("myservlet2").forward(request,response);
    //... then in myservlet2
      String xml = (String)request.getAttribute("xml");

  • Problems getting ServletInputStream

    Hi, we're using weblogic workshop, we need to get the ServletInputStream from a request in a pageflow but it seems to be empty, is this due to struts?, any idea how we can get the content of the InputStream?.
    Thanks.

    @kardenlodge
    Open Mail.app, and on the menu bar, choose Window and click Connection Doctor. On the following window, look at any of the lines that start with a red dot. One will probably be Gmail-IMAP or something similar. To the right will be an error message, what does it say? Is it an issue with a username/password? Or does it mention that some of the settings are wrong?
    Apple keeps a log of common Email Service Providers and their settings. You can cross-reference the settings on your machine with the known good settings found here.
    If it's a username/password issue, make sure you can still log into Gmail's webmail to verify you're using the correct username/password combination. By double-clicking the erroneous line in Mail Connection Doctor, it'll take you to the pane where you can input the correct password if necessary.
    Hope this helps!

  • Need help on ServletInputStream

    I want to read the ServletInputStream and print it in the servlet log.
    but I still did't understand how to do this after reading the API, it's too difficult for me to understand. Anyone can help me?
    Thank you.
    byte[] b;
    int off=0;
    int len;  <???????
    ServletInputStream sis=request.getInputStream();
    while(sis.readLine(b, off, len)!=-1) {
    System.out.println(); <<<<<<???????
    }

    It isn't too difficult. You just have to break it into pieces...
      byte[] b;
      int off=0;
      int len;  <???????So what are b, off, and len used for?
    When reading from a binary stream, you read in bytes. You will temporarily store those bytes in an array (b).
    When you are reading the stream, you don't have to fill the byte array from zero. You can fill it from some other point so that you can maintain results from some other read. The off variable is an offset in the array where you want to store the first byte read from the input stream
    Along those same lines is len: you want to make sure that you only read as many bytes as your array can fit (or some other length of consecutive bytes that is meanongful). The len represents the number of consecutive bytes that want to read from the stream (length).
    An input stream's read(byte[],int,int) method returns an interger of the actual number of bytes read from the stream, which may be the same as length you provided, but usually is less (if for any reason the process is interrupted, or the consumer who gets the bytes from the underlying source isn't up to speed, then the method will return as quickly as possible with whatever it could get... in the ServletInputStream readLine method it also imediately returns when a new line is reached...)
    Now we understand the pieces?
    Useually they will get initialized to some values. For example, I like to keep my byte array and length of read large so as they don't become the limiting factor in a particular read:
    int length = 1024*1024; //A big number
    byte[] buffer = new byte[length]; //Better name then b and len
    int offset = 0;
      while(sis.readLine(b, off, len)!=-1) { So now we will read from the input stream. We will do it in a loop because the entire stream will not be read at one time, so we want to make sure we get it all. The byte count returned from the method will be -1 if we reach the end of the stream, so we use that as the termination condition for our loop.
    In addition to this, however, I like to keep track of the actual byte count read in a variable so we can use it later on, so my while loop looks like this:
      int bytesRead = 0;
      while((bytesRead = sis.readLine(buffer, offset, length)) != -1) { So now we have buffer partially filled with bytes, starting at offest, and having bytesRead number of meaningful bytes in it. So we want to print it out (to System.out?? Are you sure??) So we will look though the API to see what method might be most useful in this situation...
    Well, System.out is a PrintStream, which has a write(byte[] b, int off, int len) method. This is the best candidate for out output:
              System.out.write(buffer,offset,bytesRead);
      }You see that the last parameter in the method we use is the bytesRead, since we only want to write the number of bytes that were actually read from the input stream, and not entire buffer.

  • ServletInputStream - wierd behaviour

    I have following code inside servlet. Response times are not consistent at all. I don't see any problems in the code except that it might be something inside ServletInputStream that's slow. Below is the code and the result. Results below are so wierd sometimes it takes longer to read for smaller file size as compared to the file that has larger size. There are plenty of available threads and resources, memory etc. on box
    Please help!
        public byte[] getBytes(HttpServletRequest req) {
            InputStream inp = null;
            ByteArrayOutputStream ostr = null;
            byte[] data = null;
            try {
                long l = System.currentTimeMillis();
                ostr = new ByteArrayOutputStream();
                inp = req.getInputStream();
                logger.info("Took 1 " + (System.currentTimeMillis() - l));
                int c = 0, cnt = 0;
                byte[] b = new byte[1024 * 4];
                while (-1 != (c = inp.read(b))) {
                    ostr.write(b, 0, c);
                    cnt += c;
                logger.info("Took 2 " + (System.currentTimeMillis() - l));
                data = ostr.toByteArray();
                logger.info("Took 3 " + (System.currentTimeMillis() - l) + " for length " + cnt);
            } catch (Exception e) {
                logger.error("Couldn't read Input Stream ", e);
            } finally {
                try {
                    if (null != inp) {
                        inp.close();
                    if (null != ostr) {
                        ostr.close();
                } catch (Exception e) {
                    e.printStackTrace();
            return data;
        }Results:
    09-02-25 11:33:06,123 INFO [:http-8080-12] - Took 2 33719
    2009-02-25 11:33:06,123 INFO [:http-8080-12] - Took 3 33719 for length 234934
    2009-02-25 11:33:06,162 INFO [:http-8080-7] - Took 1 0
    2009-02-25 11:33:06,168 INFO [:http-8080-7] - Took 2 6
    2009-02-25 11:33:06,168 INFO [:http-8080-7] - Took 3 6 for length 228412
    2009-02-25 11:33:06,183 INFO [:http-8080-11] - Took 1 0
    2009-02-25 11:33:06,188 INFO [:http-8080-11] - Took 2 6
    2009-02-25 11:33:06,188 INFO [:http-8080-11] - Took 3 6 for length 228370
    2009-02-25 11:33:06,640 INFO [:http-8080-11] - Took 1 0
    2009-02-25 11:33:06,643 INFO [:http-8080-11] - Took 2 3
    2009-02-25 11:33:06,643 INFO [:http-8080-11] - Took 3 3 for length 111169
    2009-02-25 11:33:06,682 INFO [:http-8080-7] - Took 1 0
    2009-02-25 11:33:06,685 INFO [:http-8080-7] - Took 2 3
    2009-02-25 11:33:06,685 INFO [:http-8080-7] - Took 3 3 for length 111232
    2009-02-25 11:33:06,749 INFO [:http-8080-4] - Took 2 1177
    2009-02-25 11:33:06,750 INFO [:http-8080-4] - Took 3 1178 for length 239050
    2009-02-25 11:33:06,779 INFO [:http-8080-1] - Took 2 2233
    2009-02-25 11:33:06,779 INFO [:http-8080-1] - Took 3 2233 for length 111104
    2009-02-25 11:33:08,232 INFO [:http-8080-10] - Took 2 4628
    2009-02-25 11:33:08,232 INFO [:http-8080-10] - Took 3 4628 for length 225770
    2009-02-25 11:33:08,419 INFO [:http-8080-9] - Took 2 4811
    2009-02-25 11:33:08,420 INFO [:http-8080-9] - Took 3 4812 for length 232581
    2009-02-25 11:33:08,451 INFO [:http-8080-8] - Took 2 4633
    2009-02-25 11:33:08,451 INFO [:http-8080-8] - Took 3 4633 for length 225509
    2009-02-25 11:33:09,123 INFO [:http-8080-5] - Took 2 4631
    2009-02-25 11:33:09,123 INFO [:http-8080-5] - Took 3 4631 for length 228427
    2009-02-25 11:33:10,169 INFO [:http-8080-3] - Took 2 15257
    2009-02-25 11:33:10,170 INFO [:http-8080-3] - Took 3 15258 for length 239099
    2009-02-25 11:33:14,248 INFO [:http-8080-6] - Took 2 20500
    2009-02-25 11:33:14,248 INFO [:http-8080-6] - Took 3 20500 for length 146626
    2009-02-25 11:33:02,889 INFO [:http-8080-7] - Took 3 2282 for length 111165
    2009-02-25 11:33:03,107 INFO [:http-8080-9] - Took 2 2231
    2009-02-25 11:33:03,107 INFO [:http-8080-9] - Took 3 2231 for length 111257
    2009-02-25 11:33:03,192 INFO [:http-8080-10] - Took 1 0
    2009-02-25 11:33:03,194 INFO [:http-8080-10] - Took 2 2
    2009-02-25 11:33:03,195 INFO [:http-8080-10] - Took 3 3 for length 111079
    2009-02-25 11:33:03,202 INFO [:http-8080-7] - Took 1 0
    2009-02-25 11:33:03,205 INFO [:http-8080-7] - Took 2 3
    2009-02-25 11:33:03,205 INFO [:http-8080-7] - Took 3 3 for length 111196
    2009-02-25 11:33:03,211 INFO [:http-8080-8] - Took 1 0
    2009-02-25 11:33:03,224 INFO [:http-8080-8] - Took 2 13
    2009-02-25 11:33:03,225 INFO [:http-8080-8] - Took 3 14 for length 234934
    -----

    session is not getting replicated. I noticed that the class name of          HttpSession
              > is weblogic.servlet.internal.session.MemorySessionData on solaris servers
              and
              > its weblogic.servlet.internal.session.ReplicatedSessionData on windows
              clustered
              > servers. So the fail over doesn't really work correctly
              It sounds like you need to double/triple check the configuration of the
              servers in the cluster. The servers apparently don't know to use the
              clustered sessions, and that is a configuration item, not part of the app.
              Peace,
              Cameron Purdy
              Tangosol, Inc.
              http://www.tangosol.com/coherence.jsp
              Tangosol Coherence: Clustered Replicated Cache for Weblogic
              "Praveen Peddi" <[email protected]> wrote in message
              news:3f09e877$[email protected]..
              >
              

  • How can I read the ServletInputStream from a JSC application ?

    I have asked this question in a number of different ways on the forum without getting a solution that works. What I am trying to do should be a common thing in any business application, I just want to get the data posted to my application, which has been posted as an XML document.
    Methods like getRequest(), getRequestParameterMap(), and getRequestMap() are just not doing it. These are not parameters sent with the URL, or parameters at all really, it is just an XML document sent in the body of the post request.
    I have been trying to drill down to something that extends HttpServlet in the JSC architecture. I've done a lot of drilling, and haven't hit oil yet !
    Joe Paladin

    I tested it, and it worked ! I made some minor modifications, and corrected a little typo here and there, so I figured I would post the actual code that I have so far in my page's preRender() that goes and gets the data posted to the page. One improvement I still need to make is getting the actual length of the content, for some reason I had trouble calling getContentLength(). This should really get people going though who might be doing similar work with XML Servlets :
    try {
    HttpServletRequest httpreq = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
    httpreq.getInputStream().readLine(inputbytes, 0, 100);
    postData3 = new String(inputbytes);
    } catch (Exception e) {
    // report error
    postData3 = "Error reading post data";
    }

  • ServletInputStream.read() causes read time out error

    this part of the jsp page
    <jsp:useBean id="testServlet" scope="page" class="testServlet" />
    <%
    testServlet.doUpload(request);
    %>
    this is part of the servlet
    public void doUpload(HttpServletRequest request) throws IOException
    BufferedInputStream br = new BufferedInputStream(request.getInputStream());
    /* error here! */
    int i = br.read();
    it will produce an read time out error when i reach the error line
    btw..... i am using tomcat as server and parsing the form :
    <form name="form1" enctype="multipart/form-data" method="get" action="converter.jsp">
    <input type="file" name="filename">
    </form>
    thnx in advance!

    I'd think for the request to have an input stream, the request method on the form would need to be post, not get. Other than that, I don't know why you've created a Servlet - seems like you could have just created a simple class that takes a HttpServletRequest object (doesn't have to be a servlet). Your jsp page is the real servlet that's being called.

  • Servlet charset encoding and ServletInputStream

    Does any one have code sample which implement
    HttpServletRequest.getInputStream()?
    Does any one know if there is any way to change request encoding in servlet 2.2??

    Checkout Tomcat at jakarta.apache.org site, this is the reference implementation for the Servlet API, is open source and provides plently of material.
    Also checkout this book:
    which covers all the must know stuff on Servlets.
    http://www.oreilly.com/catalog/jservlet2/toc.html
    Not exactly sure what you mean by this
    change request encoding in servlet 2.2??
    If you actually mean internationalisation of the response stream, checkout these links.
    http://java.sun.com/products/jdk/1.2/docs/guide/internat/index.html
    http://java.sun.com/docs/books/tutorial/essential/io/index.html
    http://developer.java.sun.com/developer/technicalArticles/Streams/WritingIOSC/

  • Trying to get lighttpd to upload a file through perl cgi

    Hi, I'm quite new in these things, so I might be doing something obvious wrong, but I'd like some help on this.
    I'm trying to make a webpage where people can upload files, this is the html page (located at /srv/html/index.html):
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>lighttpd Test Page</title>
    </head>
    <body>
    <div style="text-align:center; font: 12px sans-serif;">
    <span style="font-weight: bold; font-size: 20px;">
    Arch Linux
    </span>
    <br><br>
    This is a test page for the lighttpd Web Server.<br>
    <form action="/cgi-bin/upload.pl" method="post" enctype="multipart/form-data">
    <input type="file" name="fileName" size="40">
    <input type="submit" value="Send">
    <input type="reset">
    </form>
    </div>
    </body>
    </html>
    And the backend (in /srv/html/cgi-bin/upload.pl):
    #!/usr/bin/perl -wT
    use strict;
    use CGI;
    use CGI::Carp qw ( fatalsToBrowser );
    use File::Basename;
    $CGI::POST_MAX = 1024 * 1024 * 5000; # 5GB filesize limit
    my $safe_filename_characters = "a-zA-Z0-9_.-";
    my $upload_dir = "/srv/jail/";
    my $query = new CGI;
    my $filename = $query->param("fileName");
    if ( !$filename )
    print $query->header ( );
    print "There was a problem uploading your file (filesize limit may be exceeded).";
    exit;
    my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' );
    $filename = $name . $extension;
    $filename =~ tr/ /_/;
    $filename =~ s/[^$safe_filename_characters]//g;
    if ( $filename =~ /^([$safe_filename_characters]+)$/ )
    $filename = $1;
    else
    die "Filename contains invalid characters";
    my $upload_filehandle = $query->upload("fileName");
    open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!";
    binmode UPLOADFILE;
    while ( <$upload_filehandle> )
    print UPLOADFILE;
    close UPLOADFILE;
    print $query->header ( );
    print <<END_HTML;
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Done!</title>
    </head>
    <body>
    <p>Uploading done!</p>
    </body>
    </html>
    END_HTML
    My server config:
    # lighttpd configuration file
    # use it as a base for lighttpd 1.0.0 and above
    # $Id: lighttpd.conf,v 1.7 2004/11/03 22:26:05 weigon Exp $
    ############ Options you really have to take care of ####################
    ## modules to load
    # at least mod_access and mod_accesslog should be loaded
    # all other module should only be loaded if really neccesary
    # - saves some time
    # - saves memory
    server.modules = (
    # "mod_rewrite",
    # "mod_redirect",
    # "mod_alias",
    "mod_access",
    # "mod_cml",
    # "mod_trigger_b4_dl",
    # "mod_auth",
    # "mod_status",
    # "mod_setenv",
    # "mod_fastcgi",
    # "mod_proxy",
    # "mod_simple_vhost",
    # "mod_evhost",
    # "mod_userdir",
    "mod_cgi",
    # "mod_compress",
    # "mod_ssi",
    # "mod_usertrack",
    # "mod_expire",
    # "mod_secdownload",
    # "mod_rrdtool",
    "mod_accesslog" )
    ## a static document-root, for virtual-hosting take look at the
    ## server.virtual-* options
    server.document-root = "/srv/http/"
    ## where to send error-messages to
    server.errorlog = "/var/log/lighttpd/error.log"
    # files to check for if .../ is requested
    index-file.names = ( "index.php", "index.html",
    "index.htm", "default.htm" )
    ## set the event-handler (read the performance section in the manual)
    # server.event-handler = "freebsd-kqueue" # needed on OS X
    # mimetype mapping
    mimetype.assign = (
    ".pdf" => "application/pdf",
    ".sig" => "application/pgp-signature",
    ".spl" => "application/futuresplash",
    ".class" => "application/octet-stream",
    ".ps" => "application/postscript",
    ".torrent" => "application/x-bittorrent",
    ".dvi" => "application/x-dvi",
    ".gz" => "application/x-gzip",
    ".pac" => "application/x-ns-proxy-autoconfig",
    ".swf" => "application/x-shockwave-flash",
    ".tar.gz" => "application/x-tgz",
    ".tgz" => "application/x-tgz",
    ".tar" => "application/x-tar",
    ".zip" => "application/zip",
    ".mp3" => "audio/mpeg",
    ".m3u" => "audio/x-mpegurl",
    ".wma" => "audio/x-ms-wma",
    ".wax" => "audio/x-ms-wax",
    ".ogg" => "application/ogg",
    ".wav" => "audio/x-wav",
    ".gif" => "image/gif",
    ".jar" => "application/x-java-archive",
    ".jpg" => "image/jpeg",
    ".jpeg" => "image/jpeg",
    ".png" => "image/png",
    ".xbm" => "image/x-xbitmap",
    ".xpm" => "image/x-xpixmap",
    ".xwd" => "image/x-xwindowdump",
    ".css" => "text/css",
    ".html" => "text/html",
    ".htm" => "text/html",
    ".js" => "text/javascript",
    ".asc" => "text/plain",
    ".c" => "text/plain",
    ".cpp" => "text/plain",
    ".log" => "text/plain",
    ".conf" => "text/plain",
    ".text" => "text/plain",
    ".txt" => "text/plain",
    ".dtd" => "text/xml",
    ".xml" => "text/xml",
    ".mpeg" => "video/mpeg",
    ".mpg" => "video/mpeg",
    ".mov" => "video/quicktime",
    ".qt" => "video/quicktime",
    ".avi" => "video/x-msvideo",
    ".asf" => "video/x-ms-asf",
    ".asx" => "video/x-ms-asf",
    ".wmv" => "video/x-ms-wmv",
    ".bz2" => "application/x-bzip",
    ".tbz" => "application/x-bzip-compressed-tar",
    ".tar.bz2" => "application/x-bzip-compressed-tar",
    # default mime type
    "" => "application/octet-stream",
    # Use the "Content-Type" extended attribute to obtain mime type if possible
    #mimetype.use-xattr = "enable"
    ## send a different Server: header
    ## be nice and keep it at lighttpd
    # server.tag = "lighttpd"
    #### accesslog module
    accesslog.filename = "/var/log/lighttpd/access.log"
    ## deny access the file-extensions
    # ~ is for backupfiles from vi, emacs, joe, ...
    # .inc is often used for code includes which should in general not be part
    # of the document-root
    url.access-deny = ( "~", ".inc" )
    $HTTP["url"] =~ "\.pdf$" {
    server.range-requests = "disable"
    # which extensions should not be handle via static-file transfer
    # .php, .pl, .fcgi are most often handled by mod_fastcgi or mod_cgi
    static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
    ######### Options that are good to be but not neccesary to be changed #######
    ## bind to port (default: 80)
    server.port = ###
    ## bind to localhost (default: all interfaces)
    #server.bind = "127.0.0.1"
    ## error-handler for status 404
    #server.error-handler-404 = "/error-handler.html"
    #server.error-handler-404 = "/error-handler.php"
    ## to help the rc.scripts
    server.pid-file = "/var/run/lighttpd/lighttpd.pid"
    ###### virtual hosts
    ## If you want name-based virtual hosting add the next three settings and load
    ## mod_simple_vhost
    ## document-root =
    ## virtual-server-root + virtual-server-default-host + virtual-server-docroot
    ## or
    ## virtual-server-root + http-host + virtual-server-docroot
    #simple-vhost.server-root = "/srv/http/vhosts/"
    #simple-vhost.default-host = "www.example.org"
    #simple-vhost.document-root = "/htdocs/"
    ## Format: <errorfile-prefix><status-code>.html
    ## -> ..../status-404.html for 'File not found'
    #server.errorfile-prefix = "/usr/share/lighttpd/errors/status-"
    #server.errorfile-prefix = "/srv/http/errors/status-"
    ## virtual directory listings
    #dir-listing.activate = "enable"
    ## enable debugging
    #debug.log-request-header = "enable"
    #debug.log-response-header = "enable"
    #debug.log-request-handling = "enable"
    #debug.log-file-not-found = "enable"
    ### only root can use these options
    # chroot() to directory (default: no chroot() )
    #server.chroot = "/"
    ## change uid to <uid> (default: don't care)
    server.username = "http"
    ## change uid to <uid> (default: don't care)
    server.groupname = "http"
    #### compress module
    #compress.cache-dir = "/var/cache/lighttpd/compress/"
    #compress.filetype = ("text/plain", "text/html")
    #### proxy module
    ## read proxy.txt for more info
    #proxy.server = ( ".php" =>
    # ( "localhost" =>
    # "host" => "192.168.0.101",
    # "port" => 80
    #### fastcgi module
    ## read fastcgi.txt for more info
    ## for PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini
    #fastcgi.server = ( ".php" =>
    # ( "localhost" =>
    # "socket" => "/var/run/lighttpd/php-fastcgi.socket",
    # "bin-path" => "/usr/bin/php-cgi"
    #### CGI module
    cgi.assign = ( ".pl" => "/usr/bin/perl",
    ".cgi" => "/usr/bin/perl" )
    #### SSL engine
    #$SERVER["socket"] == "0.0.0.0:443" {
    ssl.engine = "enable"
    ssl.pemfile = "/etc/ssl/private/lighttpd.pem"
    # server.errorlog = "/var/log/lighttpd/error-ssl.log"
    # accesslog.filename = "/var/log/lighttpd/access-ssl.log"
    # server.document-root = "/home/lighttpd/html-ssl"
    #### status module
    #status.status-url = "/server-status"
    #status.config-url = "/server-config"
    #### auth module
    ## read authentication.txt for more info
    #auth.backend = "plain"
    #auth.backend.plain.userfile = "lighttpd.user"
    #auth.backend.plain.groupfile = "lighttpd.group"
    #auth.backend.ldap.hostname = "localhost"
    #auth.backend.ldap.base-dn = "dc=my-domain,dc=com"
    #auth.backend.ldap.filter = "(uid=$)"
    #auth.require = ( "/server-status" =>
    # "method" => "digest",
    # "realm" => "download archiv",
    # "require" => "user=jan"
    # "/server-config" =>
    # "method" => "digest",
    # "realm" => "download archiv",
    # "require" => "valid-user"
    #### url handling modules (rewrite, redirect, access)
    #url.rewrite = ( "^/$" => "/server-status" )
    #url.redirect = ( "^/wishlist/(.+)" => "http://www.123.org/$1" )
    #### both rewrite/redirect support back reference to regex conditional using %n
    #$HTTP["host"] =~ "^www\.(.*)" {
    # url.redirect = ( "^/(.*)" => "http://%1/$1" )
    # define a pattern for the host url finding
    # %% => % sign
    # %0 => domain name + tld
    # %1 => tld
    # %2 => domain name without tld
    # %3 => subdomain 1 name
    # %4 => subdomain 2 name
    #evhost.path-pattern = "/srv/http/vhosts/%3/htdocs/"
    #### expire module
    #expire.url = ( "/buggy/" => "access 2 hours", "/asdhas/" => "access plus 1 seconds 2 minutes")
    #### ssi
    #ssi.extension = ( ".shtml" )
    #### rrdtool
    #rrdtool.binary = "/usr/bin/rrdtool"
    #rrdtool.db-name = "/var/lib/lighttpd/lighttpd.rrd"
    #### setenv
    #setenv.add-request-header = ( "TRAV_ENV" => "mysql://user@host/db" )
    #setenv.add-response-header = ( "X-Secret-Message" => "42" )
    ## for mod_trigger_b4_dl
    # trigger-before-download.gdbm-filename = "/var/lib/lighttpd/trigger.db"
    # trigger-before-download.memcache-hosts = ( "127.0.0.1:11211" )
    # trigger-before-download.trigger-url = "^/trigger/"
    # trigger-before-download.download-url = "^/download/"
    # trigger-before-download.deny-url = "http://127.0.0.1/index.html"
    # trigger-before-download.trigger-timeout = 10
    ## for mod_cml
    ## don't forget to add index.cml to server.indexfiles
    # cml.extension = ".cml"
    # cml.memcache-hosts = ( "127.0.0.1:11211" )
    #### variable usage:
    ## variable name without "." is auto prefixed by "var." and becomes "var.bar"
    #bar = 1
    #var.mystring = "foo"
    ## integer add
    #bar += 1
    ## string concat, with integer cast as string, result: "www.foo1.com"
    #server.name = "www." + mystring + var.bar + ".com"
    ## array merge
    #index-file.names = (foo + ".php") + index-file.names
    #index-file.names += (foo + ".php")
    #### include
    #include /etc/lighttpd/lighttpd-inc.conf
    ## same as above if you run: "lighttpd -f /etc/lighttpd/lighttpd.conf"
    #include "lighttpd-inc.conf"
    #### include_shell
    #include_shell "echo var.a=1"
    ## the above is same as:
    #var.a=1
    The site is running over https with a self signed ssl-cert, if that matters. If I try to upload a file, the browser just quickly reloades the page, the filename still in the input field. The file isn't uploaded and the page that the script should display when completed doesn't show neither.
    Does anyone know how to troubleshoot this? I'm not getting any errors, it just doesn't work..

    I haven't used Websphere before so I can't say much about that. Try putting <%@ page language="Java" %> at the top of your jsp page.
    Try putting your java files into a package and see if that helps. I read somewhere that Tomcat once had issues with running classes that weren't in a package. Make sure to put the package statement at the top of your Java files if you do.
    Websphere says it caught an unhandled exception. Instead of having your method throw and Exception put your code in a try-catch block and then print a stack trace to see if it says anything when it trys to read and write data.
    Try{
        PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("doUpload.txt")));
        ServletInputStream in = request.getInputStream();
        int a=0;
        a=in.read();
        while (a!= -1){
            pw.print((char) a);
            a=in.read();
        pw.close();
    }catch(Exception e){
      e.printStackTrace();
    }Sorry I can't really give you more help.
    -S-

  • XML file is not being displayed in browser? Why?

    Hi all!
    I have a secnario file->XI->J2EE appl.
    I am using  File sender adapter and HTTP Receiver adapter.
    I placed XML file in D:\somedir of my machine, it is picking up well by XI, <b>all i want to know is how XI sends this XML file to my J2EE Appl.</b>Because my servlet should display the same XML file in browser. I deployed my J2EE appl on weblogic application server9.0 I am getting the following error:
    The XML page cannot be displayed
    Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
    XML document must have a top level element. Error processing resource 'http://localhost:7001/Invoke/DisplayRes'.
    These are settings that i have given in my Receiver HTTP adapter:
    Aadapter Type: HTTP
                       Receiver
    Transport Protocol:  HTTP1.0
    Message Protocol:    XI payload in HTTP body
    Adapter Engine:      Integration Server
    Addressing Type:     URL address
    Target host:         localhost
    Service Number:      7001(Port number of Weblogic appl server--where my J2EE appl is deployed).
    Path     :  /Invoke/DisplayRes/(Context path of J2EE appl)
    Authentication Type:Use Logon Data for SAP System
    Content Type: text/xml
    Username:   xiappluser
    password:   xx
    XML code:   UTF-8
    This is my Servlet code:
    public class DisplayRes extends HttpServlet {
         public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
         doPost(request,response);
         public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
         BufferedReader brin =new BufferedReader(new InputStreamReader(request.getInputStream()));
         String inputLine;
         StringBuffer sBuf = new StringBuffer();
         PrintWriter out = response.getWriter();
         response.setContentType("text/xml");
         while ((inputLine = brin.readLine()) != null)
             sBuf.append(inputLine);
               out.println(sBuf.toString());
              brin.close();
             out.flush();
    Where i went wrong please help me,
    NOTE: I want to know how XI sends XML file to my J2EE appl. I suppose my servlet receives it in request object.If so can i use like:
    response.setContentType("text/xml");
      String xmlFile = request.getParameter("myXMLFile");
      PrintWriter out = response.getWriter();
      out.write(xmlFile);
      out.flush();
      out.close();
    Please help me!
    Thanks a lot!

    Hi Datta,
    You seem to have big problem with this scneario as you have raised this question couple of times , in couple of topics / threads. I will try to make a few things about this clear.
    1. XI when sends data to a J2EE application , in your case a servlet, I believe you must be using a HTTP adapter to post the data to it. Whenever XI will post a XML data to a HTTP resource , it will post it as the request body and that is why the code in one of my previous post reads,
    BufferedReader brin =new BufferedReader(new InputStreamReader(request.getInputStream()));
    String inputLine;
    StringBuffer sBuf = new StringBuffer();
    PrintWriter out = response.getWriter();
    response.setContentType("text/xml");
    while ((inputLine = brin.readLine()) != null)
    sBuf.append(inputLine);
    out.println(sBuf.toString());
    brin.close();
    out.flush();
    If you 've noticed, the statement
    request.getInputStream()
    retrieves the body of the request as binary data using a ServletInputStream.
    So your answer to your question is
    <b>XI transferes data to a servlet as a part of HTTP request body</b>, if you use a HTTP adapter.
    2. By J2EE application , if you mean a server java proxy, then the method whose name matches with that of the Inbound Message interface recieves a parameter , from which you can retrieve the parameters passed by XI. Just check the getters of that object.
    Hope this clears your basic doubts!!!
    Rgds,
    Amol

Maybe you are looking for

  • From-outcome not working

    Hi, I have <navigation-rule>      <from-view-id>/dys/pages/config/sucks.jsp</from-view-id>      <navigation-case>           <description>           This shit is so buggy it sucks           </description>      <from-outcome>done</from-outcome>      <t

  • Master Detail form in APEX 3.1

    Hi, I am a bit new to the wonders of APEX (Only 1 project behind me). On my current project I need to make a Master-Detail so I used the APEX template for that. However I have trouble setting my foreign key value in the detail table. Table setup is l

  • Transformation from multiple elements to multiple instances of same element

    I have to do a transformation where some elements in the source side has to be mapped into multiple instances of an element which has name-value pair elements. For example source has element1 element2 element3 element4 Target has elementspecgroup (0-

  • Missing Images Grey Box with ?

    Have tried drills to view inserted images in 4-page Pages doc, going thru Finder to view, reinsertion of images, trashed com.apple.iwork.Pages.plist,,reinstalled iworks '05 CD, upgraded to 1.0.2, read copious discussions from gurus, still no joy. Ima

  • FOP: unknown font ... problems whith multiple threads

    I know that FOP (0.20.5) is not fully threadsafe, so I followed the suggested actions to minimze problems and even serialized the core FOP processing in my report threads: /** Semaphore to synchronize FOP processing. */ static private final Object fo