How does a servlet read incoming XML??

how does a servlet read incoming XML??
thanks in advance
annie
Message was edited by:
annie613

Hi, anyone have an example code of sending a file to servlet and receiving the file in servlet?
I have a JUNIT TEST wit the following code:
==========================================
               HttpURLConnection connection = (HttpURLConnection) url.openConnection();
               connection.setDoOutput(true);
               connection.setDoInput(true);
               connection.setAllowUserInteraction(false);
               connection.setRequestMethod("POST");
               out = new DataOutputStream(connection.getOutputStream());
               BufferedReader reader = new BufferedReader(new FileReader(
                         "/Performance.zip"));
               String line = null;
               while ((line = reader.readLine()) != null) {
                    out.write((line + "\n").getBytes());
               out.close();
               // Read Response
               InputStream in = connection.getInputStream();
               int x;
               while ((x = in.read()) != -1) {
                    System.out.write(x);
               in.close();
               BufferedReader r = new BufferedReader(new InputStreamReader(in));
               StringBuffer buf = new StringBuffer();
               while ((line = r.readLine()) != null) {
                    buf.append(line);
=================================================
and my SERVLET code is like following:
               ServletInputStream in = request.getInputStream();
               parameters = request.getParameterMap();
               path += "file_" + request.getSession().getId() + ".zip";
               // write the input stream to file
               OutputStream fileOut = new FileOutputStream(path);
               CRC32 crc = new CRC32();
               long size = 0;
               int read;
               byte[] buf = new byte[8 * 1024];
               while ((read = in.read(buf)) != -1) {
                    fileOut.write(buf, 0, read);
                    size += read;
                    crc.update(buf);
Still when reading the InputStream, nothing is received in the servlet.
Any idea how to fix it?
thanks,
Jari

Similar Messages

  • How does the DAQmx read.vi work in producer/consumer mode

    Dear all,
    I have one question: how does the DAQmx read.vi work in producer/consumer mode ? 
    I mean if i set the acquisition samples quantity is 5000,(see the enclosed picture), how does the DAQmx read.vi acquire the samples ?
    5000 samples one time ?
    And how does the write. vi work ? Also 5000 samples one time ?
    Look forward to your reply.
    Thank you.
    Attachments:
    producer consumer mode.png ‏28 KB

    It will read 5000 samples per channel.
    The Write Measurement File just writes whatever you give it.  It you send it 5000 data points, it will write the 5000 data points.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How does one uninstall Reader 9.4.5

    How does one uninstall Reader 9.4.5

    You may want to try the following:
    Run this fix from Microsoft: http://support.microsoft.com/mats/Program_Install_and_Uninstall
    Uninstall Reader using Add/Remove Programs
    If you want to reinstall Reader, download it from http://get.adobe.com/reader/direct/

  • How does JDBC adapter reads or writes the data to DB

    Hi All,
             How does JDBC adapter read the data from a db, is it that it collects all the data in one go and sends to XI, or is it record by record.  And what if it writes to a db?
    Xier

    Hi,
    It collects all record at one time and while writing to DB you can push all data at one go...
    We are using receiver JDBC adapter to push data to DB and its one go..
    Nilesh

  • How does the servlet implement the multi-thread feature?

    There is only one instance of every servlet in one wep application.
    When several clients invoke the doPost() method of the same servlet,the servlet can process their request respectively.
    So there much multi threads of one servelt.
    But the Servlet doesn't implement the Runnable interface of extends the Thread class.
    I wan't to know,how does the servlet/servlet container implement the multi-thread feature?

    Hi johnnylzb
    There is only one servlet instance existing.
    (assuming u have <load-on-startup>1</load-on-startup>)
    The server creates a thread for every request ..
    and all the threads access the same servlet instance.
    For this its not necessary for the Servlet to extend Thread or Runnable.
    hope this helps

  • How does a servlet close the browser window?

    How can a servlet close the browser window it is running in?

    I'm running the servlet by calling it in a browser window, passing parameters using POST, with the parameters appearing at the end of the url.
    Is there another way to run the servlet, without it affecting the browser window? That would be a better solution.

  • How does SQL*PLUS read script files

    Hello!
    well, it is possible to start sqlplus with an sql script file:
    sqlplus user/pass@srv @my_script.sqlok, so what happens if I delete the file my_script.sql ?
    My script here is about 1 GB big! sqlplus was half way done when I deleted the file.
    Is the sqlplus going to stop with an error? Or just hang?
    I copied the my_script.sql file now to the folder again and I think that sqlplus is still working fine. But can I be sure, that all statements in the script have been processed?
    Thanks in advance!

    Results are OS dependent which you declined to share with us.
    I suspect *NIX & not Windoze.
    On Windoze, you can not delete open file.
    On *NIX open file does not actually get deleted until fclose() is called.
    All in all, you are OK.

  • How does enhance thin line work on Adobe reader X?

    Hi there,
    I noticed a display difference between different PDF readers. Especially in the rendering of thin line weights and widths and after a little research I discovered that Adobe reader X has a option called "enhance thin line", which when turned on (turned on by default) it seems to thicken/enbolden the thin lines.
    Option is under "Edit->Preferences->Display->Enhance thin line
    Opening these in a different PDF reader like PDFill you notice the same lines are thin by default and I assume this is how the drawing creator originally intended the viewer to see it.
    My question is, is this setting only affect the electronic display? i.e. monitors and laptops screens or does this setting also affect the output print?
    Also how does the Adobe reader decide which lines to articifically increase and which ones to leave alone and also by what level does it increase the lines to?
    Does the reader parse the file and checks for any line widths that are for example less than 0.5 in width and then add .2 to all these lines?
    Many questions I know but I just hope someone has some answers
    Many thanks in advance.

    Been searching around the internet but still can't find a answer, can anybody help?

  • How to read an XML from a servlet?

    Hi,
    I'm just starting programming and now I have a problem I can't solve. I hope someone can help me.</p>
    On the client side I have a xml report and a script wich sends to the server the information I've got from the report. In this case, the 'Poliza' value.
    On the server-side I have a servlet. I try to get the parameters (from the URL or from the XML), but I don't have any response on the client side. I'm sure I'm doing something wrong but I can't find the solution for solving it.
    I suppose there are two ways of solving the problem.
    - Make an http connetion and send just the parametes on the URL? Does anyone know how to make it?
    - Reading the XML on the servlet and extract the parameters the script sent. Does anyone know how to read it?
    Thank you in advance
    I attach part of the code.
    CLIENT SIDE
    <report....>
    <field sortid="0" id="Poliza" inputtype="textbox" label="Poliza" rows="1" wide="false" required="false"/>
    </report>
    <script name="ValidacionOnlineValidation1" script="if (0 == 0){
    var szURL="http://URLServer/vonline/vonline?Poliza="+Poliza.value;
    var szUserAgent = "JoP-XML_Posting_v1.0";
    var m_XML;
    /* In the line below, construct a XML-document that contains all the information you need to send to the server*/
    var szXML = "<?xml version=\"1.0\"?><data><objects><object name=\"Poliza\" value=\"123456789\"/></objects></data>";
    /* Create an instance of the MS XML Document Object Model Parser*/
    m_XML= new ActiveXObject("Microsoft.XMLDOM");
    m_XML.validateOnParse=true;                                                                                                         
    var bLoadResult = m_XML.loadXML(szXML);
    if (bLoadResult==true) {
      /*Instance of the transport object, method,...*/
      var m_HttpReq = new ActiveXObject("Pocket.HTTP");
      m_HttpReq.method = "GET";
      m_HttpReq.Headers.create("Content-Type", "text/xml");
      m_HttpReq.Headers.find ("User-Agent").Value = szUserAgent;
      m_HttpReq.timeout = 150000;
      /*Do the actual post of the data*/
      var m_HttpResponse = m_HttpReq.GetResponse(szURL,m_XML.xml);
      if (m_HttpResponse.statusCode==200) {...}
    SERVER SIDE
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
         String Error="";
         String MSG = "";
         response.setContentType("text/html");
         PrintWriter out1 = response.getWriter();
         Enumeration arrayparametros = request.getParameterNames();
         for (;arrayparametros.hasMoreElements();){
              String parametro = (String)arrayparametros.nextElement();
              String valorparametro = request.getParameter(parametro);
              if (parametro.equals("Poliza")){
                   vonlineLogica logica = new vonlineLogica();
                   LOGS ="on";
                   Respuesta respuesta = logica.procesarSolicitud(request,valorparametro);
                   Error = Respuesta.getError();
                   MSG = Respuesta.getMensaje();
              else{          
                   Error = parametro; MSG = valorparametro;
                   String[] values = request.getParameterValues(parametro);
         out1.println("Result: " + Error + " / " + MSG);
         out1.close();                    
    }

    Thanks by your help Shanu.
    Nevertheless, finally I tryed the easiest way (pass the parameter with 'GET'). Moreover I found why my code wasn't working. It was a fool thing. I though PDA connect throught a proxy, but it wasn't true. Whatever.
    Regards.
    FSG.
    The final script on the xml-report is:
    <report type="Validacion Online" required="false" multiple="false" attachments="false" scriptref="store://this/reportdef/script[@name='ValidacionOnlineValidation1']">
         <field sortid="0" id="Poliza" inputtype="textbox" label="Poliza" rows="1" wide="false" required="false"/>
    </report>
    <script name="ValidacionOnlineValidation1" script="if (0 == 0)
    var szURL="http://URL/vonline/vonline?parameter1=";+Poliza.value;                         
    var m_HttpReq = new ActiveXObject("Pocket.HTTP");                                             m_HttpReq.timeout = 15000;
    var m_HttpResponse = m_HttpReq.GetResponse(szURL,"");
    window.alert(m_HttpResponse.string);
    if (m_HttpResponse.statusCode==200)  {....}
    else {....}

  • How to send incoming XML as mail-attachment

    Hi Experts,
    I have the following scenario: an incoming XML-file should be send as attachment of a mail. Now, I have defined incoming message with the structure of the xml-message and outgoing message as mail-package. In the message mapping I fill the nessesary mail-fields. In my receiver comm.channel (mailadapter) I checked "Use mail package" and "Keep attachment".
    Result is that the mail is created and send ok, but without attachment....what am I doing wrong here?
    Regards,
    William

    Hi JWD,
    You should configure the mail adapter with 'use the mail adpater' and 'keep attachments'.
    Create an XML file conform the XML structure provide by SAP
    The mail package should look like this:
    <?xml version="1.0" encoding="utf-8"?>
    <ns:MT_Mail_Sent xmlns:xi="http://sap.com/xi/XI/Mail/30">
    <xi:Mail>
    <Subject>Item</Subject>
    <From>MAIL ADDRESS</From>
    <To>MAIL ADRESS</To>
    <Content_Type>multipart/mixed; boundary="AaBb--984dfgeSSd3532"</Content_Type>
    <Content_Disposition>attachment</Content_Disposition>
    <Content>
    AaBb984dfgeSSd3532
    Content-Type: text/plain
    this is sample data.
    AaBb984dfgeSSd3532
    Content-Type: text/plain;name="CSV_data.csv"
    Order number;Item number;description<xsl:text> </xsl:text>
    <xsl:for-each select="Article_line">
    <xsl:value-of select="Ord_nmbr"/>;<xsl:value-of select="Item_nmbr"/>;<xsl:value-of select="Description<xsl:text>
    </xsl:text></xsl:for-each>
    AaBb984dfgeSSd3532
    Content-Type: text/plain;name="TXT_data.txt"
    Order number;Item number;description<xsl:text> </xsl:text>
    <xsl:for-each select="Article_line">
    <xsl:value-of select="Ord_nmbr"/>;<xsl:value-of select="Item_nmbr"/>;<xsl:value-of select="Description<xsl:text> </xsl:text></xsl:for-each>
    AaBb984dfgeSSd3532
    </Content>
    </xi:Mail>
    </ns:MT_Mail_Sent>
    In the above example you should have some content and 2 attachments (1 csv file and 1 txt file).
    After each break (AaBb984dfgeSSd3532) specify again the 'Content-Type'.
    *When you want to send a message payload as described, you have to set in the mail receiver channel the parameter Content Encoding to None and uncheck Keep Attachments.
    The last boundary AaBb984dfgeSSd3532 should be omitted, as the mail adapter sets that border itself (tested with SP16)*
    Reward points if this helps
    Regards
    Pragathi.

  • Does income xml request get validated against wsdl?

    Hi, there:
    I'm using document/literal web service. My question is: Does income xml request get validated automatically against wsdl complex type xml schema? If not is there any configuration way we can set to validate income xml request automatically?
    I searched posts in this forum, it seems the same question was asked long long time ago already, but no answer. So, I want to check that question again.
    I simply tested my web service by using soapUI, it seems no xml validation implemented on any request at all.
    Highly appreciated if any help or comment, thanks a lot in advance.
    David

    Thank you very much jwenting for the reply. We are using jbossWs.
    Yes, I definately agree that it's very cool that wsdl is generated on the fly, and all xml message is parsed to java bean automatically by jaxb. However, my 2 cents is:
    1. How can I generate other xml schema restrictions in wsdl on the fly except "enum" (ex. pattern, minInclusive, maxInclusive etc.)? Currently, it seems only @XmlEnum can generate "enum" restriction in wsdl automatically, no other restrictions could be generated automatically in wsdl.
    2. Even if I have those restrictions defined manually in wsdl, as it doesn't implement validation on income xml request, and I should do the validation inside my webservice logic, which means that even if I have those xml schema restrictions defined in wsdl, they are useless.
    That's the reason I want to check if anyway the validation can be implemented automatically on income xml request.
    Again, highly appreciated any further helps or comments. Thanks a lot in advance.
    David

  • What are JSP, Servlet , Bean in MVC ??..how does it function?

    suppose there's a bean file (.java) consisting of SQL query, and a servlet (.java) used to show an image, and lastly a jsp page when clicked shows the image.............can you please explain how does this work,how the logic flows,what happens step by step.....i really need to understand this, thankz.

    A JSP page is essentially an easy way to create an abstract behind the scenes servlet where its whole purpose is to serve HTML. JSP tags and java code within the page are processed on the server side first and then a response is sent containing the HTML.
    The JSP can send its request to another handler or servlet that can do the processing.
    I don't understand where a java bean comes into play in this situation.

  • How does Servlet Multithreads work?

    Currently I am trying to make a little server that works as a DatagramSocket server. Whenever it receives the packet, it spawns a thread and this thread will take care of this packet. However, this thread class implements Runnable, and it has class variable of Packet. So to run the thread, I do like:
    PacketRouter rp = new PacketRouter(packet);
    Thread t = new Thread(rp);
    r.start();
    However, in PacketRouter, Packet is a class variable, which could be inconsistent when reading or updating this class variable in another thread. The situation reminds my memory of a Servlet. A container creates a new thread of my servlet to serve particular Request.
    My question is, how does the container pass this Request object down to the servlet's "service" method when run() has no parameter? Thanks.

    Sorry but it seems you did not understand Threading that well - why do you start an own Thread for each packet? A servlet-server already creates a Thread for each request - so you can have even hundreds of requests running (practically) at the same time.
    Furthermore you are in a new Thread so you can't "pass" anything down, the only thing is to wait until this thread would be finished which is ... well plain damn stupid because then you would not need a Thread.
    Good luck, lg Clemens

  • How does XDB optimize XML Query?

    I found the query speed of XDB is much slower than Berkeley XML DB.
    How does XDB optimize XML Query?
    Are there any documents on this subject?
    And can XDB create indices on XMLType ( e.g. the index on element/attribute value and/or structure index)? if yes, how to do that?

    lezhou had a valid question and asked about:
    "I found the query speed of XDB is much slower than Berkeley XML DB"
    "How does XDB optimize XML Query?"
    These point to a "XML DB Concepts Guide", which does not yet exist.
    The procedures are explained, the methods are explained. If you enable event tracing as described in the XMLDB Developers Guide 10gR2, you will see statements in your trace file which will tell you more about the XML DB architecture (and therefor you can deduct performance impact) then the manual will reveal.
    An other example:
    The xdbconfig.xsd file is neatly explained - in regards of http-port-etc
    But not what the implecations are if you alter one of the other ones (the not explained parameters).
    If you know the architecture (GROUND LEVEL), you can give an correct answer to the initial question "I found the query speed of XDB is much slower than Berkeley XML DB. How does XDB optimize XML Query?"
    The balanced tree index is constructed the same way (on the same theory) in Oracle, DB2, but apparantly X is faster because in with the same buildup/architecture/databasestructure for both products, with the same data, with the same X --> value Y is beter constructed and delivers a better performance.
    apples = apples
    oracle xmldb = berkeley xmldb --> how can i test the o.apples=b.apples and that under these circumstances o.apples are faster ;-)
    THEREFOR:
    "I have to disagree a little bit...("It speaks about all these in detail").
    Still waiting for the XMLDB Concepts Guide / Administrators Guide / Performance Guide.

  • How to binding incoming xml node list to the tree control as dataProvider

    Recently, I faced into one issue: I want to binding incoming xml node (it's not avaliable at start) list to the tree control as a dataProvider.
    Since the incoming xml node list is not avaliable at beginning but I needs to bind it to the tree, so I create one virtual one in the xml, and prepare to remove it before the tree is shown. (ready for the actual node adding). But It did not work.
    Please see the presudo-code here:
    1.  Model layer(CsModel.as)
    public class CsModel
            [Bindable]
            public var treeXML:XML=<nodes><car label="virtualOne" id="1">
                                   </car></nodes>;
            (Here, I want to build binding relationship on the <car/> node,
             one 'virtual/stub' node is set here with lable="virtualOne".
             But this node will be deleted after IdTree
             control is created completely.)      
            [Bindable]
            public var treeData:XMLList =new XMLListCollection(treeXML.car);
    2. view layer(treePage.mxml)
            private var _model:CsModel = new CsModel();
            private function addNode():void
                    var newNode:XML=<car/>;
                    newNode.@label="newOne";
                    newNode.@id=1;
                    _model.treeXML.appendChild(newNode);
                             private function cleanData():void
                                     delete _model.treeXML.car;
            <mx:VBox height="100%" width="100%">
            <mx:Button label="AddNode" click="addNode()" />
            <mx:Tree id="IdTree"  labelField="@label"
              creationComplete="cleanData()"
              dataProvider="{_model}"/>
        </mx:VBox>
    3. Top view layer (App.Mxml)
    <mx:application>
        <treePage />
    </mx:application>
    For method: cleanData(),It's expected that when the treePage is shown, we first delete the virutalOne to provide one 'clear' tree since we don't want show virtualOne to the user. The virutalOne node just for building the relationship between treeData and treeXML at beginning. But the side effect of this method, I found, is that the relationship between treeXML and treeData was cut off. And this leads to that when I added new node (by click the 'addNode' button) to the xmlXML, the xmlData was not affected at all !
    So Is there any other way to solve this issue or bind the incoming xml node list to the xmlListCollection which will be used as Tree control's dataProvider ?

    If u want to display the name : value then u can do like this
    <xsl:eval>this.selectSingleNode("name").nodeName</xsl:eval> : <xsl:value-of select="name" />

Maybe you are looking for

  • Hiccups/hangs with pulseaudio and hd audio ALC883 (ClevoM570RU)

    Hello guys, well, as the topic already says, I'm having problems with pulseaudio combined with an ALC883 hd audio card on a Clevo-M570RU. I got occassional hiccups and hangs and pulseaudio rewinds. For some strange reason I can't kill pulseaudio with

  • Mouse Coordinates and using the getPoint method

    Hello, I have a mouseClicked event that uses the getPoint method to get the coordinates of the mouse. Because the mouse is a shape (the cursor), it contains more than 1 pair of coordinates, so getPoint is supposed to return the coordinates of what is

  • Future course of action

    Hello to you all. My name is Abhik Dhar and I am from West Bengal, India. I am a B.com (Hons) student and I want to become an SAP (FI/CO) consultant. Since my graduation course is going to be complete in a few months time, what course should I enroll

  • Bbb file

    Why would it save my backup in a .bbb file on a Windows computer?

  • Problem with alias

    I've two tables. Table One contains 3 columns A,B,C where A is the Primary key. Table Two contains A,D,E where A is the foreign key. Select * from One,Two where One.A=Two.A So when I create a custom folder using above SQL ,it would say it is Not Vali