List of usage examples for javax.xml.soap SOAPFault addDetail
public Detail addDetail() throws SOAPException;
From source file:net.bpelunit.framework.control.util.BPELUnitUtil.java
/** * Creates a new, generic SOAP fault to be used when something goes wrong in a partner track and * other tracks must be notified.// w w w .jav a 2 s . c o m * * @return */ public static SOAPMessage 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."); return message; } catch (Exception e) { return null; } }
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 w w.j a v a 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: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 2s. c om*/ // 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:edu.duke.cabig.c3pr.webservice.studyimportexport.impl.StudyImportExportImpl.java
/** * Creates the soap fault.//from w ww .ja v a 2 s . c om * * @param msg the msg * @return the sOAP fault */ private SOAPFault createSOAPFault(String msg) { try { SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault fault = factory.createFault(); fault.setFaultString(msg); fault.setFaultCode(new QName(SOAP_NS, SOAP_FAULT_CODE)); Detail detail = fault.addDetail(); final Element detailEntry = detail.getOwnerDocument().createElementNS(SERVICE_NS, STUDY_IMPORT_FAULT); detail.appendChild(detailEntry); final Element detailMsg = detail.getOwnerDocument().createElementNS(SERVICE_NS, FAULT_MESSAGE); detailMsg.setTextContent(msg); detailEntry.appendChild(detailMsg); return fault; } catch (SOAPException e) { log.error(ExceptionUtils.getFullStackTrace(e)); throw new WebServiceException(e); } }
From source file:it.cnr.icar.eric.server.interfaces.soap.RegistryBSTServlet.java
private SOAPMessage createFaultSOAPMessage(java.lang.Throwable e, SOAPHeader sh) { SOAPMessage msg = null;//from ww w . jav a 2s . c o m if (log.isDebugEnabled()) { log.debug("Creating Fault SOAP Message with Throwable:", e); } try { // Will this method be "legacy" ebRS 3.0 spec-compliant and // return a URN as the <faultcode/> value? Default expectation // is of a an older client. Overridden to instead be SOAP // 1.1-compliant and return a QName as the faultcode value when // we know (for sure) client supports new approach. boolean legacyFaultCode = true; // get SOAPHeaderElement list from the received message // TODO: if additional capabilities are needed, move code to // elsewhere if (null != sh) { Iterator<?> headers = sh.examineAllHeaderElements(); while (headers.hasNext()) { Object obj = headers.next(); // confirm expected Iterator content if (obj instanceof SOAPHeaderElement) { SOAPHeaderElement header = (SOAPHeaderElement) obj; Name headerName = header.getElementName(); // check this SOAP header for relevant capability // signature if (headerName.getLocalName().equals(BindingUtility.SOAP_CAPABILITY_HEADER_LocalName) && headerName.getURI().equals(BindingUtility.SOAP_CAPABILITY_HEADER_Namespace) && header.getValue().equals(BindingUtility.SOAP_CAPABILITY_ModernFaultCodes)) { legacyFaultCode = false; // only interested in one client capability break; } } } } msg = MessageFactory.newInstance().createMessage(); SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); SOAPFault fault = msg.getSOAPBody().addFault(); // set faultCode String exceptionName = e.getClass().getName(); // TODO: SAAJ 1.3 has introduced preferred QName interfaces Name name = env.createName(exceptionName, "ns1", BindingUtility.SOAP_FAULT_PREFIX); fault.setFaultCode(name); if (legacyFaultCode) { // we now have an element child, munge its text (hack alert) Node faultCode = fault.getElementsByTagName("faultcode").item(0); // Using Utility.setTextContent() implementation since Java // WSDP 1.5 (containing an earlier DOM API) does not // support Node.setTextContent(). Utility.setTextContent(faultCode, BindingUtility.SOAP_FAULT_PREFIX + ":" + exceptionName); } // set faultString String errorMsg = e.getMessage(); if (errorMsg == null) { errorMsg = "NULL"; } fault.setFaultString(errorMsg); // create faultDetail with one entry Detail det = fault.addDetail(); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); String str = sw.toString(); name = env.createName("StackTrace", "rs", "urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0"); DetailEntry de = det.addDetailEntry(name); de.setValue(str); // de.addTextNode(str); // TODO: Need to put baseURL for this registry here msg.saveChanges(); } catch (SOAPException ex) { log.warn(ex, ex); // otherwise ignore the problem updating part of the message } return msg; }
From source file:it.cnr.icar.eric.server.interfaces.soap.RegistrySAMLServlet.java
/** * This method is a copy of the respective method from RegistrySOAPServlet. * The SAML-based Servlet returns X.509 certificate base SOAP messages. * //from ww w . j a va 2 s. com */ private SOAPMessage createFaultSOAPMessage(java.lang.Throwable e, SOAPHeader sh) { SOAPMessage msg = null; if (log.isDebugEnabled()) { log.debug("Creating Fault SOAP Message with Throwable:", e); } try { // Will this method be "legacy" ebRS 3.0 spec-compliant and // return a URN as the <faultcode/> value? Default expectation // is of a an older client. Overridden to instead be SOAP // 1.1-compliant and return a QName as the faultcode value when // we know (for sure) client supports new approach. boolean legacyFaultCode = true; // get SOAPHeaderElement list from the received message // TODO: if additional capabilities are needed, move code to // elsewhere if (null != sh) { Iterator<?> headers = sh.examineAllHeaderElements(); while (headers.hasNext()) { Object obj = headers.next(); // confirm expected Iterator content if (obj instanceof SOAPHeaderElement) { SOAPHeaderElement header = (SOAPHeaderElement) obj; Name headerName = header.getElementName(); // check this SOAP header for relevant capability // signature if (headerName.getLocalName().equals(BindingUtility.SOAP_CAPABILITY_HEADER_LocalName) && headerName.getURI().equals(BindingUtility.SOAP_CAPABILITY_HEADER_Namespace) && header.getValue().equals(BindingUtility.SOAP_CAPABILITY_ModernFaultCodes)) { legacyFaultCode = false; // only interested in one client capability break; } } } } msg = MessageFactory.newInstance().createMessage(); SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); SOAPFault fault = msg.getSOAPBody().addFault(); // set faultCode String exceptionName = e.getClass().getName(); // TODO: SAAJ 1.3 has introduced preferred QName interfaces Name name = env.createName(exceptionName, "ns1", BindingUtility.SOAP_FAULT_PREFIX); fault.setFaultCode(name); if (legacyFaultCode) { // we now have an element child, munge its text (hack alert) Node faultCode = fault.getElementsByTagName("faultcode").item(0); // Using Utility.setTextContent() implementation since Java // WSDP 1.5 (containing an earlier DOM API) does not // support Node.setTextContent(). Utility.setTextContent(faultCode, BindingUtility.SOAP_FAULT_PREFIX + ":" + exceptionName); } // set faultString String errorMsg = e.getMessage(); if (errorMsg == null) { errorMsg = "NULL"; } fault.setFaultString(errorMsg); // create faultDetail with one entry Detail det = fault.addDetail(); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); String str = sw.toString(); name = env.createName("StackTrace", "rs", "urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0"); DetailEntry de = det.addDetailEntry(name); de.setValue(str); // de.addTextNode(str); // TODO: Need to put baseURL for this registry here msg.saveChanges(); } catch (SOAPException ex) { log.warn(ex, ex); // otherwise ignore the problem updating part of the message } return msg; }
From source file:de.unibi.techfak.bibiserv.BiBiTools.java
/** * Returns a SOAPFaultException with specified * * @param faultcode// w ww. ja va2 s . c o m * @param faultstring * @param hobitstatuscode * @param hobitstatusdescription * @return */ public static SOAPFaultException createSOAPFaultException(String faultcode, String faultstring, String hobitstatuscode, String hobitstatusdescription) { SOAPFault fault = null; try { SOAPFactory sfi = SOAPFactory.newInstance(); fault = sfi.createFault(); fault.setFaultCode(new QName("http://schemas.xmlsoap.org/soap/envelope/", faultcode, "soap")); fault.setFaultString(faultstring); if (hobitstatuscode != null && hobitstatusdescription != null) { Detail detail = fault.addDetail(); DetailEntry detailentry = detail.addDetailEntry(new QName( "http://hobit.sourceforge.net/xsds/hobitStatuscode.xsd", "hobitStatuscode", "status")); SOAPElement statuscode = detailentry.addChildElement( new QName("http://hobit.sourceforge.net/xsds/hobitStatuscode.xsd", "statuscode", "status")); statuscode.addTextNode(hobitstatuscode); SOAPElement description = detailentry.addChildElement(new QName( "http://hobit.sourceforge.net/xsds/hobitStatuscode.xsd", "description", "status")); description.addTextNode(hobitstatusdescription); } } catch (SOAPException e) { log.fatal("SOAPException occured : " + e.getMessage()); } return new SOAPFaultException(fault); }
From source file:org.apache.cxf.ws.security.sts.provider.SecurityTokenServiceProvider.java
public Source invoke(Source request) { Source response = null;/*from w w w . j a v a2 s. co m*/ try { RequestSecurityTokenType rst = convertToJAXBObject(request); Object operationImpl = null; List<?> objectList = rst.getAny(); for (int i = 0; i < objectList.size(); i++) { Object obj = objectList.get(i); if (obj instanceof JAXBElement) { QName qname = ((JAXBElement<?>) obj).getName(); if (qname.equals(new QName(WSTRUST_13_NAMESPACE, WSTRUST_REQUESTTYPE_ELEMENTNAME))) { operationImpl = operationMap.get(((JAXBElement<?>) obj).getValue().toString()); break; } } } if (operationImpl == null) { throw new Exception("Implementation for this operation not found."); } Method[] methods = operationImpl.getClass().getMethods(); for (int x = 0; x < methods.length; x++) { Class<?>[] paramClass = methods[x].getParameterTypes(); if (paramClass.length == 1 && paramClass[0].equals(rst.getClass())) { RequestSecurityTokenResponseCollectionType tokenResponse = (RequestSecurityTokenResponseCollectionType) methods[x] .invoke(operationImpl, rst); if (tokenResponse == null) { throw new Exception("Error in implementation class."); } response = new JAXBSource(jaxbContext, new ObjectFactory().createRequestSecurityTokenResponseCollection(tokenResponse)); return response; } } } catch (Exception e) { LOG.error(e); try { SOAPFault fault = soapFactory.createFault(); if (e.getMessage() == null) { fault.setFaultString(e.getCause().getMessage()); } else { fault.setFaultString(e.getMessage()); } Detail detail = fault.addDetail(); detail = fault.getDetail(); QName qName = new QName(WSTRUST_13_NAMESPACE, "Fault", "ns"); DetailEntry de = detail.addDetailEntry(qName); qName = new QName(WSTRUST_13_NAMESPACE, "ErrorCode", "ns"); SOAPElement errorElement = de.addChildElement(qName); StackTraceElement[] ste = e.getStackTrace(); errorElement.setTextContent(ste[0].toString()); throw new SOAPFaultException(fault); } catch (SOAPException e1) { LOG.error(e1); } } return response; }