use of javax.xml.soap.SOAPException in project stanbol by apache.
the class CeliAnalyzedTextLemmatizerEngine method computeEnhancements.
@Override
public void computeEnhancements(ContentItem ci) throws EngineException {
AnalysedText at = getAnalysedText(this, ci, true);
String language = getLanguage(this, ci, true);
isLangaugeConfigured(this, languageConfig, language, true);
List<LexicalEntry> terms;
try {
terms = this.client.performMorfologicalAnalysis(at.getSpan(), language);
} catch (IOException e) {
throw new EngineException("Error while calling the CELI Lemmatizer" + " service (configured URL: " + serviceURL + ")!", e);
} catch (SOAPException e) {
throw new EngineException("Error wile encoding/decoding the request/" + "response to the CELI lemmatizer service!", e);
}
Map<LexicalCategory, Double> tokenLexCats = new EnumMap<LexicalCategory, Double>(LexicalCategory.class);
for (LexicalEntry term : terms) {
if (term.getTermReadings().isEmpty()) {
//ignore terms without readings
continue;
}
//Add the LexicalEntry as Token to the Text. NOTE that if a
//Token with the same start/end positions already exist this
//Method returns the existing instance
Token token = at.addToken(term.getFrom(), term.getTo());
//Now try to get POS annotations for the Token
for (Value<PosTag> posAnno : token.getAnnotations(NlpAnnotations.POS_ANNOTATION)) {
if (posAnno.value().isMapped()) {
for (LexicalCategory cat : posAnno.value().getCategories()) {
if (!tokenLexCats.containsKey(cat)) {
//do not override with lover prob
tokenLexCats.put(cat, posAnno.probability());
}
}
}
}
for (Reading reading : term.getTermReadings()) {
MorphoFeatures mf = CeliMorphoFeatures.parseFrom(reading, language);
//add the readings (MorphoFeatures)
if (mf != null) {
//use the POS tags of the morpho analysis and compare it
//with existing POS tags.
double posProbability = -1;
Set<LexicalCategory> mfCats = EnumSet.noneOf(LexicalCategory.class);
for (PosTag mfPos : mf.getPosList()) {
mfCats.addAll(mfPos.getCategories());
}
for (LexicalCategory mfCat : mfCats) {
Double prob = tokenLexCats.get(mfCat);
if (prob != null && posProbability < prob) {
posProbability = prob;
}
}
//add the morpho features with the posProbabiliy
Value<MorphoFeatures> value = Value.value(mf, posProbability < 0 ? Value.UNKNOWN_PROBABILITY : posProbability);
token.addAnnotation(NlpAnnotations.MORPHO_ANNOTATION, value);
}
}
}
}
use of javax.xml.soap.SOAPException in project tomee by apache.
the class SaajMetaFactoryImpl method callFactoryMethod.
private Object callFactoryMethod(String methodName, String arg) throws SOAPException {
SAAJMetaFactory factory = (SAAJMetaFactory) SaajFactoryFinder.find("javax.xml.soap.MetaFactory");
try {
Method method = factory.getClass().getDeclaredMethod(methodName, new Class[] { String.class });
boolean accessibility = method.isAccessible();
try {
method.setAccessible(true);
Object result = method.invoke(factory, new Object[] { arg });
return result;
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof SOAPException) {
throw (SOAPException) e.getTargetException();
} else {
throw new SOAPException("Error calling factory method: " + methodName, e);
}
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new SOAPException("Error calling factory method: " + methodName, e);
} finally {
method.setAccessible(accessibility);
}
} catch (NoSuchMethodException e) {
throw new SOAPException("Factory method not found: " + methodName, e);
}
}
use of javax.xml.soap.SOAPException in project cxf by apache.
the class SAAJInInterceptor method handleMessage.
@SuppressWarnings("unchecked")
public void handleMessage(SoapMessage message) throws Fault {
if (isGET(message)) {
return;
}
Boolean bodySet = (Boolean) message.get(BODY_FILLED_IN);
if (Boolean.TRUE.equals(bodySet)) {
return;
}
message.put(BODY_FILLED_IN, Boolean.TRUE);
try {
SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
if (soapMessage == null) {
MessageFactory factory = preInterceptor.getFactory(message);
soapMessage = factory.createMessage();
message.setContent(SOAPMessage.class, soapMessage);
}
XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
if (xmlReader == null) {
return;
}
final SOAPPart part = soapMessage.getSOAPPart();
Document node = (Document) message.getContent(Node.class);
if (node != part && node != null) {
StaxUtils.copy(node, new SAAJStreamWriter(part));
} else {
SOAPEnvelope env = soapMessage.getSOAPPart().getEnvelope();
if (node == null) {
adjustPrefixes(env, (String) message.get(ReadHeadersInterceptor.ENVELOPE_PREFIX), (String) message.get(ReadHeadersInterceptor.BODY_PREFIX));
}
List<XMLEvent> events = (List<XMLEvent>) message.get(ReadHeadersInterceptor.ENVELOPE_EVENTS);
applyEvents(events, env);
SOAPBody body = soapMessage.getSOAPBody();
events = (List<XMLEvent>) message.get(ReadHeadersInterceptor.BODY_EVENTS);
applyEvents(events, body);
}
message.setContent(Node.class, soapMessage.getSOAPPart());
Collection<Attachment> atts = message.getAttachments();
if (atts != null) {
for (Attachment a : atts) {
if (a.getDataHandler().getDataSource() instanceof AttachmentDataSource) {
try {
((AttachmentDataSource) a.getDataHandler().getDataSource()).cache(message);
} catch (IOException e) {
throw new Fault(e);
}
}
AttachmentPart ap = soapMessage.createAttachmentPart(a.getDataHandler());
Iterator<String> i = a.getHeaderNames();
while (i != null && i.hasNext()) {
String h = i.next();
String val = a.getHeader(h);
ap.addMimeHeader(h, val);
}
if (StringUtils.isEmpty(ap.getContentId())) {
ap.setContentId(a.getId());
}
soapMessage.addAttachmentPart(ap);
}
}
// replace header element if necessary
if (message.hasHeaders()) {
replaceHeaders(soapMessage, message);
}
if (soapMessage.getSOAPPart().getEnvelope().getHeader() == null) {
soapMessage.getSOAPPart().getEnvelope().addHeader();
}
// If we have an xmlReader that already is counting the attributes and such
// then we don't want to rely on the system level defaults in StaxUtils.copy
// CXF-6173
boolean secureReader = StaxUtils.isSecureReader(xmlReader, message);
StaxUtils.copy(xmlReader, new SAAJStreamWriter(soapMessage.getSOAPPart(), soapMessage.getSOAPPart().getEnvelope().getBody()), true, !secureReader);
DOMSource bodySource = new DOMSource(soapMessage.getSOAPPart().getEnvelope().getBody());
xmlReader = StaxUtils.createXMLStreamReader(bodySource);
xmlReader.nextTag();
// move past body tag
xmlReader.nextTag();
message.setContent(XMLStreamReader.class, xmlReader);
} catch (SOAPException soape) {
throw new SoapFault(new org.apache.cxf.common.i18n.Message("SOAPHANDLERINTERCEPTOR_EXCEPTION", BUNDLE), soape, message.getVersion().getSender());
} catch (XMLStreamException e) {
throw new SoapFault(new org.apache.cxf.common.i18n.Message("SOAPHANDLERINTERCEPTOR_EXCEPTION", BUNDLE), e, message.getVersion().getSender());
}
}
use of javax.xml.soap.SOAPException in project cxf by apache.
the class SAAJStreamWriter method createElementNS.
@Override
protected Element createElementNS(String ns, String pfx, String local) {
Element cur = getCurrentNode();
if (cur instanceof SOAPBody) {
try {
if (StringUtils.isEmpty(pfx) && StringUtils.isEmpty(ns)) {
Element el = ((SOAPBody) cur).addBodyElement(new QName(local));
cur.removeChild(el);
return el;
}
Element el = ((SOAPBody) cur).addBodyElement(new QName(ns, local, pfx == null ? "" : pfx));
cur.removeChild(el);
return el;
} catch (SOAPException e) {
// ignore
}
} else if (cur instanceof SOAPHeader) {
try {
Element el = ((SOAPHeader) cur).addHeaderElement(new QName(ns, local, pfx == null ? "" : pfx));
cur.removeChild(el);
return el;
} catch (SOAPException e) {
// ignore
}
} else if (cur instanceof SOAPElement) {
try {
Element el = null;
if (StringUtils.isEmpty(pfx) && StringUtils.isEmpty(ns)) {
el = ((SOAPElement) cur).addChildElement(local, "", "");
} else {
el = ((SOAPElement) cur).addChildElement(local, pfx == null ? "" : pfx, ns);
adjustPrefix(el, pfx);
}
cur.removeChild(el);
return el;
} catch (SOAPException e) {
// ignore
}
}
return super.createElementNS(ns, pfx, local);
}
use of javax.xml.soap.SOAPException in project cxf by apache.
the class HandlerChainInvokerTest method testHandleMessageThrowsProtocolExceptionOutbound.
@Test
public void testHandleMessageThrowsProtocolExceptionOutbound() {
message = new SoapMessage(message);
lmc = new LogicalMessageContextImpl(message);
pmc = new WrappedMessageContext(message);
ProtocolException pe = new ProtocolException("banzai");
protocolHandlers[2].setException(pe);
invoker.setRequestor(true);
assertTrue(invoker.isOutbound());
boolean continueProcessing = true;
invoker.setLogicalMessageContext(lmc);
continueProcessing = invoker.invokeLogicalHandlers(false, lmc);
assertTrue(continueProcessing);
// create an empty SOAP body for testing
try {
pmc = new SOAPMessageContextImpl(message);
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage soapMessage = factory.createMessage();
((SOAPMessageContext) pmc).setMessage(soapMessage);
} catch (SOAPException e) {
// do nothing
}
try {
invoker.setProtocolMessageContext(pmc);
continueProcessing = invoker.invokeProtocolHandlers(false, pmc);
fail("did not get expected exception");
} catch (ProtocolException e) {
assertEquals("banzai", e.getMessage());
}
assertFalse((Boolean) pmc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY));
assertFalse((Boolean) lmc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY));
assertTrue(invoker.isInbound());
// the message is replaced by fault message
Source responseMessage = lmc.getMessage().getPayload();
// System.out.println(getSourceAsString(responseMessage));
assertTrue(getSourceAsString(responseMessage).indexOf("banzai") > -1);
// assertFalse(continueProcessing);
assertEquals(1, logicalHandlers[0].getHandleMessageCount());
assertEquals(1, logicalHandlers[1].getHandleMessageCount());
assertEquals(1, logicalHandlers[2].getHandleMessageCount());
assertEquals(1, logicalHandlers[3].getHandleMessageCount());
assertEquals(1, protocolHandlers[0].getHandleMessageCount());
assertEquals(1, protocolHandlers[1].getHandleMessageCount());
assertEquals(1, protocolHandlers[2].getHandleMessageCount());
assertEquals(0, protocolHandlers[3].getHandleMessageCount());
assertTrue(logicalHandlers[3].getInvokeOrderOfHandleMessage() < protocolHandlers[0].getInvokeOrderOfHandleMessage());
assertTrue(protocolHandlers[1].getInvokeOrderOfHandleMessage() < protocolHandlers[2].getInvokeOrderOfHandleMessage());
assertEquals(1, logicalHandlers[0].getCloseCount());
assertEquals(1, logicalHandlers[1].getCloseCount());
assertEquals(1, logicalHandlers[2].getCloseCount());
assertEquals(1, logicalHandlers[3].getCloseCount());
assertEquals(1, protocolHandlers[0].getCloseCount());
assertEquals(1, protocolHandlers[1].getCloseCount());
assertEquals(1, protocolHandlers[2].getCloseCount());
assertEquals(0, protocolHandlers[3].getCloseCount());
assertTrue(protocolHandlers[2].getInvokeOrderOfClose() < protocolHandlers[1].getInvokeOrderOfClose());
assertTrue(protocolHandlers[0].getInvokeOrderOfClose() < logicalHandlers[3].getInvokeOrderOfClose());
assertEquals(1, logicalHandlers[0].getHandleFaultCount());
assertEquals(1, logicalHandlers[1].getHandleFaultCount());
assertEquals(1, logicalHandlers[2].getHandleFaultCount());
assertEquals(1, logicalHandlers[3].getHandleFaultCount());
assertEquals(1, protocolHandlers[0].getHandleFaultCount());
assertEquals(1, protocolHandlers[1].getHandleFaultCount());
assertEquals(0, protocolHandlers[2].getHandleFaultCount());
assertEquals(0, protocolHandlers[3].getHandleFaultCount());
assertTrue(protocolHandlers[0].getInvokeOrderOfHandleFault() < logicalHandlers[3].getInvokeOrderOfHandleFault());
assertTrue(protocolHandlers[2].getInvokeOrderOfHandleFault() < protocolHandlers[1].getInvokeOrderOfHandleFault());
}
Aggregations