Sending xml file from client to servlet

Hi,
I am writing the server component of an applcation, such that it will receive xml files from the clients(standalone application similar to javaSwing stuff but it's coded in C#), and the servlet will have to extract the data from the xml file and update the mySql database. it will also fulfill the client's request for xmlFiles (and extract data from DB, format to xml file and send back to client)
I'm new to implementing the servlet receiving files from clients so would need some help.
I've got 3 questions to ask:
1) How does the servlet receive/returns the xml file from the client as a series of httpPost request/response. Do i send a File or the file's contents as a String to/from the client?
2) Is it also a must to use socket for the file transfers? I have read in other posts about sockets as well as HttpURLConnection but i don't quite understand.
3) When I send a file back to the client(client is standalone application written in C# whereas server is coded in java), what do i specify for the HttpResponse.setContentType() in my servlet? (i'm returning the xml file to client)
Would really appreciate for any help rendered. If you have any useful links, would appreciate them too. Thanks a lot.
Karen

I've got 3 questions to ask:
1) How does the servlet receive/returns the xml file
from the client as a series of httpPost
request/response. Do i send a File or the file's
contents as a String to/from the client?The server will listen on some port for requests. The client has to open a socket to this server to send the file as string to the server.
see http://java.sun.com/docs/books/tutorial/networking/index.html
>
2) Is it also a must to use socket for the file
transfers? I have read in other posts about sockets as
well as HttpURLConnection but i don't quite
understand.You use HttpURLConnection to make a request using the http protocol, instead of opening a socket and then writing the html headers yourself.
3) When I send a file back to the client(client is
standalone application written in C# whereas server is
coded in java), what do i specify for the
HttpResponse.setContentType() in my servlet? (i'm
returning the xml file to client)Its up to your receiving program how to interpret this though, so you probably dont need this.

