Send binary file using xml

Hi all,
I've got an application wich currently sends xml messages through sockets between server and client. Now, I'd like to be able of sending binary files (jpegs and other images...) as some content of these files. Is it possible with CDATA? Do you know any URL with an example or something?
thanks a lot!

This is a little example that shows the solution I adopted.
Two classes, a server and a client, execute the server in a given port and the client with "localhost" as ip and the same port as the server.
Ex: java Server 5555
java Client localhost 5555
the code:
import java.net.*;
import java.io.*;
public class Server {
    public static void main(String[] args) {
        ServerSocket serverSocket = null;
        if(args.length!=1){
            System.out.println("ERROR: java Server <port>");
        } else {
               // Create listening socket
               try {
                    serverSocket = new ServerSocket((new Integer(args[0])).intValue());
               } catch (IOException e) {
                    System.out.println("ERROR: not possible to listen on the specified port");
                    System.exit(1);
               // Create wait for connection
               Socket clientSocket = null;
               try {
                    clientSocket = serverSocket.accept();
               } catch (IOException e) {
                    System.err.println("ERROR: Accept failed.");
                    System.exit(1);
               try{
                      // Get the output channel
                    PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
                    // Send a xml message
                    out.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?><FOO><VAR message=\"ugly harcoded XMLmessage\"/></FOO>\0");
                    out.flush();
                    out.close();
                    clientSocket.close();
                    serverSocket.close();
               } catch(IOException IOE){
                    System.out.println("ERROR: on send");
import java.io.*;
import org.w3c.dom.Document;
import java.net.*;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import org.xml.sax.InputSource;
public class Client {
     public static void handleIncomingMessage(Document doc){
        System.out.println("DO WHAT YOU WANT WITH THE XML!");
    public static void main(String[] args){
        BufferedReader in = null;
        Socket socket = null;
        if(args.length!=2){
            System.out.println("ERROR: java Client <ip> <port>");
        } else {
            String ip = args[0];
            int port = (new Integer(args[1])).intValue();
               // Open a socket to the server
            try {
                    socket = new Socket(ip,port);
               } catch (UnknownHostException e) {
                    System.out.println("ERROR: Unknow host!");
                    System.exit(1);
               } catch (IOException e) {
                    System.out.println("ERROR: I/O error");
                    System.exit(1);
          try {
            // Get the input channel
               in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        } catch (IOException e) {
            System.err.println("ERROR: I/O error");
            System.exit(1);
          // Create a DocumentBuilder to convert the socket's incoming String
        // to a XML parsed Document
          Document XMLmessage =null;
        DocumentBuilder builder = null;
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          try{
               builder = factory.newDocumentBuilder();
        } catch (ParserConfigurationException PCE) {
            System.out.println(PCE.toString());
          try{
            String messageRead = "";
            char caracter;
            StringBuffer sb = null;
               // Read from the socket until \0
               sb = new StringBuffer();
               caracter =(char)in.read();
               while(caracter != '\0'){
                    sb.append(caracter);
                    caracter = (char)in.read();
               messageRead = sb.toString();
               System.out.println("Recieved: "+messageRead);
            // Parse the read message
               try{
                    XMLmessage = builder.parse(new InputSource((Reader)new StringReader(messageRead)));
                    // Work with it
                    handleIncomingMessage(XMLmessage);
               } catch(IOException IOE){
                    System.out.println(IOE.toString());
               } catch(SAXException SE) {
                    System.out.println(SE.toString());
          } catch(IOException IOE){
               System.out.println("ERROR: I/O error");
}hope it helps!
any comment about the code will be welcome

Similar Messages

  • How to send a file using IOCP?

    When using blocking sockets, all I had to do to send a file was to open the file and loop through it and send it in chunks.
    But I find sending a file using overlapped sockets to be more challenging. I can think of the following approach to do it:
    I open the file and send the first chunk, and I keep track of the file handle and file position.
    Now when I get a completion packet indicating that some data has been sent, I check to see if the socket is currently in the process of sending a file, and if it is, I retrieve the file handle and file position and send the next chunk.
    I repeat step 2 until I reach the last chunk in the file, and then I close the file.
    Is this approach correct?
    Note: I don't want to use TransmitFile().

    This approach is more or less correct, but maybe you'd have to know some more things.
    If send "returns" it means, that you buffer has been copied into the internal buffer of system or the network interface card or whatever... in general it means, that you can free/reuse the buffer you have used, but it doesn't mean, that the data
    has been delivered (it does not even mean it has been sent already).
    That's why I'm normally using some flow-control (messages from the receiver) to verify the real data flow.
    The next point is, that you shouldn't read from the file only after you got the ok that the first chunk has been sent. You should read the data as soon as possible so that you can respond much quicker to a send-complete-message. I'd recommend to send using
    multiple buffers.
    Rudolf

  • Getting error while running the XML file using XML Publisher Desktop

    Hi all,
    We have successfully loaded the XML file using XML Publisher Desktop. But when we preview the same using PDF format we are getting the following error.
    Font Dir: C:\Program Files\Oracle\XML Publisher Desktop\Template Builder for Word\fonts
    Run XDO Start
    RTFProcessor setLocale: en-us
    FOProcessor setData: C:\Documents and Settings\smanmadh\Desktop\ProductCompensationDT.xml
    FOProcessor setLocale: en-us
    java.lang.NullPointerException
         at oracle.apps.xdo.template.fo.area.PageNumber.formatString(PageNumber.java:104)
         at oracle.apps.xdo.template.fo.IDManager.registerId(IDManager.java:44)
         at oracle.apps.xdo.template.fo.area.AreaTree.registerLastPageJoinSeq(AreaTree.java:1106)
         at oracle.apps.xdo.template.fo.area.AreaTree.incrementJoinSequenceIndex(AreaTree.java:219)
         at oracle.apps.xdo.template.fo.area.AreaTree.registerLastPageDocument(AreaTree.java:1089)
         at oracle.apps.xdo.template.fo.area.AreaTree.forceOutput(AreaTree.java:471)
         at oracle.apps.xdo.template.fo.elements.FORoot.end(FORoot.java:58)
         at oracle.apps.xdo.template.fo.FOHandler.endElement(FOHandler.java:386)
         at oracle.xml.parser.v2.XMLContentHandler.endElement(XMLContentHandler.java:196)
         at oracle.xml.parser.v2.NonValidatingParser.parseElement(NonValidatingParser.java:1212)
         at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:301)
         at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:268)
         at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:149)
         at oracle.apps.xdo.template.fo.FOProcessingEngine.process(FOProcessingEngine.java:279)
         at oracle.apps.xdo.template.FOProcessor.generate(FOProcessor.java:1022)
         at RTF2PDF.runRTFto(RTF2PDF.java:626)
         at RTF2PDF.runXDO(RTF2PDF.java:460)
         at RTF2PDF.main(RTF2PDF.java:251)
    Thanks in Advance.
    Sudeep.

    This is BI related. You will get a quicker answer from the BI Publisher forum
    BI Publisher

  • Error while running the XML file using XML Publisher Desktop

    Hi All,
    We have successfully loaded the XML file using XML Publisher Desktop.But when we try to preview it using the PDF format we are getting the following error.
    Font Dir: C:\Program Files\Oracle\XML Publisher Desktop\Template Builder for Word\fonts
    Run XDO Start
    RTFProcessor setLocale: en-us
    FOProcessor setData: C:\Documents and Settings\smanmadh\Desktop\ProductCompensationDT.xml
    FOProcessor setLocale: en-us
    java.lang.NullPointerException
         at oracle.apps.xdo.template.fo.area.PageNumber.formatString(PageNumber.java:104)
         at oracle.apps.xdo.template.fo.IDManager.registerId(IDManager.java:44)
         at oracle.apps.xdo.template.fo.area.AreaTree.registerLastPageJoinSeq(AreaTree.java:1106)
         at oracle.apps.xdo.template.fo.area.AreaTree.incrementJoinSequenceIndex(AreaTree.java:219)
         at oracle.apps.xdo.template.fo.area.AreaTree.registerLastPageDocument(AreaTree.java:1089)
         at oracle.apps.xdo.template.fo.area.AreaTree.forceOutput(AreaTree.java:471)
         at oracle.apps.xdo.template.fo.elements.FORoot.end(FORoot.java:58)
         at oracle.apps.xdo.template.fo.FOHandler.endElement(FOHandler.java:386)
         at oracle.xml.parser.v2.XMLContentHandler.endElement(XMLContentHandler.java:196)
         at oracle.xml.parser.v2.NonValidatingParser.parseElement(NonValidatingParser.java:1212)
         at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:301)
         at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:268)
         at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:149)
         at oracle.apps.xdo.template.fo.FOProcessingEngine.process(FOProcessingEngine.java:279)
         at oracle.apps.xdo.template.FOProcessor.generate(FOProcessor.java:1022)
         at RTF2PDF.runRTFto(RTF2PDF.java:626)
         at RTF2PDF.runXDO(RTF2PDF.java:460)
         at RTF2PDF.main(RTF2PDF.java:251)
    Any pointers will be of great help.
    Thanks in Advance
    Sudeep.


    I had a similar error which when I searched, came up with this thread.
    My issue was resolved after I discovered that my RTF template was not really RTF. It was sill in MS Word DOC format. This was discovered by reviewing two templates in NOTEPAD. The MS-DOC files have a lot of "special" characters in them. My RTF was not really RTF.
    After doing a SAVE AS - RTF format, then the preview worked as expected.
    Just Sharing...
    --Tim                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Sending empty files using SFTP Adapter

    I am trying to send empty files using SFTP adapter. The interface has to send the file whether its empty file or containing data using SFTP adapter. I am using BizTalk Server 2013 R2. Is it a bug or the hotfix is already there for this issue.

    The issue here is not your SFTP not able to send 0KB files, but the file receive adapter that is receiving the file. The file adapter deletes 0 KB files and doest not transmit it further.
    If u have a ftp receive for example you should be able to send 0KB files.
    If u have a custom file receive adapter , is it handling 0KB files ?
    Regards &lt;br/&gt; When you see answers and helpful posts,&lt;br/&gt; please click Vote As Helpful, Propose As Answer, and/or Mark As Answer

  • How to send an email using XML Publisher

    Can any body help me how to send an email using XML Publisher.
    Regards,
    Suresh

    Sorry ,
    when a http://blogs.oracle.com/xmlpublisher/newsItems/departments/documentDelivery
    this it show this not answer the question.
    Thanks
    Welcome to Oracle Blogs
    Welcome to the Oracle blogging community, where Oracle executives, employees, and non-employees exchange views about customer requirements and best practices.
    We're sorry, the weblog you requested cannot be accessed.
    - You may not have the necessary permission for access the weblog.
    - This weblog does not exist.
    You may wish to try again using one of the tools below.
    - Check the URL and contact your System Administrator for access.
    - Or click here to go back to Oracle Blogs homepage.
    Powered by
    Movable Type and Oracle
    The views expressed on this blog are my own and do not necessarily reflect the views of Oracle. Terms of Use

  • Sending a File Using DataGram Sockets

    I writting one java program that can be used to transfer a file from one computer to another computer.
    I wrote using Sockets.
    But i want to do that using DatagramSockets. Can we send a file using DataGramSockets?
    Please reply soon.

    You can use DataGram but it is harder.
    One issue is you need to retransmit missing packets. This means you need to keep track of which packets have been sent and be able to send missing ones again.
    If Socket work for you why do you want to use DataGrams

  • Send A file Using JMS

    I want to send a file Using JMS.. and want to have
    These Details in the message that send.
    Receivers IP address & The file
    That mean I want to send a File from one client to another client Using a Queue
    Can Anyone help me to solve this problem
    thanks

    Read the file then use a JMS BytesMessage or TextMessage. Add your own JMS header for the recievers ip and any other info you want to annotate the message with.
    Watch out for character encoding and max file size problems.
    If your client / server are not on the same network you're likely to run into firewall issues.
    Don't kid yourself that this will be a transactional solution.
    Assumes both clients are Java (JMS headers are a pain to read otherwise)

  • Send binary files from SAP System to SAP XI/PI

    Dear experts,
    in our SAP ERP-System we have a link to JPG files which are stored in an archive. We want to send these files with some other information to our SAP XI and then store them on a file server. Is there a way to send a MIME attachment via RFC? Or is there another way to send binary files from SAP ERP to SAP XI? We want to avoid polling the files on OS level.
    Thanks and regards,
    David

    Most recommended way is to go for ABAP proxies. They support attachments.
    Regards,
    Prateek

  • How to send large files using web service

    hello everyone,
    I am new to this forum, so please pardon me if I post some silly problem...
    I have created one service which sends file when client (jsp) request it. I am using JBOSS as my server. purpose of this application is when client request some fle then service will send this file... and most of the time we need to send only pdfs and ppts...
    Problem is, this service sends txt, java files easily of any size but when i tried sending PDF, PPT then i got xml.SAXParseException.......
    I thought this error is because of some characters, but how to fix it....
    I am working on Linux.
    code snippet is:
    import java.io.*;
    public class MyHelloService
    public String file_size (String name)
         String s = new String("");
    byte[] sendata1=new byte[100];
         try
              System.out.println("name recived is :::::::::::"+name);
              FileInputStream in=new FileInputStream(name);
              int size=0;
              size=in.available();
              System.out.println("FILE SIZE IS:::::"+size);
              byte[] sendata11=new byte[size];
              i=in.read(sendata11);
              System.out.println(new String(sendata11));
              s=new String(sendata11);
         catch(Exception e)
                   System.out.println("EXCEPTION IN JWS:::"+e);
                   s=new String("nofilefounderror");
         return s;
    pls tell me what am i doing wrong ad how to fix this?
    and one more thing can i send byte array from a web service as i tried but couldnt do that... so i am reading everything in a single byte array and then converted to string.....
    is it possibel to send file in a chunk?if yes, how to do that?
    waiting for the reply..... pls reply as soon as possible....
    Rashi

    hi,
    I am sending file from server to client i.e client will request for a file and service will send it back....... no socket connection is there...I am using JBOSS and apache axis.
    pls help me out.....
    Rashi

  • How to send A file using Webservice?

    I heard about webservice when I read through XML...
    It a bit like XML cannot show off it strength without webservice...lol
    What is webservice? What library should I use to send a file from server to client using webservice?
    Webservice is Quite new for me. Any expert here can direct me to the tutorial link that can teach me how to use webservice?
    I go through some code :
    <?xml version="1.0"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://namespaces.cafeconleche.org/xmljava/ch2/"
    xmlns="http://namespaces.cafeconleche.org/xmljava/ch2/"
    elementFormDefault="qualified">What is xmlns? Is webservice can run it at localhost? My house don't have internet. :(
    Thank....

    to learn webservice..you can try these samples...
    http://www.csd.abdn.ac.uk/~bscharla/teaching/CS5302/practicals/practical8.shtml

  • How to send TDMS file using TCP/IP

    Hi,
    I'm working with a cRIO-9025, chassis cRIO-9118 and NI 9239 module.
    I've done an acquisition (voltage) where data is in 1D Wfm SGL. I've saved this data using a TDMS file, but now I want to send this file to an other computer (in this case mine) because the file is stored in the target. To do that I've implemented this example:
    http://zone.ni.com/devzone/cda/epd/p/id/2842#0requirements
    The problem is that the tdms file is created but it hasn't any data. I attach the image of the program. The program is done in other project (not which I use to make acq) to make it easy and then implement it when it works.
    *The name file in the client is not used because I had a conflict with path.
    What I'm looking for is make an acquisition of 10 minutes every 30 minutes and then send this data to an other computer (or others). I'm not sure if it's the best way, maybe is better to send data at the same time as the acquisition is being done, but my theacher told me that is easier if I send the file when acquisition has finished. To make acq I use FPGA and RT.
    I would appreciate your help. Thanks!!
    Solved!
    Go to Solution.

    I believe the FTP VIs are built into LabVIEW 2011SP1 - I have the VI present, but I could have installed the internet toolkit (don't know).
    Look in the following location:   Function Palette -> Connectivity -> Internet -> FTP
    You're really looking for the VI named, "FTP Get File.vi".  What this VI does is contacts an FTP server and requests a file from it.  If your files are on the target, and you know the filename that will be created (such as files created in a sequence) you can request the file from the target and have them copied to the local machine (Windows).  RT cannot "push" files to the Windows side unless you have an FTP server (like FileZilla Server) running on the Windows host.
    It's a very simple one-VI solution.  You specify host (the IP Address of the target you're pulling files from), the remote path for the file (for instance if the file is located in c:\ni-rt\data\myfile.zip then that's what you put as the remote path of the file), the local path for the file (where you want the file copied to, along with the name of the file, such as c:\mydir\myfile.zip), the username to log into the FTP server with (default is 'anonymous') and the password to use (default is an empty string).  The importan thing to note is whether to use a binary transfer or not - if the file is a text file, no binary transfer needed; if the file is a binary file then you get better results using a binary transfer - I prefer to always use binary transfers, as non-binary transfers actually "interpret" and "convert" text information in the files.
    -Danny

  • Sending Binary Data using HTP package

    Has anyone been successful in using the HTP package and its PUTRAW procedure to send binary data to a browser?
    Example code shows basic idea:
    create or replace
    procedure test_raw as
    output VARCHAR2(20);
    begin
    OWA_UTIL.MIME_HEADER('application/x-gzip', TRUE);
    output := 'Hello World!';
    HTP.PUTRAW(UTL_RAW.CAST_TO_RAW(output));
    HTP.FLUSH;
    end test_raw;
    I receive an empty file when called from the browser.
    What gives?

    I found my answer. I should be using wpg_docload.download_file(BLOB) to "download" a the contents of a BLOB.

  • Creating indesign files using xml & c#

    hey...
    i need to make an indesign template/doc from an XML file using C# as the language. can anyone of you please help me in this.
    Thanks in advance to all of you.

    The InDesign file format is a proprietary binary format, which changes between releases. Your best shot is IDML, but that is only for CS4. There is also the INCX interchange format, but it has limitations.

  • File format while sending a file  using FTP Process

    Hi,
    I am facing a formatting problem when i send a file from SAP application server to a different sever using FTP process.
    The problem is like this:
    Lets say I have a file with 10 records on the application server. When i am downloading this file to a pc, the file is showing 10 lines.
    But when i open the same file on the other server it is showing 10 records as 1 line.
    The file i am sending is a text file.(ex: acc_payable.txt)
    If i open the same file on the other server using word pad it is showing 10 records in 10 different lines.
    I want the file to be opened using notepad and want to see the each record in a different line
    Can anybody help me on this issue
    Regards,
    Radhakrishna

    Another stab at "simplest": can you avoid embedding
    newline characters in the strings
    your write and reply on PrintWriter's
    println() methods instead?But, if I understand the OP, this will cause the same problem. He is running on Unix but wants to generate a DOS type eol. The println() method will use the OS default; therefore, he needs to explicitly specify the DOS eol.

Maybe you are looking for

  • V$temp_space_header showing temp space fully utilized but not true

    hi, any experience regarding temp space headeR? currently we are experiencing this issue: when using this: SELECT tablespace_name, SUM(bytes_used), SUM(bytes_free) FROM v$temp_space_header GROUP BY tablespace_name; TABLESPACE_NAME SUM(BYTES_USED) SUM

  • FCE to iDVD (w chapters created in FCE)

    Hello, I've searched old threads on how to Export your FCE project to iDVD. Most of the posts said to "export to quicktime movie", then load your movie into iDVD. I tried that, and it worked - however, I created my chapters in FCE and they did not ca

  • HT1386 Stinking syncing problem

    I'm up to date on all software but suddenly I'm not able to sync my i5 with iTunes. The battery starts charging but it doesn't even register as an available device, much less start updating. Just nothing. Any suggestions?

  • Hi, i can't open photo library on my iPhoto. Now lost all my photos.  How to restore al photos on iPhoto?

    Hi, i can't open photo library on my iPhoto. Now lost all my photos.  How to restore all photos on iPhoto on Macbookair?

  • Video playback pauses in iTunes

    The video we downloaded from iTunes regularly pauses during playback on our iMac. The sound and video are choppy. Sometimes the video plays and the sound continues; other times both video and sound freeze up momentarily. How do we resolve this? At th