use of javax.xml.soap.SOAPPart in project ddf by codice.
the class SoapRequestDecoder method decodeRelayState.
public String decodeRelayState(String samlRequest) {
String relayState = null;
try {
SOAPPart soapMessage = SamlProtocol.parseSoapMessage(samlRequest);
SOAPEnvelope envelope = soapMessage.getEnvelope();
SOAPHeader header = envelope.getHeader();
Iterator iterator = header.examineAllHeaderElements();
while (iterator.hasNext()) {
SOAPHeaderElement soapHeaderElement = (SOAPHeaderElement) iterator.next();
if ("RelayState".equals(soapHeaderElement.getLocalName())) {
relayState = soapHeaderElement.getValue();
break;
}
}
} catch (XMLStreamException e) {
throw new IllegalArgumentException("Unable to convert parse SOAP request.");
} catch (SOAPException e) {
throw new IllegalArgumentException("Unable to get SOAP envelope.");
}
return relayState;
}
use of javax.xml.soap.SOAPPart in project nhin-d by DirectProject.
the class RepositorySOAPHandler method handleMessage.
/**
* This method handles the incoming and outgoing SOAP-Message. It's an
* excellent point to manipulate the SOAP.
*
* @param SOAPMessageContext
* The SOAPMessageContext object.
*
* @return true if successful handling, false otherwise.
*/
@Override
public boolean handleMessage(SOAPMessageContext context) {
//Inquire incoming or outgoing message.
boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
try {
if (outbound) {
getHeaderData();
SOAPMessage msg = ((SOAPMessageContext) context).getMessage();
// dumpSOAPMessage(msg);
SOAPPart sp = msg.getSOAPPart();
// edit Envelope
SOAPEnvelope env = sp.getEnvelope();
SOAPHeader sh = env.addHeader();
@SuppressWarnings("unused") SOAPBody sb = env.getBody();
if (action != null) {
QName qname = new QName("http://www.w3.org/2005/08/addressing", "Action");
SOAPHeaderElement saction = sh.addHeaderElement(qname);
boolean must = true;
saction.setMustUnderstand(must);
saction.setValue(action);
}
if (relatesTo != null) {
QName qname = new QName("http://www.w3.org/2005/08/addressing", "RelatesTo");
SOAPHeaderElement relates = sh.addHeaderElement(qname);
relates.setValue(relatesTo);
}
if (from != null) {
QName qname = new QName("http://www.w3.org/2005/08/addressing", "From");
QName child = new QName("http://www.w3.org/2005/08/addressing", "Address");
SOAPHeaderElement efrom = sh.addHeaderElement(qname);
SOAPElement address = efrom.addChildElement(child);
address.setValue(from);
}
if (messageId != null) {
QName qname = new QName("http://www.w3.org/2005/08/addressing", "MessageID");
SOAPHeaderElement message = sh.addHeaderElement(qname);
message.setValue(messageId);
}
if (to != null) {
QName qname = new QName("http://www.w3.org/2005/08/addressing", "To");
SOAPHeaderElement sto = sh.addHeaderElement(qname);
sto.setValue(to);
}
} else {
//should not be any inbound
}
} catch (Exception e) {
LOGGER.error("Error handling SOAP message", e);
return false;
}
return true;
}
use of javax.xml.soap.SOAPPart in project Payara by payara.
the class BaseAuthConfig method getName.
private static Name getName(SOAPMessage message) {
Name rvalue = null;
SOAPPart soap = message.getSOAPPart();
if (soap != null) {
try {
SOAPEnvelope envelope = soap.getEnvelope();
if (envelope != null) {
SOAPBody body = envelope.getBody();
if (body != null) {
Iterator it = body.getChildElements();
while (it.hasNext()) {
Object o = it.next();
if (o instanceof SOAPElement) {
rvalue = ((SOAPElement) o).getElementName();
break;
}
}
}
}
} catch (SOAPException se) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "WSS: Unable to get SOAP envelope", se);
}
}
}
return rvalue;
}
use of javax.xml.soap.SOAPPart in project stanbol by apache.
the class LemmatizerClientHTTP method lemmatizeContents.
public String lemmatizeContents(String text, String lang) throws SOAPException, IOException {
// 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);
writer.write("<mor:inputText lang=\"");
writer.write(lang);
writer.write("\" text=\"");
StringEscapeUtils.escapeXml(writer, text);
writer.write("\"/>");
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);
// 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();
StringBuilder buff = new StringBuilder();
NodeList nlist = soapBody.getElementsByTagNameNS("*", "LexicalEntry");
for (int i = 0; i < nlist.getLength(); i++) {
Element result = (Element) nlist.item(i);
NodeList lemmasList = result.getElementsByTagNameNS("*", "Lemma");
if (lemmasList != null && lemmasList.getLength() > 0) {
HashSet<String> lemmas = new HashSet<String>();
for (int j = 0; j < lemmasList.getLength(); j++) {
lemmas.add(lemmasList.item(j).getTextContent());
}
for (String lemma : lemmas) {
buff.append(lemma).append(' ');
}
} else {
buff.append(result.getAttributeNS("*", "WordForm")).append(' ');
}
}
return buff.toString().trim();
}
use of javax.xml.soap.SOAPPart in project stanbol by apache.
the class SentimentAnalysisServiceClientHttp method extractSentimentExpressions.
public List<SentimentExpression> extractSentimentExpressions(String text, String lang) throws SOAPException, IOException {
if (text == null || text.isEmpty()) {
// no text -> no extractions
return Collections.emptyList();
}
// create the POST request
HttpURLConnection con = Utils.createPostRequest(serviceEP, requestHeaders, connectionTimeout);
// write content
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(con.getOutputStream(), UTF8));
writer.write(SOAP_PREFIX);
writer.write("<sen:analyzeText><arg0><![CDATA[" + text + "]]></arg0><arg1>" + lang + "</arg1></sen:analyzeText>");
writer.write(SOAP_SUFFIX);
writer.close();
// Call the service
long start = System.currentTimeMillis();
InputStream stream = con.getInputStream();
log.debug("Request to {} took {}ms", serviceEP, System.currentTimeMillis() - start);
// Create SoapMessage and parse the results
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage message = msgFactory.createMessage();
SOAPPart soapPart = message.getSOAPPart();
// Load the SOAP text into a stream source
StreamSource source = new StreamSource(new InputStreamReader(stream, UTF8));
// Set contents of message
soapPart.setContent(source);
SOAPBody soapBody = message.getSOAPBody();
// extract the results
List<SentimentExpression> sentExpressions = new Vector<SentimentExpression>();
NodeList nlist = soapBody.getElementsByTagName("relation");
String snippetStr = null;
for (int i = 0; i < nlist.getLength(); i++) {
Element relation = (Element) nlist.item(i);
String sentimentType = relation.getAttribute("type");
int startSnippet = Integer.parseInt(relation.getAttribute("start"));
int endSnippet = Integer.parseInt(relation.getAttribute("end"));
NodeList snippet = relation.getElementsByTagName("snippet");
if (snippet.getLength() > 0) {
snippetStr = snippet.item(0).getTextContent();
}
List<String> arguments = new Vector<String>();
NodeList argsList = relation.getElementsByTagName("arguments");
for (int x = 0; x < argsList.getLength(); x++) {
NodeList lemmas = ((Element) argsList.item(x)).getElementsByTagName("lemma");
for (int y = 0; y < lemmas.getLength(); y++) {
Element lemma = (Element) lemmas.item(y);
String lemmaStr = lemma.getAttribute("lemma");
if (lemmaStr != null && lemmaStr.length() > 0)
arguments.add(lemmaStr);
}
}
SentimentExpression expr = new SentimentExpression(sentimentType, snippetStr, startSnippet, endSnippet, arguments);
sentExpressions.add(expr);
}
return sentExpressions;
}
Aggregations