use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class DispatchImpl method mapException.
private RuntimeException mapException(Exception ex) {
if (ex instanceof Fault && ex.getCause() instanceof IOException) {
throw new WebServiceException(ex.getMessage(), ex.getCause());
}
if (getBinding() instanceof HTTPBinding) {
HTTPException exception = new HTTPException(HttpURLConnection.HTTP_INTERNAL_ERROR);
exception.initCause(ex);
return exception;
} else if (getBinding() instanceof SOAPBinding) {
SOAPFault soapFault = null;
try {
soapFault = JaxWsClientProxy.createSoapFault((SOAPBinding) getBinding(), ex);
} catch (SOAPException e) {
// ignore
}
if (soapFault == null) {
return new WebServiceException(ex);
}
SOAPFaultException exception = new SOAPFaultException(soapFault);
exception.initCause(ex);
return exception;
}
return new WebServiceException(ex);
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class JaxWsClientProxy method invoke.
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (client == null) {
throw new IllegalStateException("The client has been closed.");
}
Endpoint endpoint = getClient().getEndpoint();
String address = endpoint.getEndpointInfo().getAddress();
MethodDispatcher dispatcher = (MethodDispatcher) endpoint.getService().get(MethodDispatcher.class.getName());
Object[] params = args;
if (null == params) {
params = new Object[0];
}
try {
if (method.getDeclaringClass().equals(BindingProvider.class) || method.getDeclaringClass().equals(Object.class) || method.getDeclaringClass().equals(Closeable.class) || method.getDeclaringClass().equals(AutoCloseable.class)) {
return method.invoke(this, params);
} else if (method.getDeclaringClass().isInstance(client)) {
return method.invoke(client, params);
}
} catch (InvocationTargetException e) {
throw e.getCause();
}
BindingOperationInfo oi = dispatcher.getBindingOperation(method, endpoint);
if (oi == null) {
Message msg = new Message("NO_BINDING_OPERATION_INFO", LOG, method.getName());
throw new WebServiceException(msg.toString());
}
client.getRequestContext().put(Method.class.getName(), method);
boolean isAsync = isAsync(method);
Object result = null;
try {
if (isAsync) {
result = invokeAsync(method, oi, params);
} else {
result = invokeSync(method, oi, params);
}
} catch (WebServiceException wex) {
throw wex;
} catch (Exception ex) {
for (Class<?> excls : method.getExceptionTypes()) {
if (excls.isInstance(ex)) {
throw ex;
}
}
if (ex instanceof Fault && ex.getCause() instanceof IOException) {
throw new WebServiceException(ex.getMessage(), ex.getCause());
}
if (getBinding() instanceof HTTPBinding) {
HTTPException exception = new HTTPException(HttpURLConnection.HTTP_INTERNAL_ERROR);
exception.initCause(ex);
throw exception;
} else if (getBinding() instanceof SOAPBinding) {
SOAPFault soapFault = createSoapFault((SOAPBinding) getBinding(), ex);
if (soapFault == null) {
throw new WebServiceException(ex);
}
SOAPFaultException exception = new SOAPFaultException(soapFault);
if (ex instanceof Fault && ex.getCause() != null) {
exception.initCause(ex.getCause());
} else {
exception.initCause(ex);
}
throw exception;
} else {
throw new WebServiceException(ex);
}
} finally {
if (addressChanged(address)) {
setupEndpointAddressContext(getClient().getEndpoint());
}
}
Map<String, Object> respContext = client.getResponseContext();
Map<String, Scope> scopes = CastUtils.cast((Map<?, ?>) respContext.get(WrappedMessageContext.SCOPES));
if (scopes != null) {
for (Map.Entry<String, Scope> scope : scopes.entrySet()) {
if (scope.getValue() == Scope.HANDLER) {
respContext.remove(scope.getKey());
}
}
}
return adjustObject(result);
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class HandlerChainInvoker method setFaultMessage.
/*
* When the message direction is reversed, if the message is not already a
* fault message then it is replaced with a fault message
*/
private void setFaultMessage(MessageContext mc, Exception exception) {
Message msg = ((WrappedMessageContext) mc).getWrappedMessage();
msg.setContent(Exception.class, exception);
msg.removeContent(XMLStreamReader.class);
msg.removeContent(Source.class);
try {
SOAPMessage soapMessage = null;
SoapVersion version = null;
if (msg instanceof SoapMessage) {
version = ((SoapMessage) msg).getVersion();
}
soapMessage = SAAJFactoryResolver.createMessageFactory(version).createMessage();
msg.setContent(SOAPMessage.class, soapMessage);
SOAPBody body = SAAJUtils.getBody(soapMessage);
SOAPFault soapFault = body.addFault();
if (exception instanceof SOAPFaultException) {
SOAPFaultException sf = (SOAPFaultException) exception;
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();
soapFault.addDetail();
while (nd != null) {
soapFault.getDetail().appendChild(nd);
nd = nd.getNextSibling();
}
}
} else if (exception instanceof Fault) {
SoapFault sf = SoapFault.createFault((Fault) exception, ((SoapMessage) msg).getVersion());
soapFault.setFaultString(sf.getReason());
SAAJUtils.setFaultCode(soapFault, sf.getFaultCode());
if (sf.hasDetails()) {
soapFault.addDetail();
Node nd = soapMessage.getSOAPPart().importNode(sf.getDetail(), true);
nd = nd.getFirstChild();
while (nd != null) {
soapFault.getDetail().appendChild(nd);
nd = nd.getNextSibling();
}
}
} else {
SAAJUtils.setFaultCode(soapFault, new QName("http://cxf.apache.org/faultcode", "HandlerFault"));
soapFault.setFaultString(exception.getMessage());
}
} catch (SOAPException e) {
e.printStackTrace();
// do nothing
}
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class SecurityTokenServiceImpl method throwUnsupportedOperation.
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);
}
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class SubscriptionGrantingTest method cannotProcessFilter.
@Test
public void cannotProcessFilter() throws IOException {
Subscribe subscribe = new Subscribe();
ExpirationType exp = new ExpirationType();
DeliveryType delivery = new DeliveryType();
XMLGregorianCalendar dateRequest = (XMLGregorianCalendar) DurationAndDateUtil.parseDurationOrTimestamp("2138-06-26T12:23:12.000-01:00");
exp.setValue(DurationAndDateUtil.convertToXMLString(dateRequest));
exp.setBestEffort(true);
subscribe.setExpires(exp);
subscribe.setDelivery(delivery);
subscribe.getDelivery().getContent().add(createDummyNotifyTo());
subscribe.setFilter(new FilterType());
subscribe.getFilter().getContent().add("@^5this-is-not-a-valid-xpath-expression!!!*-/");
try {
eventSourceClient.subscribeOp(subscribe);
} catch (SOAPFaultException ex) {
Assert.assertTrue(ex.getFault().getFaultCode().contains(CannotProcessFilter.LOCAL_PART));
Assert.assertTrue(ex.getFault().getTextContent().contains(CannotProcessFilter.REASON));
return;
}
Assert.fail("Event source should have sent a CannotProcessFilter fault");
}
Aggregations