use of javax.xml.ws.soap.SOAPFaultException in project camel by apache.
the class Soap11DataFormatAdapter method createExceptionFromFault.
/**
* Creates an exception and eventually an embedded bean that contains the
* fault detail. The exception class is determined by using the
* elementNameStrategy. The qName of the fault detail should match the
* WebFault annotation of the Exception class. If no fault detail is set a
* SOAPFaultException is created.
*
* @param fault Soap fault
* @return created Exception
*/
private Exception createExceptionFromFault(Fault fault) {
String message = fault.getFaultstring();
Detail faultDetail = fault.getDetail();
if (faultDetail == null || faultDetail.getAny().size() == 0) {
try {
return new SOAPFaultException(SOAPFactory.newInstance().createFault(message, fault.getFaultcode()));
} catch (SOAPException e) {
throw new RuntimeCamelException(e);
}
}
JAXBElement<?> detailEl = (JAXBElement<?>) faultDetail.getAny().get(0);
Class<? extends Exception> exceptionClass = getDataFormat().getElementNameStrategy().findExceptionForFaultName(detailEl.getName());
Constructor<? extends Exception> messageConstructor;
Constructor<? extends Exception> constructor;
try {
messageConstructor = exceptionClass.getConstructor(String.class);
Object detail = JAXBIntrospector.getValue(detailEl);
try {
constructor = exceptionClass.getConstructor(String.class, detail.getClass());
return constructor.newInstance(message, detail);
} catch (NoSuchMethodException e) {
return messageConstructor.newInstance(message);
}
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
}
use of javax.xml.ws.soap.SOAPFaultException in project camel by apache.
the class Soap12DataFormatAdapter method createExceptionFromFault.
/**
* Creates an exception and eventually an embedded bean that contains the
* fault detail. The exception class is determined by using the
* elementNameStrategy. The qName of the fault detail should match the
* WebFault annotation of the Exception class. If no fault detail is set
* a {@link javax.xml.ws.soap.SOAPFaultException} is created.
*
* @param fault Soap fault
* @return created Exception
*/
private Exception createExceptionFromFault(Fault fault) {
StringBuilder sb = new StringBuilder();
for (Reasontext text : fault.getReason().getText()) {
sb.append(text.getValue());
}
String message = sb.toString();
Detail faultDetail = fault.getDetail();
if (faultDetail == null || faultDetail.getAny().size() == 0) {
try {
return new SOAPFaultException(SOAPFactory.newInstance().createFault(message, fault.getCode().getValue()));
} catch (SOAPException e) {
throw new RuntimeCamelException(e);
}
}
JAXBElement<?> detailEl = (JAXBElement<?>) faultDetail.getAny().get(0);
Class<? extends Exception> exceptionClass = getDataFormat().getElementNameStrategy().findExceptionForFaultName(detailEl.getName());
Constructor<? extends Exception> messageConstructor;
Constructor<? extends Exception> constructor;
try {
messageConstructor = exceptionClass.getConstructor(String.class);
Object detail = JAXBIntrospector.getValue(detailEl);
try {
constructor = exceptionClass.getConstructor(String.class, detail.getClass());
return constructor.newInstance(message, detail);
} catch (NoSuchMethodException e) {
return messageConstructor.newInstance(message);
}
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
}
use of javax.xml.ws.soap.SOAPFaultException in project camel by apache.
the class CxfConsumerPayloadFaultCauseEnabledTest method testInvokingFromCxfClient.
@Test
public void testInvokingFromCxfClient() throws Exception {
this.getCamelContextService();
URL wsdlURL = getClass().getClassLoader().getResource("person.wsdl");
PersonService ss = new PersonService(wsdlURL, SERVICE_QNAME);
Person client = ss.getSoap();
Client c = ClientProxy.getClient(client);
c.getInInterceptors().add(new LoggingInInterceptor());
c.getOutInterceptors().add(new LoggingOutInterceptor());
((BindingProvider) client).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceAddress);
Holder<String> personId = new Holder<String>();
personId.value = "";
Holder<String> ssn = new Holder<String>();
Holder<String> name = new Holder<String>();
try {
client.getPerson(personId, ssn, name);
fail("SOAPFault expected!");
} catch (Exception e) {
assertTrue(e instanceof SOAPFaultException);
SOAPFault fault = ((SOAPFaultException) e).getFault();
assertEquals("Someone messed up the service. Caused by: Homer", fault.getFaultString());
}
}
use of javax.xml.ws.soap.SOAPFaultException in project midpoint by Evolveum.
the class TestWSSecurity method test123GetConfigAsNobodyGoodPasswordDigest.
@Test
public void test123GetConfigAsNobodyGoodPasswordDigest() throws Exception {
final String TEST_NAME = "test123GetConfigAsNobodyGoodPasswordDigest";
displayTestTitle(TEST_NAME);
LogfileTestTailer tailer = createLogTailer();
modelPort = createModelPort(USER_NOBODY_USERNAME, USER_NOBODY_PASSWORD, WSConstants.PW_DIGEST);
Holder<ObjectType> objectHolder = new Holder<ObjectType>();
Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
// WHEN
try {
modelPort.getObject(getTypeQName(SystemConfigurationType.class), SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, objectHolder, resultHolder);
AssertJUnit.fail("Unexpected success");
} catch (SOAPFaultException e) {
assertSoapSecurityFault(e, "FailedAuthentication", "could not be authenticated or authorized");
}
tailer.tail();
assertAuditLoginFailed(tailer, "no authorizations");
}
use of javax.xml.ws.soap.SOAPFaultException in project midpoint by Evolveum.
the class TestWSSecurity method test105GetConfigWrongUsernameDigest.
@Test
public void test105GetConfigWrongUsernameDigest() throws Exception {
final String TEST_NAME = "test105GetConfigWrongUsernameDigest";
displayTestTitle(TEST_NAME);
LogfileTestTailer tailer = createLogTailer();
modelPort = createModelPort("admin", USER_ADMINISTRATOR_PASSWORD, WSConstants.PW_DIGEST);
Holder<ObjectType> objectHolder = new Holder<ObjectType>();
Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
// WHEN
try {
modelPort.getObject(getTypeQName(SystemConfigurationType.class), SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, objectHolder, resultHolder);
AssertJUnit.fail("Unexpected success");
} catch (SOAPFaultException e) {
assertSoapSecurityFault(e, "FailedAuthentication", "could not be authenticated or authorized");
}
tailer.tail();
assertAuditLoginFailed(tailer, "no user");
}
Aggregations