private SoapFault mapSoapFault(SOAPFaultException sfe) { SoapFault sf = new SoapFault(sfe.getFault().getFaultString(), sfe, sfe.getFault().getFaultCodeAsQName()); sf.setRole(sfe.getFault().getFaultActor()); if (sfe.getFault().hasDetail()) { sf.setDetail(sfe.getFault().getDetail()); } return sf; }
/** * Constructor for JaxWsSoapFaultException. * @param original the original JAX-WS SOAPFaultException to wrap */ public JaxWsSoapFaultException(SOAPFaultException original) { super(original.getMessage(), original); }
@org.junit.Test public void testPlaintext() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = EmptySOAPBodyTest.class.getResource("client.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); URL wsdl = EmptySOAPBodyTest.class.getResource("DoubleIt.wsdl"); Service service = Service.create(wsdl, SERVICE_QNAME); QName portQName = new QName(NAMESPACE, "DoubleItPlaintextPort"); DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class); updateAddressPort(port, PORT); try { port.doubleIt(25); fail("Should have thown an exception"); } catch (SOAPFaultException t) { assertTrue("Wrong exception cause " + t.getCause(), t.getCause() instanceof IllegalEmptyResponseException); } ((java.io.Closeable)port).close(); bus.shutdown(true); }
@Test public void testFault() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = SecurityPolicyTest.class.getResource("https_config_client.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); URL wsdl = SecurityPolicyTest.class.getResource("DoubleIt.wsdl"); Service service = Service.create(wsdl, SERVICE_QNAME); QName portQName = new QName(NAMESPACE, "DoubleItFaultPortSignThenEncrypt"); DoubleItPortType pt = service.getPort(portQName, DoubleItPortType.class); updateAddressPort(pt, PORT); ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, new KeystorePasswordCallback()); ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES, "alice.properties"); ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES, "bob.properties"); // DOM try { pt.doubleIt(5); fail("SOAPFaultException expected!"); } catch (SOAPFaultException e) { assertEquals("Foo", e.getFault().getFaultString()); } finally { ((java.io.Closeable)pt).close(); bus.shutdown(true); } }
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); }
soapFault.setFaultString(sf.getFault().getFaultString()); SAAJUtils.setFaultCode(soapFault, sf.getFault().getFaultCodeAsQName()); soapFault.setFaultActor(sf.getFault().getFaultActor()); if (sf.getFault().hasDetail()) { Node nd = soapMessage.getSOAPPart().importNode(sf.getFault().getDetail(), true); nd = nd.getFirstChild(); new QName("http://cxf.apache.org/faultcode", "HandlerFault")); soapFault.setFaultString(exception.getMessage());
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); }
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); }
public static SoapFault11 create(SOAPFaultException sfe) { try { SOAPFault cause = sfe.getFault(); QName faultCode = cause.getFaultCodeAsQName(); String reason = cause.getFaultString(); SoapFaultType soapFaultType = SoapFaultType.toState(reason); Detail detail = cause.getDetail(); return new SoapFault11(soapFaultType, faultCode, null, detail); } catch (InvalidEnumerationException e) { return new SoapFault11(e); } } /**
private void throwUnsupportedOperation(String string) { try { SOAPFault fault = SAAJFactoryResolver.createSOAPFactory(null).createFault(); fault.setFaultString("Unsupported operation " + string); throw new SOAPFaultException(fault); } catch (SOAPException e) { throw new Fault(e); } }
public SOAPFaultException getSOAPFaultException( WssSoapFaultException sfe, boolean isSOAP12) { SOAPFault fault = null; try { if (isSOAP12) { fault = soapFactory.createFault(sfe.getFaultString(),SOAPConstants.SOAP_SENDER_FAULT); fault.appendFaultSubcode(sfe.getFaultCode()); } else { fault = soapFactory.createFault(sfe.getFaultString(), sfe.getFaultCode()); } } catch (Exception e) { throw new RuntimeException(this + ": Internal Error while trying to create a SOAPFault"); } return new SOAPFaultException(fault); }
} catch (SOAPFaultException sfe) { lastError = "SOAP Fault prevented connect (EtradealSettings). " + sfe.getFault().getFaultString() + " (Fault code : " + sfe.getFault().getFaultCode() + ")."; logger.error(lastError); logger.error(GTMSLog.exceptionToString(sfe)); isConnected = false; sfe.printStackTrace(); } catch (WebServiceException wse) {
private void setFault(Message msg, SOAPFaultException e) { SOAPFault fault = e.getFault(); Detail detail = fault.getDetail(); if (detail != null) { for (Iterator i = detail.getDetailEntries(); i.hasNext();) { DetailEntry entry = (DetailEntry)i.next(); FaultException fe = new FaultException(e.getMessage(), entry, e); fe.setFaultName(entry.getElementQName()); msg.setFaultBody(fe); } } else { msg.setFaultBody(e); } }
try { //... invoke service via client } catch (javax.xml.ws.soap.SOAPFaultException soapFaultException) { javax.xml.soap.SOAPFault fault = soapFaultException.getFault(); //<Fault> node javax.xml.soap.Detail detail = fault.getDetail(); // <detail> node Iterator detailEntries = detail.getDetailEntries(); //nodes under <detail> //application / service-provider-specific XML nodes (type javax.xml.soap.DetailEntry) from here }
private void checkError() { if (error != null) { if (getBinding() instanceof SOAPBinding) { SOAPFault soapFault = null; try { soapFault = JaxWsClientProxy.createSoapFault((SOAPBinding)getBinding(), new Exception(error.toString())); } catch (SOAPException e) { //ignore } if (soapFault != null) { throw new SOAPFaultException(soapFault); } } else if (getBinding() instanceof HTTPBinding) { HTTPException exception = new HTTPException(HttpURLConnection.HTTP_INTERNAL_ERROR); exception.initCause(new Exception(error.toString())); throw exception; } throw new WebServiceException(error.toString()); } } private RuntimeException mapException(Exception ex) {
/** * Return the wrapped JAX-WS SOAPFault. */ public final SOAPFault getFault() { return ((SOAPFaultException) getCause()).getFault(); }
if (soapVersion != null && soapVersion.getVersion() != 1.1) { if (f instanceof SoapFault) { for (Iterator<QName> it = CastUtils.cast(sf.getFault().getFaultSubcodes()); it.hasNext();) { ((SoapFault) f).addSubCode(it.next()); if (sf.getFault().getFaultReasonLocales().hasNext()) { Locale lang = (Locale) sf.getFault() .getFaultReasonLocales().next(); String convertedLang = lang.getLanguage(); String country = lang.getCountry();
public static DispositionReportFaultMessage MapException(SOAPFaultException ex) { org.uddi.api_v3.DispositionReport r = new org.uddi.api_v3.DispositionReport(); r.setTruncated(false); r.getResult().addAll(MapFault(ex.getFault())); DispositionReportFaultMessage x = new DispositionReportFaultMessage(ex.getMessage(), r); return x; }
@Test public void testNewLineInExceptionMessage() throws Exception { Greeter greeter = getGreeter(); try { greeter.greetMe("newline"); fail("Should throw Exception!"); } catch (SOAPFaultException ex) { assertEquals("greetMeFault Caused by: Get a wrong name <greetMe>", ex.getMessage()); StackTraceElement[] elements = ex.getCause().getStackTrace(); assertEquals("org.apache.cxf.systest.soapfault.details.GreeterImpl11", elements[0].getClassName()); assertTrue(ex.getCause().getCause().getMessage().endsWith("Test \n cause.")); } }
@Test public void testAnonToNonAnon() throws Exception { try (AddNumbersPortTypeProxy port = getPort()) { port.getRequestContext() .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT + "/jaxws/addNonAnon"); try { port.addNumbers3(-1, 2); } catch (SOAPFaultException e) { assertTrue(e.getFault().getFaultCode().contains("OnlyNonAnonymousAddressSupported")); } } } @Test