Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #30273 > unrolled thread

Sending SOAP through sockets

Started byPeter <pawell55555@gmail.com>
First post2014-11-03 13:46 -0800
Last post2014-11-05 04:30 -0800
Articles 3 — 2 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  Sending SOAP through sockets Peter <pawell55555@gmail.com> - 2014-11-03 13:46 -0800
    Re: Sending SOAP through sockets Roedy Green <see_website@mindprod.com.invalid> - 2014-11-04 17:15 -0800
      Re: Sending SOAP through sockets Roedy Green <see_website@mindprod.com.invalid> - 2014-11-05 04:30 -0800

#30273 — Sending SOAP through sockets

FromPeter <pawell55555@gmail.com>
Date2014-11-03 13:46 -0800
SubjectSending SOAP through sockets
Message-ID<72351757-dc88-414c-b9c0-1ff5d7c64da4@googlegroups.com>
I try to send soap message from client written by me to server also written by me through sockets.

I'll try to paste only important code that should do that (communication between server and client is ok - I can send String object):

    // Client

    /* Soap */
    MessageFactory factory = MessageFactory.newInstance();
	SOAPMessage soapMsg = factory.createMessage();
	SOAPPart part = soapMsg.getSOAPPart();
			 
	SOAPEnvelope envelope = part.getEnvelope();
	SOAPHeader header = envelope.getHeader();
	SOAPBody body = envelope.getBody();
			 
	header.addTextNode("SomeText");
	header.setValue("SomeValue");
			 
	SOAPBodyElement element = body.addBodyElement(envelope.createName("JAVA", "training", "aaa"));
	element.addChildElement("XXX").addTextNode("YYY");
			 
	SOAPBodyElement element1 = body.addBodyElement(envelope.createName("JAVA", "training", "bbb"));
	element1.addChildElement("Spring").addTextNode("TrainingonSpring");
    /* Soap */

    String soapMessage = soapMsg.toString();

    Socket s = new Socket(serverHostname, 10007);
    PrintStream out = new PrintStream(s.getOutputStream(), true);

    out.println(soapMessage);



    // Server
    ServerSocket serverSocket = new ServerSocket(10007);
    Socket socket = serverSocket.accept(); 
    BufferedReader in = new BufferedReader(new InputStreamReader( socket.getInputStream())); 
    String inputLine = in.readLine(); 
    // I've read Soap as a String and I want to change it to SoapMessage

    InputStream is = new ByteArrayInputStream(inputLine.getBytes());
    SOAPMessage soap = MessageFactory.newInstance().createMessage(null, is);

    // I try to print for example Header Value to system output
    System.out.println(soap.getSOAPHeader().getValue().toString());


   ///////////////////

I have a lot of errors. ;(


ERROR:  'Content is not allowed in prolog.'
Nov 03, 2014 9:25:43 PM com.sun.xml.internal.messaging.saaj.soap.EnvelopeFactory createEnvelope
SEVERE: SAAJ0511: Unable to create envelope from given source
Exception in thread "main" com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to create envelope from given source:
        at com.sun.xml.internal.messaging.saaj.soap.EnvelopeFactory.createEnvelope(Unknown Source)
        at com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPPart1_1Impl.createEnvelopeFromSource(Unknown Source)
        at com.sun.xml.internal.messaging.saaj.soap.SOAPPartImpl.getEnvelope(Unknown Source)
        at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.getSOAPHeader(Unknown Source)
        at EchoServer.main(EchoServer.java:64)
Caused by: javax.xml.transform.TransformerException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
        at com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer.transform(Unknown Source)
        ... 5 more


etc.





I'm a beginner. I spent many many hours tried to solve this problem.... ;(


Please help me. 

[toc] | [next] | [standalone]


#30277

FromRoedy Green <see_website@mindprod.com.invalid>
Date2014-11-04 17:15 -0800
Message-ID<r5ti5at3vbu7ljrmva7k1fo1bhlu0i4br6@4ax.com>
In reply to#30273
On Mon, 3 Nov 2014 13:46:52 -0800 (PST), Peter <pawell55555@gmail.com>
wrote, quoted or indirectly quoted someone who said :

>I'm a beginner. I spent many many hours tried to solve this problem..

See if you can find ANY soap application with source.  For example
Amazon AWS, then watch it operate with a packet sniffer and by tracing
the code until you understand generally how SOAP works.
You might also bring your background understanding up to snuff by
reading a text.  See http://mindprod.com/jgloss/soap.html

The first thing that hits me is my understanding is SOAP sits atop
HTTP.  Otherwise it is going to have trouble tunneling through
firewalls without special setup. You are trying to use raw sockets.
-- 
Roedy Green Canadian Mind Products http://mindprod.com
Software gets slower faster than hardware gets faster.
~ Niklaus Wirth (born: 1934-02-15 age: 80) Wirth’s Law

[toc] | [prev] | [next] | [standalone]


#30281

FromRoedy Green <see_website@mindprod.com.invalid>
Date2014-11-05 04:30 -0800
Message-ID<826k5a9jrg8q4f94gpq79g8ds2gsj2va39@4ax.com>
In reply to#30277
On Tue, 04 Nov 2014 17:15:57 -0800, Roedy Green
<see_website@mindprod.com.invalid> wrote, quoted or indirectly quoted
someone who said :

>See http://mindprod.com/jgloss/soap.html

I have been having trouble with uploads. That page is out of date.
Hopefully the problem will be fixed some time on wed.
-- 
Roedy Green Canadian Mind Products http://mindprod.com
Software gets slower faster than hardware gets faster.
~ Niklaus Wirth (born: 1934-02-15 age: 80) Wirth’s Law

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web