SOAP message format for converting Socket Message format and vice versa using Java

I am currently studying the SOAP message format for converting Socket Message format and vice versa using Java.

I need this to reuse an outdated system that reads a socket format message in order to connect to a website that sends and receives a SOAP message format.

How can I do it? Should I consider text processing?

Socket Example for SOAP

CONNECTOR

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Interface Code="20" <Transaction Txn="01880120121024000001" CD="01880120121024000001001" Date="2012-10-24 17:27:25" BirthDate="1983-03-27" Code="8110009000000720" Type="0"/> </Interface> 

SOAP

 <?xml version='1.0' encoding='UTF-8'?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <webRequest xmlns="http://____________"> <arg0 xmlns="">&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?>&lt;Interface xmlns="http://____________" Version="1.0" Code="20" Txn="123" CD="456">&lt;Info BirthDate="1983-03-27" Code="1234" Type="0" />&lt;/Interface></arg0> </webRequest> </soapenv:Body> </soapenv:Envelope> 
+7
java soap sockets messaging
source share
1 answer

A socket message is a body hidden by XML from a SOAP message. You do not need additional libraries, as there are javax classes for parsing SOAP requests .

SOAP for the socket is simple:

 String message = "<?xml version='1.0' encoding='UTF-8'?>\n<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soapenv:Body>\n <webRequest xmlns=\"http://____________\">\n <arg0 xmlns=\"\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"\n standalone=\"yes\"?>&lt;Interface xmlns=\"http://____________\"\n Version=\"1.0\" Code=\"20\" Txn=\"123\" CD=\"456\">&lt;Info\n BirthDate=\"1983-03-27\" Code=\"1234\" Type=\"0\" />&lt;/Interface></arg0>\n </webRequest>\n </soapenv:Body>\n</soapenv:Envelope>"; InputStream is = new ByteArrayInputStream(message.getBytes()); SOAPMessage request = MessageFactory.newInstance().createMessage(null, is); System.out.println(request.getSOAPBody().getTextContent()); 

Socket for SOAP is more complex because we need to create webRequest wrap webRequest :

 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); docFactory.setNamespaceAware(true); // webRequest needs a namespace DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.newDocument(); Element root = doc.createElementNS("http://____________", "webRequest"); doc.appendChild(root); Element argElement = doc.createElement("arg0"); root.appendChild(argElement); String message = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<Interface Code=\"20\" \n <Transaction Txn=\"01880120121024000001\" CD=\"01880120121024000001001\" \n Date=\"2012-10-24 17:27:25\" BirthDate=\"1983-03-27\" Code=\"8110009000000720\" Type=\"0\"/>\n</Interface>"; argElement.setTextContent(message); SOAPMessage request = MessageFactory.newInstance().createMessage(); request.getSOAPBody().addDocument(doc); request.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true"); request.writeTo(System.out); 
+5
source share

All Articles