Java Encapsulation SOAP Data __java

Source: Internet
Author: User
/** * Encapsulates SOAP data * @return * @throws soapexception/public String Initsoapdata () throws exception{SoapMessage
		SoapMessage = Messagefactory.newinstance (). CreateMessage ();
		Soappart Soappart = Soapmessage.getsoappart ();
		SoapEnvelope SoapEnvelope = Soappart.getenvelope ();
		SoapHeader SoapHeader = Soapenvelope.getheader ();
		Soapenvelope.addnamespacedeclaration ("Rec", "Http://cebpubservice.com/ReceiveService");
		SoapElement id = soapheader.addchildelement ("Token", "Rec"). Addchildelement ("Token", "rec"); Id.settextcontent ("XXX content ...)
		");
		Soapbody soapbody = Soapenvelope.getbody ();
		SoapElement informres = soapbody.addchildelement ("Receive", "rec");
		Informres.addchildelement ("Node name", "Rec"). Settextcontent ("M1420110010268"); Add more content at once informres.addchildelement (node name, rec). settextcontent (New SimpleDateFormat ("Yyyy-mm-dd ' T ' HH:mm:ss.
		
		SSS "). Format (new Date ()) +" +08:00 ");
		
		SOURCE Source = Soappart.getcontent ();
		Node root = null; if (source instanceof Domsource) {root = ((domsource) source). GetNode ();
			else if (source instanceof SAXSource) {InputSource Insource = ((SAXSource) source). Getinputsource ();
			Documentbuilderfactory dbf = Documentbuilderfactory.newinstance ();
			Dbf.setnamespaceaware (TRUE);
			Document doc = Dbf.newdocumentbuilder (). Parse (Insource);
		Root = (Node) doc.getdocumentelement ();
		} Transformer Transformer = Transformerfactory.newinstance (). Newtransformer ();  		
		Transformer.setoutputproperty (outputkeys.encoding, "utf-8");
		Transformer.setoutputproperty (outputkeys.indent, "yes"); 
		Transformer.setoutputproperty (Outputkeys.method, "html");
		Domsource Domsource = new Domsource (root);
		Streamresult Streamresult = new Streamresult ();
		Bytearrayoutputstream BAOs = new Bytearrayoutputstream ();
		Streamresult.setoutputstream (BAOs);
		Transformer.transform (Domsource, Streamresult);
		
	return baos.tostring (); }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.