List of usage examples for javax.xml.soap SOAPConstants SOAP_RECEIVER_FAULT
QName SOAP_RECEIVER_FAULT
To view the source code for javax.xml.soap SOAPConstants SOAP_RECEIVER_FAULT.
Click Source Link
From source file:eu.domibus.ebms3.sender.EbMS3MessageBuilder.java
public SOAPMessage buildSOAPFaultMessage(Error ebMS3error) throws EbMS3Exception { SignalMessage signalMessage = new SignalMessage(); signalMessage.getError().add(ebMS3error); SOAPMessage soapMessage = this.buildSOAPMessage(signalMessage, null); try {/*ww w.j a va2s. c o m*/ // An ebMS signal does not require any SOAP Body: if the SOAP Body is not empty, it MUST be ignored by the MSH, as far as interpretation of the signal is concerned. //TODO: locale is static soapMessage.getSOAPBody().addFault(SOAPConstants.SOAP_RECEIVER_FAULT, "An error occurred while processing your request. Please check the message header for more details.", Locale.ENGLISH); } catch (SOAPException e) { throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0004, "An error occurred while processing your request. Please check the message header for more details.", e, MSHRole.RECEIVING); } return soapMessage; }
From source file:com.centurylink.mdw.hub.servlet.SoapServlet.java
/** * Allow version specific factory passed in to support SOAP 1.1 and 1.2 * <b>Important</b> Faults are treated differently for 1.1 and 1.2 For 1.2 * you can't use the elementName otherwise it throws an exception * * @see http://docs.oracle.com/cd/E19159-01/819-3669/bnbip/index.html * * @param factory/*from ww w . ja v a2 s . c om*/ * @param code * @param message * @return Xml fault string * @throws SOAPException * @throws TransformerException */ protected String createSoapFaultResponse(String soapVersion, String code, String message) throws SOAPException, TransformerException { SOAPMessage soapMessage = getSoapMessageFactory(soapVersion).createMessage(); SOAPBody soapBody = soapMessage.getSOAPBody(); /** * Faults are treated differently for 1.1 and 1.2 For 1.2 you can't use * the elementName otherwise it throws an exception * * @see http://docs.oracle.com/cd/E19159-01/819-3669/bnbip/index.html */ SOAPFault fault = null; if (soapVersion.equals(SOAPConstants.SOAP_1_1_PROTOCOL)) { // existing 1.1 functionality fault = soapBody.addFault(soapMessage.getSOAPHeader().getElementName(), message); if (code != null) fault.setFaultCode(code); } else if (soapVersion.equals(SOAPConstants.SOAP_1_2_PROTOCOL)) { /** * For 1.2 there are only a set number of allowed codes, so we can't * just use any one like what we did in 1.1. The recommended one to * use is SOAPConstants.SOAP_RECEIVER_FAULT */ fault = soapBody.addFault(SOAPConstants.SOAP_RECEIVER_FAULT, code == null ? message : code + " : " + message); } return DomHelper.toXml(soapMessage.getSOAPPart().getDocumentElement()); }
From source file:org.apache.axis2.saaj.SOAPFactoryTest.java
@Validated @Test//from w ww . jav a 2s . c o m public void testCreateFault() { try { SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); //SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault sf = factory.createFault("This is the fault reason.", SOAPConstants.SOAP_RECEIVER_FAULT); assertNotNull(sf); assertTrue(sf instanceof SOAPFault); QName fc = sf.getFaultCodeAsQName(); //Expect FaultCode="+SOAPConstants.SOAP_RECEIVER_FAULT Iterator i = sf.getFaultReasonTexts(); if (i == null) { log.info("Call to getFaultReasonTexts() returned null iterator"); } String reason = ""; while (i.hasNext()) { reason += (String) i.next(); } assertNotNull(reason); assertTrue(reason.indexOf("This is the fault reason.") > -1); assertTrue(fc.equals(SOAPConstants.SOAP_RECEIVER_FAULT)); } catch (SOAPException e) { fail("Caught unexpected SOAPException"); } }
From source file:org.apache.axis2.saaj.SOAPFactoryTest.java
@Test public void testCreateFault1() { try {// w w w. j a v a 2 s .c om //SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault sf = factory.createFault("This is the fault reason.", SOAPConstants.SOAP_RECEIVER_FAULT); assertNotNull(sf); QName fc = sf.getFaultCodeAsQName(); Iterator i = sf.getFaultReasonTexts(); String reason = ""; while (i.hasNext()) { reason += (String) i.next(); } log.info("Actual ReasonText=" + reason); assertNotNull(reason); assertTrue(reason.indexOf("This is the fault reason.") > -1); assertTrue(fc.equals(SOAPConstants.SOAP_RECEIVER_FAULT)); } catch (SOAPException e) { //Caught expected SOAPException } catch (Exception e) { fail("Exception: " + e); } }