Note that there are some explanatory texts on larger screens.

plurals
  1. POhow do i send an xml string to a Socket Connection
    primarykey
    data
    text
    <p>i have a multi complex xml string and i want to send it over a TCP/IP Socket connection but i dont seem to know if string written or not,when i telnet to the server and send the request i get a response correctly, but i want to implement a socket class to send request and jaxb to parse my object classes to xml. below is the code</p> <pre><code> Estel es = new Estel(); Header hd = new Header(); Request rq = new Request(); hd.setRequestType("TOPUP"); es.setHeader(hd); es.setRequest(rq); rq.setAgentCode("8033818446"); rq.setPin("44B7A065BC937DE9406EABD6AB162AD4"); rq.setDestination("08033818446"); rq.setAgentTransId("20130618211503000021"); rq.setVendorCode("CHIT"); rq.setAmount(100); rq.setProductCode("MTNTOP"); rq.setClientType("pc"); rq.setComments("testing e top up"); //JAXB mashalls the object to xml form JAXBContext jaxb = JAXBContext.newInstance(Estel.class); Marshaller msh = jaxb.createMarshaller(); msh.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); StringWriter str = new StringWriter(); msh.marshal(es, str); //what the marshalled string looks like /*&lt;estel&gt;&lt;header&gt;&lt;requesttype&gt;TOPUP&lt;/requesttype&gt;&lt;/header&gt;&lt;request&gt; &lt;agentcode&gt;8033818446&lt;/agentcode&gt;&lt;pin&gt;44B7A065BC937DE9406EABD6AB162AD4&lt;/pin&gt; &lt;destination&gt;08033818446&lt;/destination&gt; &lt;agenttransid&gt;20130618211503000021&lt;/agenttransid&gt;&lt;vendorcode&gt;CHIT&lt;/vendorcode&gt; &lt;amount&gt;100&lt;/amount&gt;&lt;productcode&gt;MTNTOP&lt;/productcode&gt;&lt;comments&gt;Powered by ReadyCash Mobile Money&lt;/comments&gt;&lt;clienttype&gt;PC&lt;/clienttype&gt;&lt;/request&gt; &lt;/estel&gt; */ Socket soc = new Socket("41.206.23.21",7101); OutputStream os = soc.getOutputStream(); os.write(str.toString().getBytes()); os.flush(); soc.shutdownOutput(); //Read input stream and unmarshall to object InputStream input = soc.getInputStream(); Unmarshaller unmarshaller = jaxb.createUnmarshaller(); System.out.print("\n--------passing---------"); Estel estel = (Estel)unmarshaller.unmarshal(input); System.out.print("\n--------reading---------"); System.out.print("\nheader is "+estel.getHeader().getResponseType()); System.out.print("\ncode is"+estel.getResponse().getAgentCode()); os.close(); input.close(); soc.close(); </code></pre> <p>I dont know if im doing the write thing, when i send this , i get invalid request in the xml body meaning i didnt send the right format,what is the proper way to send an xml marshalled in JAXB to a Socket server.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload