@Override public String getFaultString() { return getFault().getFaultString(); }
@Override public QName getFaultCodeAsQName() { return getFault().getFaultCodeAsQName(); }
@Override public String getFaultActor() { return getFault().getFaultActor(); }
@Override public boolean handleFault(SOAPMessageContext context) { if (!shouldExecute(context)) { return true; } final Span span = tracingPlugin.getTracer().scopeManager().active().span(); Tags.ERROR.set(span, Boolean.TRUE); try { final SOAPFault fault = context.getMessage().getSOAPBody().getFault(); span.setTag("soap.fault.reason", fault.getFaultString()); span.setTag("soap.fault.code", fault.getFaultCode()); } catch (SOAPException e) { logger.warn("Exception while trying to access SOAP fault (this exception was suppressed)", e); } return true; }
n = ((Document)n).getDocumentElement(); if (n.getLocalName().equals(sayHi.getLocalPart())) { response.setNode(sayHiResponse); } else if (n.getLocalName().equals(greetMe.getLocalPart())) { Element el = DOMUtils.getFirstElement(n); String s = DOMUtils.getContent(el); if ("throwFault".equals(s.trim())) { try { SOAPFactory f = SOAPFactory.newInstance(); SOAPFault soapFault = f.createFault(); soapFault.setFaultString("Test Fault String ****"); Detail detail = soapFault.addDetail(); detail = soapFault.getDetail(); QName qName = new QName("http://www.Hello.org/greeter", "TestFault", "ns"); DetailEntry de = detail.addDetailEntry(qName); qName = new QName("http://www.Hello.org/greeter", "ErrorCode", "ns"); SOAPElement errorElement = de.addChildElement(qName); errorElement.setTextContent("errorcode"); throw new SOAPFaultException(soapFault); } catch (SOAPException e) { e.printStackTrace();
soapFault.setFaultString(sf.getFault().getFaultString()); SAAJUtils.setFaultCode(soapFault, sf.getFault().getFaultCodeAsQName()); soapFault.setFaultActor(sf.getFault().getFaultActor()); if (sf.getFault().hasDetail()) { Node nd = soapMessage.getSOAPPart().importNode(sf.getFault().getDetail(), true); nd = nd.getFirstChild(); soapFault.addDetail(); while (nd != null) { soapFault.getDetail().appendChild(nd); nd = nd.getNextSibling(); soapFault.setFaultString(sf.getReason()); SAAJUtils.setFaultCode(soapFault, sf.getFaultCode()); if (sf.hasDetails()) { soapFault.addDetail(); Node nd = soapMessage.getSOAPPart().importNode(sf.getDetail(), true); nd = nd.getFirstChild(); while (nd != null) { soapFault.getDetail().appendChild(nd); nd = nd.getNextSibling(); new QName("http://cxf.apache.org/faultcode", "HandlerFault")); soapFault.setFaultString(exception.getMessage()); e.printStackTrace();
private SOAPFaultException createSOAPFaultException(String faultString) { SOAPFault soapFault; try { SOAPFactory soapFactory = SOAPFactory.newInstance(); soapFault = soapFactory.createFault(); soapFault.setFaultString(faultString); } catch (SOAPException e) { throw new RuntimeException("SOAP error"); } return new SOAPFaultException(soapFault); }
@Override public SOAPFault addFault(SOAPBody body, QName faultCode, String faultString, Locale locale) throws SOAPException { SOAPFault fault = body.addFault(); if (StringUtils.hasLength(faultCode.getNamespaceURI()) && StringUtils.hasLength(QNameUtils.getPrefix(faultCode))) { fault.addNamespaceDeclaration(faultCode.getPrefix(), faultCode.getNamespaceURI()); fault.setFaultCode(faultCode.getPrefix() + ":" + faultCode.getLocalPart()); } else if (faultCode.getNamespaceURI().equals(body.getElementName().getURI())) { fault.setFaultCode(body.getElementName().getPrefix() + ":" + faultCode.getLocalPart()); } else { fault.setFaultCode(faultCode.getLocalPart()); } fault.setFaultString(faultString); return fault; }
private static void setFaultDetail(SOAPFault fault, Throwable cause) { try { //Add Detail element to the fault. Detail detail = fault.addDetail(); QName name = new QName("https://xwss.dev.java.net", "FaultDetail", "xwssfault"); DetailEntry entry = detail.addDetailEntry(name); String exception = "Cause Not Set"; if (cause != null) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); PrintWriter s = new PrintWriter(bos); cause.printStackTrace(s); s.flush(); exception = bos.toString(); } entry.addTextNode(exception); } catch (SOAPException ex) { //ignore for now } } }
private SOAPFaultException createSOAPFaultExceptionWithDetail(String faultString) throws SOAPException { SOAPFault fault = SOAPFactory.newInstance().createFault(); QName faultName = new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE, "Server"); SAAJUtils.setFaultCode(fault, faultName); fault.setFaultActor("http://gizmos.com/orders"); fault.setFaultString(faultString); Detail detail = fault.addDetail(); QName entryName = new QName("http://gizmos.com/orders/", "order", "PO"); DetailEntry entry = detail.addDetailEntry(entryName); entry.addTextNode("Quantity element does not have a value"); QName entryName2 = new QName("http://gizmos.com/orders/", "order", "PO"); DetailEntry entry2 = detail.addDetailEntry(entryName2); entry2.addTextNode("Incomplete address: no zip code"); return new SOAPFaultException(fault); }
// Create a new SOAP 1.2 message from the message factory and obtain the SOAP body MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); SOAPMessage message = factory.createMessage(); SOAPBody soapBody = message.getSOAPPart().getEnvelope().getBody(); // get the fault SOAPFault fault = soapBody.addFault(); // since this is an error generated from the business application // where SOAPValue is the standard value code "Sender|Reciever...etc" QName faultName = new QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, SOAPValue); fault.setFaultCode(faultName); // set the fault reason text // where languageLocale is the passed language local, the Locale object can be used fault.addFaultReasonText(errorMessage, languageLocale); // generate the detail Detail detail = fault.addDetail(); // add the error code entry QName customCodeEntryName = new QName("http://www.example.com/", "customCode", "ns1"); DetailEntry customCodeEntry = detail.addDetailEntry(customCodeEntryName); customCodeEntry.addTextNode("this is custom 123 code"); // throw the exception that shall generate the SOAP fault response XML message throw new SOAPFaultException(fault);
public GreetMeResponse greetMe(GreetMeRequest gmr) { if ("fault".equals(gmr.getName())) { try { SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault fault = factory.createFault("this is a fault string!", new QName("http://foo", "FooCode")); fault.setFaultActor("mr.actor"); fault.addDetail().addChildElement("test").addTextNode("TestText"); throw new SOAPFaultException(fault); } catch (SOAPException ex) { throw new WebServiceException(ex); } } else if ("emptyfault".equals(gmr.getName())) { throw new RuntimeException("Empty!"); } GreetMeResponse resp = new GreetMeResponse(); resp.setName(gmr.getName()); return resp; }
@Override public QName getFaultCode(SOAPFault fault) { String code = fault.getFaultCode(); int idx = code.indexOf(':'); if (idx != -1) { String prefix = code.substring(0, idx); String namespace = fault.getNamespaceURI(prefix); if (StringUtils.hasLength(namespace)) { return QNameUtils.createQName(namespace, code.substring(idx + 1), prefix); } } return new QName(code); }
public Object read(QName name, int idx, T input) { SOAPFault fault = (SOAPFault)input; if (fault.getDetail() != null) { NodeList list = fault.getDetail().getChildNodes(); faultName = new QName(entry.getNamespaceURI(), entry.getLocalName()); Constructor<?> ctor = clazz.getConstructor(String.class, obj.getClass()); return ctor.newInstance(fault.getFaultString(), obj); return new SOAPFaultException(fault);
@Override protected Object makeCallError(String uniqueId, String action, String errorCode, String errorDescription) { SOAPMessage message = null; try { MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); message = messageFactory.createMessage(); message.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true"); createMessageHeader(uniqueId, String.format("%sResponse", action), true, message); SOAPFault soapFault = message.getSOAPBody().addFault(); soapFault.setFaultCode(blameSomeone(errorCode)); soapFault.setFaultString(errorDescription); soapFault.appendFaultSubcode(new QName(hostInfo.getNamespace(), errorCode)); } catch (SOAPException e) { logger.warn("makeCallError() failed", e); } return message; }
if (!soapFault.getNamespaceURI().equals(((SoapFault)ex).getFaultCode().getNamespaceURI()) && SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE .equals(((SoapFault)ex).getFaultCode().getNamespaceURI())) { final boolean isSoap11 = SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(soapFault.getNamespaceURI()); soapFault.setFaultString(((SoapFault)ex).getReason()); } else { soapFault.setFaultString(((SoapFault)ex).getReason(), stringToLocale(((SoapFault)ex).getLang())); String role = ((SoapFault)ex).getRole(); if (role != null) { soapFault.setFaultActor(role); soapFault.appendFaultSubcode(fsc); Node nd = soapFault.getOwnerDocument().importNode(((SoapFault)ex).getDetail(), true); nd = nd.getFirstChild(); soapFault.addDetail(); while (nd != null) { Node next = nd.getNextSibling(); soapFault.getDetail().appendChild(nd); nd = next; String msg = ex.getMessage(); if (msg != null) { soapFault.setFaultString(msg);
SOAPFault newFault = body.getFault(); if (newFault != null) { QName code = newFault.getFaultCodeAsQName(); String string = newFault.getFaultString(); String actor = newFault.getFaultActor(); System.err.println("SOAP fault contains... Fault code = \"" + code.toString() + "\""); System.err.println("Fault string = \"" + string + "\""); if (actor != null) { throw new SOAPFaultException(newFault); } else { se.printStackTrace();
SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME); soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_TerminationCoordinatorProcessorImpl_6()); throw new SOAPFaultException(soapFault); SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME); soapFault.addDetail().addDetailEntry(ArjunaTXConstants.TRANSACTIONROLLEDBACK_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_TerminationCoordinatorProcessorImpl_7()); throw new SOAPFaultException(soapFault); SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_RECEIVER.getValue(), ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME); soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_TerminationCoordinatorProcessorImpl_8()); throw new SOAPFaultException(soapFault); SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_RECEIVER.getValue(), ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME); soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_TerminationCoordinatorProcessorImpl_8()); throw new SOAPFaultException(soapFault); SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME); soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_TerminationCoordinatorProcessorImpl_6()); throw new SOAPFaultException(soapFault); se.printStackTrace(System.err); throw new ProtocolException(se);
@Test public void testNonAnonSoap12Fault() throws Exception { try { AddNumbersPortType port = getNonAnonPort(); ((BindingProvider)port).getRequestContext() .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT2 + "/jaxws/soap12/add"); port.addNumbers(1, 2); fail("expected SOAPFaultException"); } catch (SOAPFaultException e) { assertTrue("expected non-anonymous required message", e.getMessage().contains("Found anonymous address but non-anonymous required")); assertTrue("expected sender faultCode", e.getFault().getFaultCode().contains("Sender")); assertTrue("expected OnlyNonAnonymousAddressSupported fault subcode", e.getFault() .getFaultSubcodes() .next() .toString() .contains("{http://www.w3.org/2005/08/addressing}OnlyNonAnonymousAddressSupported")); } }
public static SOAPFaultException createSOAPFaultEx(SOAPFactory soapFactory, QName faultCode, String message) { SOAPFault sf = null; try { sf = soapFactory.createFault(); sf.setFaultCode(faultCode); sf.setFaultString(message); } catch (SOAPException se) { se.printStackTrace(); } return new SOAPFaultException(sf); }