use of javax.xml.soap.SOAPBody in project jdk8u_jdk by JetBrains.
the class SaajEmptyNamespaceTest method testAddElementToGlobalNsNoDeclarations.
/*
* Test that adding element with explicitly empty namespace URI shall put
* the element into global namespace. Namespace declarations are not added
* explicitly.
*/
@Test
public void testAddElementToGlobalNsNoDeclarations() throws Exception {
// Create empty SOAP message
SOAPMessage msg = createSoapMessage();
SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
// Add elements
SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", "");
SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");
// Check namespace URIs
Assert.assertNull(childGlobalNS.getNamespaceURI());
Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
use of javax.xml.soap.SOAPBody in project jdk8u_jdk by JetBrains.
the class SaajEmptyNamespaceTest method testAddElementToNullNs.
/*
* Test that adding element with explicitly null namespace URI shall put
* the element into global namespace.
*/
@Test
public void testAddElementToNullNs() throws Exception {
// Create empty SOAP message
SOAPMessage msg = createSoapMessage();
SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
// Add elements
SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", null);
childGlobalNS.addNamespaceDeclaration("", null);
SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");
// Check namespace URIs
Assert.assertNull(childGlobalNS.getNamespaceURI());
Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
Assert.assertEquals(TEST_NS, childDefaultNS.getNamespaceURI());
}
use of javax.xml.soap.SOAPBody in project jdk8u_jdk by JetBrains.
the class SaajEmptyNamespaceTest method testAddElementToGlobalNsQName.
/*
* Test that adding element with explicitly empty namespace URI via QName
* shall put the element in global namespace.
*/
@Test
public void testAddElementToGlobalNsQName() throws Exception {
// Create empty SOAP message
SOAPMessage msg = createSoapMessage();
SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
// Add elements
SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName("", "global-child"));
childGlobalNS.addNamespaceDeclaration("", "");
SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");
// Check namespace URIs
Assert.assertNull(childGlobalNS.getNamespaceURI());
Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
use of javax.xml.soap.SOAPBody in project tdi-studio-se by Talend.
the class SOAPUtil method invokeSOAP.
public void invokeSOAP(String version, String destination, String soapAction, String soapMessage) throws SOAPException, TransformerException, ParserConfigurationException, FileNotFoundException, UnsupportedEncodingException {
MessageFactory messageFactory = null;
if (version.equals(SOAP12)) {
messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
} else {
messageFactory = MessageFactory.newInstance();
}
SOAPMessage message = messageFactory.createMessage();
MimeHeaders mimeHeaders = message.getMimeHeaders();
mimeHeaders.setHeader("SOAPAction", soapAction);
if (basicAuth) {
addBasicAuthHeader(mimeHeaders, username, password);
}
// Create objects for the message parts
SOAPPart soapPart = message.getSOAPPart();
String encoding = getEncoding(soapMessage);
ByteArrayInputStream stream = new ByteArrayInputStream(soapMessage.getBytes(encoding));
StreamSource preppedMsgSrc = new StreamSource(stream);
soapPart.setContent(preppedMsgSrc);
// InputStream stream = new FileInputStream(new File("d://soap.txt"));
// StreamSource preppedMsgSrc = new StreamSource(stream);
// soapPart.setContent(preppedMsgSrc);
message.saveChanges();
// Send the message
SOAPMessage reply = connection.call(message, destination);
SOAPPart reSoapPart = reply.getSOAPPart();
if (reSoapPart != null && reSoapPart instanceof SOAPPartImpl) {
((SOAPPartImpl) reSoapPart).setSourceCharsetEncoding(encoding);
}
SOAPEnvelope reEnvelope = reSoapPart.getEnvelope();
SOAPHeader reHeader = reEnvelope.getHeader();
if (reHeader != null) {
setReHeaderMessage(Doc2StringWithoutDeclare(extractContentAsDocument(reHeader)));
}
SOAPBody reBody = reEnvelope.getBody();
if (reBody.getFault() != null) {
hasFault = true;
setReFaultMessage(Doc2StringWithoutDeclare(extractContentAsDocument(reBody)));
setReBodyMessage(null);
} else {
hasFault = false;
if (reBody.getChildNodes().getLength() < 1) {
setReBodyMessage(null);
} else if (reBody.getChildNodes().getLength() == 1 && reBody.getChildNodes().item(0) instanceof javax.xml.soap.Text) {
setReBodyMessage(null);
} else {
setReBodyMessage(Doc2StringWithoutDeclare(extractContentAsDocument(reBody)));
}
setReFaultMessage(null);
}
}
use of javax.xml.soap.SOAPBody in project stanbol by apache.
the class LemmatizerClientHTTP method performMorfologicalAnalysis.
public List<LexicalEntry> performMorfologicalAnalysis(String text, String lang) throws IOException, SOAPException {
//create the POST request
HttpURLConnection con = Utils.createPostRequest(serviceEP, requestHeaders, conTimeout);
//write content
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(con.getOutputStream(), UTF8));
//write the SOAP envelope, header and start the body
writer.write(SOAP_REQUEST_PREFIX);
//write the data (language and text)
writer.write("<mor:inputText lang=\"");
writer.write(lang);
writer.write("\" text=\"");
StringEscapeUtils.escapeXml(writer, text);
writer.write("\"/>");
//close the SOAP body and envelope
writer.write(SOAP_REQUEST_SUFFIX);
writer.close();
//Call the service
long start = System.currentTimeMillis();
InputStream stream = con.getInputStream();
log.debug("Request to {} took {}ms", serviceEP, System.currentTimeMillis() - start);
if (log.isTraceEnabled()) {
//log the response if trace is enabled
String soapResponse = IOUtils.toString(stream, "UTF-8");
log.trace("SoapResponse: \n{}\n", soapResponse);
stream = new ByteArrayInputStream(soapResponse.getBytes(Charset.forName("UTF-8")));
}
// Create SoapMessage
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage message = msgFactory.createMessage();
SOAPPart soapPart = message.getSOAPPart();
// Load the SOAP text into a stream source
StreamSource source = new StreamSource(stream);
// Set contents of message
soapPart.setContent(source);
SOAPBody soapBody = message.getSOAPBody();
List<LexicalEntry> lista = new Vector<LexicalEntry>();
NodeList nlist = soapBody.getElementsByTagNameNS("*", "LexicalEntry");
for (int i = 0; i < nlist.getLength(); i++) {
Element result = (Element) nlist.item(i);
String wordForm = result.getAttribute("WordForm");
int from = Integer.parseInt(result.getAttribute("OffsetFrom"));
int to = Integer.parseInt(result.getAttribute("OffsetTo"));
LexicalEntry le = new LexicalEntry(wordForm, from, to);
List<Reading> readings = new Vector<Reading>();
NodeList lemmasList = result.getElementsByTagNameNS("*", "Lemma");
if (lemmasList != null && lemmasList.getLength() > 0) {
for (int j = 0; j < lemmasList.getLength(); j++) {
Element lemmaElm = (Element) lemmasList.item(j);
String lemma = lemmaElm.getTextContent();
NodeList features = ((Element) lemmaElm.getParentNode()).getElementsByTagNameNS("*", "LexicalFeature");
Hashtable<String, List<String>> featuresMap = new Hashtable<String, List<String>>();
for (int k = 0; features != null && k < features.getLength(); k++) {
Element feat = (Element) features.item(k);
String name = feat.getAttribute("name");
String value = feat.getTextContent();
List<String> values = null;
if (featuresMap.containsKey(name))
values = featuresMap.get(name);
else
values = new Vector<String>();
values.add(value);
featuresMap.put(name, values);
}
Reading r = new Reading(lemma, featuresMap);
readings.add(r);
}
}
le.setTermReadings(readings);
lista.add(le);
}
return lista;
}
Aggregations