// 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);
/** * It can either e within an extra tag, or directly. */ private Iterator detailChildrenIterator(Detail detail) { /* sb.append("<ns2:AccessDeniedWebServiceException xmlns:ns2=\"http://exceptionthrower.system.services.v4_0.soap.server.nameapi.org/\">"); sb.append("<blame>CLIENT</blame>"); sb.append("<errorCode>2101</errorCode>"); sb.append("<faultCause>AccessDenied</faultCause>"); */ DetailEntry firstDetailEntry = getFirstDetailEntry(detail); if (firstDetailEntry!=null) { String localName = firstDetailEntry.getElementName().getLocalName(); if (localName.endsWith("Exception")) { //got a subtag return firstDetailEntry.getChildElements(); } } return detail.getDetailEntries(); } private List<SOAPElement> getFaultInfoElements(@NotNull Detail detail) {
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);
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(); DetailEntry de = detail.addDetailEntry(qName); SOAPElement errorElement = de.addChildElement(qName); errorElement.setTextContent("errorcode"); throw new SOAPFaultException(soapFault); } catch (SOAPException e) { e.printStackTrace();
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); }
throw new SOAPException("Operation not found: " + operationName); Detail d = fault.addDetail(); DetailEntry de = d.addDetailEntry(fe.getFaultName()); SOAPElement dece = de.addChildElement("message"); if (fe.getMessage() != null) { dece.addTextNode(fe.getMessage()); response.getSOAPBody().addChildElement(soapFactory.createElement(element));
SOAPBody body = message.getSOAPBody(); SOAPFault fault = body.addFault(); fault.setFaultCode("Server"); fault.setFaultString("Unexpected server error."); Detail detail = fault.addDetail(); Name entryName = envelope.createName("message"); DetailEntry entry = detail.addDetailEntry(entryName); entry.addTextNode("The server is not able to complete the request. Internal error.");
Name faultCodeName = soapFault.getFaultCodeAsName(); QName faultCode = new QName(faultCodeName.getURI(), faultCodeName.getLocalName(), faultCodeName.getPrefix()); String faultString = soapFault.getFaultString(); String faultActor = soapFault.getFaultActor(); Detail detail = soapFault.getDetail(); TypeMapping typeMapping = serContext.getTypeMapping(); Iterator it = detail.getDetailEntries(); while (it.hasNext()) Name deName = deElement.getElementName(); QName xmlName = new QName(deName.getURI(), deName.getLocalName()); String attrValue = deElement.getAttribute("xmlns:" + prefix); if (nsURI.length() > 0 && attrValue.length() == 0) deElement.addNamespaceDeclaration(prefix, nsURI);
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 } } }
@Override public void addTextNode(DetailEntry detailEntry, String text) throws SOAPException { detailEntry.addTextNode(text); }
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_CompletionCoordinatorProcessorImpl_1()); throw new SOAPFaultException(soapFault); SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME); soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_2()); throw new SOAPFaultException(soapFault); SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME); soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_2()); 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_CompletionCoordinatorProcessorImpl_5()); throw new SOAPFaultException(soapFault); se.printStackTrace(System.err); throw new ProtocolException(se);
} else if (v.contains("throwFault")) { try { SOAPFactory f = SOAPFactory.newInstance(); SOAPFault soapFault = f.createFault(); soapFault.setFaultString("Test Fault String ****"); Detail detail = soapFault.addDetail(); detail = soapFault.getDetail(); DetailEntry de = detail.addDetailEntry(qName); SOAPElement errorElement = de.addChildElement(qName); errorElement.setTextContent("errorcode"); throw new SOAPFaultException(soapFault); } catch (SOAPException ex) {
/** * Creates a new, generic SOAP fault to be used when something goes wrong in a partner track and * other tracks must be notified. * * @return */ public static String generateGenericSOAPFault() { try { MessageFactory mFactory= MessageFactory.newInstance(); SOAPMessage message= mFactory.createMessage(); SOAPBody body= message.getSOAPBody(); SOAPFault fault= body.addFault( BPELUnitConstants.SOAP_FAULT_CODE_CLIENT, BPELUnitConstants.SOAP_FAULT_DESCRIPTION); Detail detail= fault.addDetail(); DetailEntry entry= detail.addDetailEntry(new QName("http://www.bpelunit.org/framework/error", "BPELUnitFault")); entry.addTextNode("The BPELUnit test framework has detected a test failure or error. This test case is aborted."); ByteArrayOutputStream b= new ByteArrayOutputStream(); message.writeTo(b); return b.toString(); } catch (Exception e) { return "(internal fault)"; } }
@Override public void addTextNode(DetailEntry detailEntry, String text) throws SOAPException { detailEntry.addTextNode(text); }
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_CompletionCoordinatorProcessorImpl_6()); throw new SOAPFaultException(soapFault); SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME); soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_7()); throw new SOAPFaultException(soapFault); SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME); soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_7()); 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_CompletionCoordinatorProcessorImpl_10()); throw new SOAPFaultException(soapFault); se.printStackTrace(System.err); throw new ProtocolException(se);
@Override public void addTextNode(DetailEntry detailEntry, String text) throws SOAPException { detailEntry.addTextNode(text); }
/** * It can either e within an extra tag, or directly. */ private Iterator detailChildrenIterator(Detail detail) { /* sb.append("<ns2:AccessDeniedWebServiceException xmlns:ns2=\"http://exceptionthrower.system.services.v4_0.soap.server.nameapi.org/\">"); sb.append("<blame>CLIENT</blame>"); sb.append("<errorCode>2101</errorCode>"); sb.append("<faultCause>AccessDenied</faultCause>"); */ DetailEntry firstDetailEntry = getFirstDetailEntry(detail); if (firstDetailEntry!=null) { String localName = firstDetailEntry.getElementName().getLocalName(); if (localName.endsWith("Exception")) { //got a subtag return firstDetailEntry.getChildElements(); } } return detail.getDetailEntries(); } private List<SOAPElement> getFaultInfoElements(@NotNull Detail detail) {
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_CompletionCoordinatorProcessorImpl_6()); throw new SOAPFaultException(soapFault); SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME); soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_7()); throw new SOAPFaultException(soapFault); SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME); soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_7()); 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_CompletionCoordinatorProcessorImpl_10()); throw new SOAPFaultException(soapFault); se.printStackTrace(System.err); throw new ProtocolException(se);
@Override public void addText(String text) { try { getSaajDetailEntry().addTextNode(text); } catch (SOAPException ex) { throw new SaajSoapFaultException(ex); } }
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);