List of usage examples for javax.xml.soap Detail addDetailEntry
public DetailEntry addDetailEntry(QName qname) 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.//from w ww. j a va 2 s . com * * @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:it.cnr.icar.eric.server.interfaces.soap.RegistryBSTServlet.java
private SOAPMessage createFaultSOAPMessage(java.lang.Throwable e, SOAPHeader sh) { SOAPMessage msg = null;/* w ww . j a v a 2 s .c om*/ 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 w w w . java 2 s . c om*/ */ 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//ww w. j a va 2 s .c om * @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.ja va2 s .c om*/ 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; }