public static SOAPFactory newInstance() throws SOAPException { try { SOAPFactory factory = $FactoryFinder.find(SOAPFactory.class, DEFAULT_SOAP_FACTORY, false); if (factory != null) { return factory; } return newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); } catch (Exception ex) { throw new SOAPException("Unable to create SOAP Factory: " + ex.getMessage(), ex); } }
String token = "authentication token given from service"; SOAPFactory sf = SOAPFactory.newInstance(); SOAPElement authElement = sf.createElement(new QName("urn:example.com", "Authentication")); SOAPElement tokenElement = sf.createElement(new QName(null, "AuthenticationToken")); tokenElement.addTextNode(token); authElement.addChildElement(tokenElement); List<Header> headers = new ArrayList<Header>(); Header dummyHeader = new Header(new QName("urn:example.com"), authElement); headers.add(dummyHeader);
public static SOAPFaultException createSOAPFaultEx(SOAPFactory soapFactory, QName faultCode, String message) { SOAPFault sf = null; try { sf = soapFactory.createFault(); sf.setFaultCode(faultCode); sf.setFaultString(message); } catch (SOAPException se) { se.printStackTrace(); } return new SOAPFaultException(sf); }
private SOAPFaultException createSOAPFaultException(String faultString) { SOAPFault soapFault; try { SOAPFactory soapFactory = SOAPFactory.newInstance(); soapFault = soapFactory.createFault(); soapFault.setFaultString(faultString); } catch (SOAPException e) { throw new RuntimeException("SOAP error"); } return new SOAPFaultException(soapFault); }
private SOAPHeaderElement createSoapHeaderElement() throws SOAPException { Name name = SOAPFactory.newInstance().createName( Constants.SOAP_HEADER_NAME_RECORD, Constants.SOAP_HEADER_PREFIX, Constants.SOAP_HEADER_NS); return new org.apache.axis.message.SOAPHeaderElement(name); }
private SOAPFault createSoapFault(final String msg, final QName qname) { try { SOAPFactory soapFactory = SOAPFactory.newInstance(); return soapFactory.createFault(msg, qname); } catch (SOAPException e) { throw new WebServiceException("Exception while trying to create SOAPFault", e); } }
SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_RECEIVER.getValue(), ArjunaTXConstants.FAULTED_ERROR_CODE_QNAME); 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_1()); 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_2()); 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_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_TerminationCoordinatorProcessorImpl_5()); 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();
@Override public DOMSource invoke(DOMSource request) { try { return invokeAllowingFaults(request); } catch (FaultMessage faultMessage) { try { SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault soapFault = factory.createFault(); soapFault.setFaultCode(SOAP11_FAULTCODE_SERVER); // todo here is a constant until we have a mechanism to determine the correct value (client / server) soapFault.setFaultString(faultMessage.getMessage()); Detail detail = soapFault.addDetail(); serializeFaultMessage(detail, faultMessage); // fault actor? // stack trace of the outer exception (FaultMessage) is unimportant, because it is always created at one place // todo consider providing stack trace of the inner exception //Detail detail = soapFault.addDetail(); //detail.setTextContent(getStackTraceAsString(faultMessage)); throw new SOAPFaultException(soapFault); } catch (SOAPException e) { throw new RuntimeException("SOAP Exception: " + e.getMessage(), e); } } }
try { if (sv == SOAPVersion.SOAP_12) { fault = SOAPVersion.SOAP_12.getSOAPFactory().createFault(); fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT); fault.appendFaultSubcode(subcode); Detail detail = fault.addDetail(); SOAPElement se = detail.addChildElement(av.problemActionTag); se = se.addChildElement(av.actionTag); se.addTextNode(unsupportedAction); } else { fault = SOAPVersion.SOAP_11.getSOAPFactory().createFault(); fault.setFaultCode(subcode);
public GreetMeResponse greetMe(GreetMeRequest gmr) { if ("fault".equals(gmr.getName())) { try { SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault fault = factory.createFault("this is a fault string!", new QName("http://foo", "FooCode")); fault.setFaultActor("mr.actor"); fault.addDetail().addChildElement("test").addTextNode("TestText"); throw new SOAPFaultException(fault); } catch (SOAPException ex) { throw new WebServiceException(ex); } } else if ("emptyfault".equals(gmr.getName())) { throw new RuntimeException("Empty!"); } GreetMeResponse resp = new GreetMeResponse(); resp.setName(gmr.getName()); return resp; }
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); }
static SOAPFault createSoapFault(SOAPBinding binding, Exception ex) throws SOAPException { SOAPFault soapFault; try { soapFault = binding.getSOAPFactory().createFault(); } catch (Throwable t) { if (!soapFault.getNamespaceURI().equals(((SoapFault)ex).getFaultCode().getNamespaceURI()) && SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE .equals(((SoapFault)ex).getFaultCode().getNamespaceURI())) { soapFault = SAAJFactoryResolver.createSOAPFactory(null).createFault(); } catch (Throwable t) { final boolean isSoap11 = SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(soapFault.getNamespaceURI()); soapFault.setFaultString(((SoapFault)ex).getReason()); } else { soapFault.setFaultString(((SoapFault)ex).getReason(), stringToLocale(((SoapFault)ex).getLang())); while (nd != null) { Node next = nd.getNextSibling(); soapFault.getDetail().appendChild(nd); nd = next;
protected Throwable getProtocolException() { try { SOAPFault fault = SOAPVersion.SOAP_12.getSOAPFactory().createFault();; if(reason != null){ for(TextType tt : reason.texts()){ fault.setFaultString(tt.getText()); } } if(code != null){ fault.setFaultCode(code.getValue()); fillFaultSubCodes(fault, code.getSubcode()); } if(detail != null && detail.getDetail(0) != null){ javax.xml.soap.Detail detail = fault.addDetail(); for(Node obj: this.detail.getDetails()){ Node n = fault.getOwnerDocument().importNode(obj, true); detail.appendChild(n); } } if(node != null) { fault.setFaultNode(node); } return new ServerSOAPFaultException(fault); } catch (SOAPException e) { throw new WebServiceException(e); } }
@Override protected void runTest() throws Throwable { SOAPElement root = newSOAPFactory().createElement("root", "p", "urn:test"); SOAPElement element = root.addChildElement("child"); assertThat(element.getLocalName()).isEqualTo("child"); assertThat(element.getNamespaceURI()).isNull(); assertThat(element.getPrefix()).isNull(); assertThat(element.getParentNode()).isSameAs(root); assertThat(element.getAttributes().getLength()).isEqualTo(0); } }
private static void addHeader(String ticketId) { try { SOAPFactory sf = SOAPFactory.newInstance(); SOAPElement userIdHeaderElement = sf.createElement(new QName("http://www.stats.com/", "UserIdHeader")); SOAPElement ticketIdElement = sf.createElement(new QName(null, "TicketId")); ticketIdElement.addTextNode(ticketId); userIdHeaderElement.addChildElement(ticketIdElement); List<Header> headers = new ArrayList<Header>(); Header dummyHeader = new Header(new QName("http://www.stats.com/"), userIdHeaderElement); headers.add(dummyHeader); BindingProvider.class.cast(service).getRequestContext().put(Header.HEADER_LIST, headers); } catch (SOAPException e) { e.printStackTrace(); } }
@Nullable protected static SOAPFaultException createSfe(@NotNull SoapFaultCode soapFaultCode) { try { QName qname = new QName("http://schemas.xmlsoap.org/soap/envelope/", soapFaultCode.name()); SOAPFactory sf = SOAPFactory.newInstance(); SOAPFault fault = sf.createFault("", qname); return new SOAPFaultException(fault); } catch (SOAPException e) { //e.printStackTrace(); return null; } }
public void appendToSOAPHeader(FederatedCatalogInfo[] fedCatInfos, SOAPHeader header) throws SAXException { try { Name name = SOAPFactory.newInstance().createName( Constants.SOAP_HEADER_NAME_FEDCATINFO, Constants.SOAP_HEADER_PREFIX, Constants.SOAP_HEADER_NS); SOAPHeaderElement headerElement = header.addHeaderElement(name); appendToSOAPHeaderElement(fedCatInfos, headerElement); } catch (SOAPException e) { LOG.error(e.getMessage(), e); throw new SAXException("Error transforming to SOAP header", e); } }
protected Throwable getProtocolException() { try { SOAPFault fault = SOAPVersion.SOAP_11.getSOAPFactory().createFault(faultstring, faultcode); fault.setFaultActor(faultactor); if(detail != null){ Detail d = fault.addDetail(); for(Element det : detail.getDetails()){ Node n = fault.getOwnerDocument().importNode(det, true); d.appendChild(n); } } return new ServerSOAPFaultException(fault); } catch (SOAPException e) { throw new WebServiceException(e); } } }
/** * @see io.apiman.gateway.engine.io.IPayloadIO#unmarshall(java.io.InputStream) */ @Override public SOAPEnvelope unmarshall(InputStream input) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(false); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(input); SOAPElement soapElement = SOAPFactory.newInstance().createElement(doc.getDocumentElement()); SOAPEnvelope envelope = (SOAPEnvelope) soapElement; return envelope; }