Similar Messages

  • Send xml file from sap to third party url through https

    Hi,
    I have a requirement to send the xml file from ecc to a 3rd party url through HTTPS. How can we achieve this using ABAP.
    Client doesn't have XI enviroment. The client has provided the 3rd party url where the file needs to be uploaded.
    Please help ! <removed by moderator>
    Thanks in advance.
    Regards,
    Chitra.K
    Edited by: Thomas Zloch on Sep 12, 2011 12:58 PM

    Hi Chitra,
    I had similar requirement and here is what I did: -
    REPORT  Z_HTTP_POST_TEST_AMEY.
    DATA: L_URL               TYPE                   STRING          ,
          L_PARAMS_STRING     TYPE                   STRING          ,
          L_HTTP_CLIENT       TYPE REF TO            IF_HTTP_CLIENT  ,
          L_RESULT            TYPE                   STRING          ,
          L_STATUS_TEXT       TYPE                   STRING          ,
          L_HTTP_STATUS_CODE  TYPE                   I               ,
          L_HTTP_LENGTH       TYPE                   I               ,
          L_PARAMS_XSTRING    TYPE                   XSTRING         ,
          L_XSTRING           TYPE                   XSTRING         ,
          L_IS_XML_TABLE      TYPE STANDARD TABLE OF SMUM_XMLTB      ,
          L_IS_RETURN         TYPE STANDARD TABLE OF BAPIRET2        ,
          L_OUT_TAB           TYPE STANDARD TABLE OF TBL1024
    MOVE 'https://<hostname>/xxx/yyy/zzz' TO L_URL.
    MOVE '<XML as string>' TO L_PARAMS_STRING.
    *STEP-1 : CREATE HTTP CLIENT
    CALL METHOD CL_HTTP_CLIENT=>CREATE_BY_URL
        EXPORTING
          URL                = L_URL
        IMPORTING
          CLIENT             = L_HTTP_CLIENT
        EXCEPTIONS
          ARGUMENT_NOT_FOUND = 1
          PLUGIN_NOT_ACTIVE  = 2
          INTERNAL_ERROR     = 3
          OTHERS             = 4 .
    "STEP-2 :  AUTHENTICATE HTTP CLIENT
    CALL METHOD L_HTTP_CLIENT->AUTHENTICATE
      EXPORTING
        USERNAME             = 'testUser'
        PASSWORD             = 'testPassword'.
    "STEP-3 :  SET HTTP HEADERS
    CALL METHOD L_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD
          EXPORTING NAME  = 'Accept'
                    VALUE = 'text/xml'.
    CALL METHOD L_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD
        EXPORTING NAME  = '~request_method'
                   VALUE = 'POST' .
    CALL METHOD L_HTTP_CLIENT->REQUEST->SET_CONTENT_TYPE
        EXPORTING CONTENT_TYPE  = 'text/xml' .
    "SETTING REQUEST DATA FOR 'POST' METHOD
    IF L_PARAMS_STRING IS NOT INITIAL.
       CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
         EXPORTING
             TEXT   = L_PARAMS_STRING
         IMPORTING
               BUFFER = L_PARAMS_XSTRING
         EXCEPTIONS
            FAILED = 1
            OTHERS = 2.
    CALL METHOD L_HTTP_CLIENT->REQUEST->SET_DATA
        EXPORTING DATA  = L_PARAMS_XSTRING  .
    ENDIF.
    "STEP-4 :  SEND HTTP REQUEST
      CALL METHOD L_HTTP_CLIENT->SEND
        EXCEPTIONS
          HTTP_COMMUNICATION_FAILURE = 1
          HTTP_INVALID_STATE         = 2.
    "STEP-5 :  GET HTTP RESPONSE
        CALL METHOD L_HTTP_CLIENT->RECEIVE
          EXCEPTIONS
            HTTP_COMMUNICATION_FAILURE = 1
            HTTP_INVALID_STATE         = 2
            HTTP_PROCESSING_FAILED     = 3.
    "STEP-6 : Read HTTP RETURN CODE
    CALL METHOD L_HTTP_CLIENT->RESPONSE->GET_STATUS
        IMPORTING
          CODE = L_HTTP_STATUS_CODE
          REASON = L_STATUS_TEXT  .
    WRITE: / 'HTTP_STATUS_CODE = ',
              L_HTTP_STATUS_CODE,
             / 'STATUS_TEXT = ',
             L_STATUS_TEXT .
    "STEP-7 :  READ RESPONSE DATA
    CALL METHOD L_HTTP_CLIENT->RESPONSE->GET_CDATA
            RECEIVING DATA = L_RESULT .
    "STEP-8 : CLOSE CONNECTION
    CALL METHOD L_HTTP_CLIENT->CLOSE
      EXCEPTIONS
        HTTP_INVALID_STATE = 1
        OTHERS             = 2   .
    "STEP-9 : PRINT OUTPUT TO FILE
    CLEAR : L_XSTRING, L_OUT_TAB[].
    CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
        EXPORTING
          TEXT   = L_RESULT
        IMPORTING
          BUFFER = L_XSTRING
        EXCEPTIONS
          FAILED = 1
          OTHERS = 2.
    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
      EXPORTING
        BUFFER                = L_XSTRING
      TABLES
        BINARY_TAB            = L_OUT_TAB .
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
       FILENAME                        = 'C:AMEYHTTP_POST_OUTPUT.xml'
      TABLES
        DATA_TAB                        = L_OUT_TAB .
    Also, following is the detailed link for use of HTTP_CLIENT class: -
    http://help.sap.com/saphelp_nw70ehp1/helpdata/EN/1f/93163f9959a808e10000000a114084/content.htm
    Also, in below link, you can ignore XI specific part and observe how its sending XML to external URL:-
    (I know it describes call to SAP XI server's URL, but it can be used to call any URL)
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/ae388f45-0901-0010-0f99-a76d785e3ccc
    In addition to all above, following configs to be present at ABAP application server: -
    1. The hostname used to URL should be present in SAP ABAP application server's 'hosts' file.
    2. Security certificate (if available) for URL to be called must be installed in SAP ABAP application server.
    Let me know if you achieve any progress with it...

  • How to send xml file from local folder to azure storage

    Hi,
    My plan is i have xml files which are under folders in my local.
    I want to use mobile service to send xml files to azure storage,
    how shall i do that, either by c# or mobile service.
    If internet stop, I will use my mobile service to transfer all xml files to azure storage and run web job to do to update azure
    sql by xml file.
    please advice.
    Superman

    Hi,
    You could refer the following link for assistance with uploading image files to Azure Blob Storage using Mobile Services:
    http://azure.microsoft.com/en-us/documentation/articles/mobile-services-windows-phone-upload-data-blob-storage/
    And for image files you could refer the following link:
    http://stackoverflow.com/questions/25977406/upload-a-text-file-with-azure-mobile-services
    Regards,
    Malar.

  • Help: question on send XML file from java client to java server

    Hi, I am now to Java, and now I am going to set up a simple network in the lab.
    I have created a random array of data and transferred to XML file on my client. Now, I would like to send it to the server. I am wondering how I can put the XML file into my client, and do I need any parser to let the server show what random date it has received?
    Anybody can give me any idea or some basic code? Thank you.
    Now, I am referring the KnockKnock example in Java online tutorial. But, not clear how to deal with the XML File.
    Fengyuan

    There are several ways you can achieve this: one could be that you transfer data over HTTP, using Servlets for instance. Have a Servlet listening on the Server with content type 'text/xml', POST the XML data to the server and have the Servlet to receive the data and re-compose the XML file. This can be achieved with different libraries:
    1) JAXB --> this is good because is the JDK standard, also for web services
    2) Castor (http://www.castor.org/)

  • How can i send xml file with a http servlet request

    Hi
    Please tell me how can I send a xml file into http servlet request.
    I have a servlet(action) java file.From this servlet I have generate a xml file. Now I need to send that xml file to another servlet with http servlet request object.
    Dave.

    When you say you have generated an XML file what do you mean?
    Is it a file stored on disk? Then pass the file path as a string to the servlet.
    Is it stored in memory as an object? The pass a reference to the object to the servlet.
    Or are you asking how to communicate between servlets?
    Look in the JavaDocs for the RequestDispatcher class. You can use this class to forward the request to another servlet. Data can be passes using the RequestDispatcher by storing it as attributes using the request getAttribute and setAttribute methods. Also described in the JavaDOcs.
    http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/RequestDispatcher.html

  • Sending a file from Applet to servlet HELP me Please

    Sorry, i have the problem this is my code Applet & Servlet but it seems working asynchronously if you have some ideas please reply me i send bytes on outputstream but the inputstream of servlet receive nothing bytes but write my system.out.print on screen server:
    Applet:
    URL servletURL = new URL(codebase, "/InviaFile/servlet/Ricevi");
    HttpURLConnection urlConnection = (HttpURLConnection) servletURL.openConnection();
    urlConnection.setRequestMethod("POST");
    urlConnection.setUseCaches(false);
    urlConnection.setDoOutput(true);
    urlConnection.setDoInput(true);
    urlConnection.setAllowUserInteraction(false);
    urlConnection.setRequestProperty("Content-Type", "application/octet-stream");
    urlConnection.setRequestProperty("Content-length", String.valueOf(100));
    urlConnection.connect();
    if(urlConnection.HTTP_BAD_REQUEST == HttpURLConnection.HTTP_BAD_REQUEST){
    /*System.out.println("Cattiva Richiesta: "+urlConnection.getContentEncoding());
    System.out.println("Tipo di metodo: "+urlConnection.getRequestMethod());
    System.out.println("Tipo di Risposta: "+urlConnection.getResponseCode());
    System.out.println("Tipo di messaggio: "+urlConnection.getResponseMessage());
    System.out.println("Tipo di contenuto: "+urlConnection.getContentType());
    System.out.println("Tipo di lunghezza contenuto: "+urlConnection.getContentLength());
    System.out.println("Tipo di doinput: "+urlConnection.getDoInput());
    System.out.println("Tipo di doouput: "+urlConnection.getDoOutput());
    System.out.println("Tipo di URL: "+urlConnection.getURL());
    System.out.println("Tipo di propriet� richiesta: "+urlConnection.getRequestProperty("Content-Type"));
    System.out.println("Entra if");
    DataOutputStream dout = new DataOutputStream(urlConnection.getOutputStream());
    InputStream is = urlConnection.getInputStream();
    if(ritornaFile("C:/Ms.tif", dout))System.out.println("Finita lettura");
    dout.close();
    urlConnection.disconnect();
    System.out.println("Fine Applet");
    }catch(Exception e) { System.err.println(e.getMessage());e.printStackTrace();}
    public boolean ritornaFile(String file, OutputStream ots)throws Exception{
    FileInputStream f = null;
    try{
    f = new FileInputStream(file);
    byte[] buf = new byte[4 * 1024];
    int byteLetti;
    while((byteLetti = f.read()) != -1){ots.writeByte(buf, 0, byteLetti);ots.flush();
    while((byteLetti = f.read()) != -1){ots.write(byteLetti);ots.flush();
    System.out.println("byteLetti= "+byteLetti);
    return true;
    }catch(Exception ex){
    System.err.println(ex.getMessage());
    return false;
    }finally{
    if(f != null)f.close();
    Servlet:
    HttpSession ses = request.getSession(true);
    System.out.println("Passa servlet "+request.getMethod());
    System.out.println("Passa servlet "+ses.getId());
    ServletInputStream servletinputstream = request.getInputStream();
    DataInputStream dis = new DataInputStream(request.getInputStream());
    int c = dis.available();
    System.out.println("c="+c);
    //ServletOutputStream servletoutputstream
    //response.getOutputStream();
    response.setContentType("application/octet-stream");
    System.out.println("URI= "+request.getRequestURI());
    System.out.println("pathTranslated: "+request.getPathTranslated());
    System.out.println("RemoteUser: "+request.getRemoteUser());
    System.out.println("UserInRole: "+String.valueOf(request.isUserInRole("")));
    System.out.println("pathInfo: "+request.getPathInfo());
    System.out.println("Protocollo: "+request.getProtocol());
    System.out.println("RemoteAddr:"+request.getRemoteAddr());
    System.out.println("RemoteHost:"+request.getRemoteHost());
    System.out.println("SessionID:"+request.getRequestedSessionId());
    System.out.println("Schema:"+request.getScheme());
    System.out.println("SeesionValido:"+String.valueOf(request.isRequestedSessionIdValid()));
    System.out.println("FromURL:"+String.valueOf(request.isRequestedSessionIdFromURL()));
    int i = request.getContentLength();
    System.out.println("i: "+i);
    ritornaFile(servletinputstream, "C:"+File.separator+"Pluto.tif");
    System.out.println("GetMimeType= "+getServletContext().getMimeType("Ms.tif"));
    InputStream is = request.getInputStream();
    int in = is.available();
    System.out.println("Legge dallo stream in="+in);
    DataInputStream diss = new DataInputStream(servletinputstream);
    int ins = diss.read();
    System.out.println("Legge dallo stream ins="+ins);
    int disins = diss.available();
    System.out.println("Legge dallo stream disins="+disins);
    is.close();
    System.out.println("Fine Servlet");
    catch(Exception exception) {
    System.out.println("IOException occured in the Server: " + exception.getMessage());exception.printStackTrace();
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    processRequest(request, response);
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    processRequest(request, response);
    /** Returns a short description of the servlet.
    public String getServletInfo() {
    return "Short description";
    public void ritornaFile(InputStream its, String fileDest )throws Exception{
    FileOutputStream f = null;
    try{
    f = new FileOutputStream(fileDest);
    byte[] buf = new byte[2 * 1024];
    int byteLetti;
    while((byteLetti = its.read()) != -1){
    f.write(buf, 0, byteLetti);
    f.flush();
    System.out.println("Byteletti="+byteLetti);
    }catch(Exception ex){
    System.err.println(ex.getMessage());
    }finally{
    if(f != null)f.close();

    Hi all,
    Can anyone help me.I am trying to send an audio file from a applet to servlet with HTTP method(no raw sockets), also the servlet shld be able to save the file on the server.Any suggestions welcome.USing audiostream class from javax.sound.sampled.
    The part of applet code which calls servlet is :
    URL url = new URL("http://" + host + "/" + context + "/servlet/UserUpdateWorkLogAudio?userid=" + userId.replace(' ', '+') + "&FileName=" + filename.replace(' ', '+'));
    URLConnection myConnection = url.openConnection();
    myConnection.setUseCaches(false);
    myConnection.setDoOutput(true);
    urlConnection.setRequestProperty("Content-Type", "application/octet-stream");
    myConnection.connect();
    out = new BufferedOutputStream(myConnection.getOutputStream());
    AudioSystem.write(audioInputStream, fileType,out); // IS THIS RIGHT APPROACH?
    ************************end of applet code**********************
    ************************servlet code******************************
    try
    {BufferedInputStream in = new BufferedInputStream(request.getInputStream());
    ????????What code shld i write here to get the audio file stream
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(filename));
    *********************************************end***********************
    Thanks
    Joe.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • [b]Urgent How to send XML file from forms 6.0 to a url to access database[/

    hi
    i need to create an XML with some values file from Oracle Forms 6.0 and then send this XML file To a URL to access the database,which in turn will send me XML file with new values.Can any body help me out as i don't have any ideas
    Regards
    Sunil

    Sunil,
    and this must be using a URL and can't be handled by a database stored procedure ?
    Anyway, your scenario can be achieved using teh Java Importer in Forms 6i and above. You woudl write a Java program that takes a String and loads it to an URL. It then checks the response URL for its content.
    Frank

  • Sending XML file from SAP to Windows Based file server with FTP function

    Hi Gurus,
    We are using SAP BW 3.0B version.
    I need to convert data in ODS to XML format and send this XML file to remote server which  is not a SAP application server, it is just a Window Based file server with FTP function..
    By writing some ABAP code I have converted ODS data into XML format (which gets saved in my local system)
    (Is that I need to put this file in Application Server to send it to the other servers? )
    Now the thing is how I can send this file to that Windows Based file server.
    plz suggest me.... what can be done......
    Thanks in Advance
    Madhusudhan
    Edited by: Madhusudhan Raju on Dec 3, 2009 4:25 AM

    I dont think the above code support windows OS. Because I always execute this script via UNIX.
    I think you can try this option, go to command prompt, goto the destination path where you have an XML file using cd....
    ftp (destination servername), specify the username and password.
    afterthat, use the command put and filename.
    check whether the file had reached destination successfully or not.
    For automation purpose, you can use the following script like
    ftp: -s: test.txt  (servername)
    In test.txt,
    UserName
    Password
    bin
    cd /files
    put file.xml
    bye
    Also, you can check in SM69, there will be some SAP external commands to automate the file transfer.
    Thanks
    Sat
    http://support.microsoft.com/?kbid=96269

  • Send xml file and recieve xml in response from servlet

    hi
    i want to send a xml file to http address and in response recieives an xml file from which i want to fetch value in java
    can everybody help me out by giving me some help code
    thanks
    haryy

    I think you can do this with the DOM API .
    Go through this: http://www.javaworld.com/javaworld/jw-07-2000/jw-0728-jdom2.html

  • Trigger workflow by sending XML-Message from a servlet

    Hi Developers,
    I am currently evaluating WLPI and followed the tutorial provided by BEA. Now
    I try to create a Workflow which is triggered by an XML-Message that is sent by
    a servlet to WLPIs JMS. The 'Programming Client Applications' gave me a hint of
    how to do it. But some parts are missing. Can you recommend a book or tutorial
    which goes beyond the tutorial or give me a hint on that?
    Regards,
    [email protected]

    Looks like the problem is on the client side (MSXML) because I can flawlessly send half-megs XML files from a Servlet to a browser or a java.net.URL

  • Hi How to get XML file from servlet that XI sent to my J2EE appl?

    Hi All!
    I have a scenario like XI sends xml file to j2ee application. In my J2EE application my servlet receives this xml. Will the xml file be in my HTTPServletRequest object? if so how to get that file from Request object.
    Please help me its urgent, Any code help is highly appreciated.
    My xml file will be like this:
    <ns0:Http_Message_Type_Demo
    xmlns:ns0="http://abcdemo.com">
    <Name>ABC</Name>
    <RollNo>123</RollNo>
    <Address>a-4</Address>
    </ns0:Http_Message_Type_Demo>
    somebody should help me!please
    Thanks

    Hi,
    You can use HTTPServletRequest object to get the XML payload.
    BufferedReader reader = request.getReader(); //gets XML payload
    String line = reader.readLine(); // to read the XML payload line by line
    (request is the HTTPServletRequest object)
    Regards,
    Uma

  • How to send XML files through Business Connector to client URL

    Dear ALL
    I am new to SAP BC. We have setup BC 4.8 and would like to send out a XML file from BC to Client URL. Could someone please guide me.
    Please suggest solutions.
    Thanks
    Ahmed

    Hello Mickael
    Thanks for your reply. No, we do not have PI. This BC will be used for point to point communication with client.
    Scenario:
    R/3 server to send XML files to BC. BC will load these files ( using pub.getfile service), this file is to be parsed using pub.loaddocument service and then sent to client in XML format wrapped with digital signature. As i am new to BC i am unable to parse this file and wrap it with the digital signaature to send it.
    Kindly advise on how best can we perform this action.
    Thanks
    Ahmed

  • How to refresh XML file  from my client machine

    Hai All
    I have temp.XML and temp.XSL template in our server machine.
    when i give a print from client machine first time it gives the record,and next time it did not get refresh.Always it shows the previous records in the browser.But when i go into the server machine and click on temp.xml,it shows the current record(correct records)
    How to refresh XML file  from my client machine?
    Regards
    Dhina

    You never delete a Time Machine backup by dragging it to the Trash. You are supposed to use the TM application to manage the backups. What you will need to do now is to simply erase the drive using Disk Utility.

  • How to create xml file from Oracle and sending the same xml file to an url

    How to create xml file from Oracle and sending the same xml file to an url

    SQL/XML (XMLElement, XMLForest, XMLAgg, etc) and UTL_HTTP.
    Whether that works for you with the version of Oracle you have, your requirements, and needs is another story. A little detail goes a long way.

  • How to upload file from client to server in servlets.

    actually in my application i have to upload file from client m/c to server.
    it is not possible through file i/p stream as fileStreams does not work on network. Please mail me if you have any solution to this.
    Thank's in advance............

    Haii roshan
    Pls go through this thread..
    http://forum.java.sun.com/thread.jspa?forumID=45&threadID=616589
    regards
    Shanu

Maybe you are looking for

  • Free Trial InDesign Print Out Problems

    Hey, I created several designs with the free month trial of inDesign. Today I signed up for the monthly plan. When I go to print out my latest design it prints out on older one (similar but different). Does InDesign not allow you to print out designs

  • At the time of Payment scheduling Bank Account List

    Hi All, As per my client requirement they want at the time of payment scheduling They have to know Bank Account status than they can do the payment scheduling. And they want process for multiple Vender and multiple House Bank. Payment by NEFT/RTGS/Ch

  • Upgrading from XI/PI7.0 to 7.1 having problems with message mapping

    Hello, We are in the process over the past week of testing our XI/PI functionality after upgrading our 7.0 XI/PI environment to PI7.1; in particular several maps that were accessible in 7.0 will not open or diaplay in 7.1 complaining of a missing nod

  • Multiple Values per Key - PLEASE HELP!!

    hi. im trying to setup a TreeMap so it contains multiple values for each key using a List to store these values and a string as a key to reference them. however, although it compiles, i recieve a ClassCastException: java.util.ArrayList error when it

  • How to backup hard drive

    I have a an empty external hard drive and my internal drive is filling up and has all my imporant documents/photos/music etc. How do I make a backup of my internal drive to the external drive? Thanks.