List of usage examples for javax.xml.soap SOAPBody addFault
public SOAPFault addFault() throws SOAPException;
From source file:com.hiperium.integration.access.control.SoapSessionHandler.java
/** * /* ww w .j a v a 2 s.c o m*/ * @param msg * @param reason */ private void generateFault(SOAPMessage msg, String reason) { try { SOAPBody body = msg.getSOAPBody(); SOAPFault fault = body.addFault(); fault.setFaultString(reason); throw new SOAPFaultException(fault); } catch (SOAPException e) { LOGGER.error(e.getMessage(), e); } }
From source file:de.drv.dsrv.spoc.web.webservice.spring.SpocMessageDispatcherServlet.java
private void createExtraErrorAndWriteResponse(final HttpServletResponse httpServletResponse, final String errorText) throws SOAPException, JAXBException, DatatypeConfigurationException, IOException { final MessageFactory factory = MessageFactory.newInstance(); final SOAPMessage message = factory.createMessage(); final SOAPBody body = message.getSOAPBody(); final SOAPFault fault = body.addFault(); final QName faultName = new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE, FaultCode.CLIENT.toString()); fault.setFaultCode(faultName);/*from w ww. ja va 2 s . c o m*/ fault.setFaultString(this.soapFaultString); final Detail detail = fault.addDetail(); final ExtraJaxbMarshaller extraJaxbMarshaller = new ExtraJaxbMarshaller(); final ExtraErrorReasonType reason = ExtraErrorReasonType.INVALID_REQUEST; final ExtraErrorType extraError = ExtraHelper.generateError(reason, this.extraErrorCode, errorText); extraJaxbMarshaller.marshalExtraError(extraError, detail); // Schreibt die SOAPMessage in einen String. final ByteArrayOutputStream out = new ByteArrayOutputStream(); message.writeTo(out); // Das Encoding, in dem sich die Message rausschreibt, kann man als // Property abfragen. final Object encodingProperty = message.getProperty(SOAPMessage.CHARACTER_SET_ENCODING); String soapMessageEncoding = "UTF-8"; if (encodingProperty != null) { soapMessageEncoding = encodingProperty.toString(); } final String errorXml = out.toString(soapMessageEncoding); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.setContentType("text/xml"); httpServletResponse.getWriter().write(errorXml); httpServletResponse.getWriter().flush(); httpServletResponse.getWriter().close(); }
From source file:com.qubit.solution.fenixedu.bennu.webservices.services.server.BennuWebServiceHandler.java
private void generateSOAPErrorMessage(SOAPMessage msg, String reason) { try {/* ww w .j av a 2s. co m*/ SOAPBody soapBody = msg.getSOAPPart().getEnvelope().getBody(); SOAPFault soapFault = soapBody.addFault(); soapFault.setFaultString(reason); throw new SOAPFaultException(soapFault); } catch (SOAPException e) { } }
From source file:cn.com.ttblog.ssmbootstrap_table.webservice.LicenseHandler.java
@SuppressWarnings("unchecked") @Override//from w w w.ja va 2s. co m public boolean handleMessage(SOAPMessageContext context) { try { Boolean out = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); logger.debug("LicenseHandler:{}", out); if (!out) { SOAPMessage message = context.getMessage(); logger.debug("SOAPMessage:{}", ToStringBuilder.reflectionToString(message)); SOAPEnvelope enve = message.getSOAPPart().getEnvelope(); SOAPHeader header = enve.getHeader(); SOAPBody body = enve.getBody(); Node bn = body.getChildNodes().item(0); String partname = bn.getLocalName(); if ("getUser".equals(partname)) { if (header == null) { // ? SOAPFault fault = body.addFault(); fault.setFaultString("??!"); throw new SOAPFaultException(fault); } Iterator<SOAPHeaderElement> iterator = header.extractAllHeaderElements(); if (!iterator.hasNext()) { // ? SOAPFault fault = body.addFault(); fault.setFaultString("??!"); throw new SOAPFaultException(fault); } while (iterator.hasNext()) { SOAPHeaderElement ele = iterator.next(); System.out.println(ele.getTextContent()); } } } } catch (SOAPException e) { e.printStackTrace(); } return true; }
From source file:de.drv.dsrv.spoc.web.webservice.jax.ExtraSchemaValidationHandler.java
private boolean handleException(final SOAPBody soapBody, final String errorText, final ExtraErrorReasonType reason) { try {/*from w w w . j a v a 2 s .c o m*/ // Bisherigen Inhalt des SOAP-Bodys entfernen soapBody.removeContents(); // SOAP-Fault erzeugen final SOAPFault fault = soapBody.addFault(); fault.setFaultString(this.soapFaultString); fault.setFaultCode(new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE, SOAP_FAULT_CODE)); final ExtraJaxbMarshaller extraJaxbMarshaller = new ExtraJaxbMarshaller(); final ExtraErrorType extraError = ExtraHelper.generateError(reason, this.extraErrorCode, errorText); extraJaxbMarshaller.marshalExtraError(extraError, fault.addDetail()); return false; } catch (final Exception e) { LOG.error("Fehler bei Exception-Behandlung.", e); throw new WebServiceException(resourceBundle.getString(Messages.ERROR_NON_EXTRA_TEXT)); } }
From source file:org.cleverbus.core.reqres.RequestResponseTest.java
/** * Test saving synchronous request/response where response is failed SOAP fault exception. *///from ww w . ja v a2s.c om @Test public void testSavingRequestWithSOAPFaultResponse() throws Exception { final String soapFault = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<SOAP-ENV:Fault xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" + " <faultcode>SOAP-ENV:Server</faultcode>" + " <faultstring>There is one error</faultstring>" + "</SOAP-ENV:Fault>"; // prepare target route prepareTargetRoute(TARGET_URI, new Processor() { @Override public void process(Exchange exchange) throws Exception { exchange.getOut().setBody(soapFault); // create SOAP Fault message SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); SOAPBody soapBody = soapEnvelope.getBody(); // Set fault code and fault string SOAPFault fault = soapBody.addFault(); fault.setFaultCode(new QName("http://schemas.xmlsoap.org/soap/envelope/", "Server")); fault.setFaultString("There is one error"); SoapMessage message = new SaajSoapMessage(soapMessage); throw new SoapFaultClientException(message); } }); // action mock.expectedMessageCount(0); try { producer.sendBody(REQUEST); fail("Target route was thrown exception."); } catch (CamelExecutionException ex) { assertRequestResponse(REQUEST, null, "org.springframework.ws.soap.client.SoapFaultClientException: There is one error", soapFault); } }
From source file:org.jasig.portal.security.provider.saml.SAMLDelegatedAuthenticationService.java
private Document createSOAPFaultDocument(String faultString) throws SOAPException { MessageFactory factory = MessageFactory.newInstance(); SOAPMessage message = factory.createMessage(); SOAPPart sp = message.getSOAPPart(); SOAPEnvelope se = sp.getEnvelope(); se.setPrefix(SOAP_PREFIX);/*ww w. j av a 2 s.co m*/ se.getHeader().detachNode(); se.addHeader(); se.getBody().detachNode(); SOAPBody body = se.addBody(); SOAPFault fault = body.addFault(); Name faultCode = se.createName("Client", null, SOAPConstants.URI_NS_SOAP_ENVELOPE); fault.setFaultCode(faultCode); fault.setFaultString(faultString); return se.getOwnerDocument(); }
From source file:org.wso2.carbon.identity.sso.saml.util.SAMLSOAPUtils.java
/** * * Creates a SOAP Fault message including the fault code and fault string. * @param faultString detailed error message * @param faultcode/* w w w. j av a2s. co m*/ * @return */ public static String createSOAPFault(String faultString, String faultcode) throws TransformerException, SOAPException { SOAPMessage soapMsg; MessageFactory factory = MessageFactory.newInstance(); soapMsg = factory.createMessage(); SOAPPart part = soapMsg.getSOAPPart(); SOAPEnvelope envelope = part.getEnvelope(); SOAPBody body = envelope.getBody(); SOAPFault fault = body.addFault(); fault.setFaultString(faultString); fault.setFaultCode(new QName(SAMLECPConstants.SOAPNamespaceURI.SOAP_NAMESPACE_URI, faultcode)); return convertSOAPMsgToString(soapMsg).replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", ""); }