use of org.apache.hello_world_soap_http.BadRecordLitFault in project cxf by apache.
the class ClientServerTest method testFaults.
@Test
public void testFaults() throws Exception {
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
SOAPService service = new SOAPService(wsdl, serviceName);
ExecutorService ex = Executors.newFixedThreadPool(1);
service.setExecutor(ex);
assertNotNull(service);
String noSuchCodeFault = "NoSuchCodeLitFault";
String badRecordFault = "BadRecordLitFault";
String illegalArgumentException = "IllegalArgumentException";
Greeter greeter = service.getPort(portName, Greeter.class);
updateAddressPort(greeter, PORT);
for (int idx = 0; idx < 2; idx++) {
try {
greeter.testDocLitFault(noSuchCodeFault);
fail("Should have thrown NoSuchCodeLitFault exception");
} catch (NoSuchCodeLitFault nslf) {
int responseCode = (Integer) ((BindingProvider) greeter).getResponseContext().get(MessageContext.HTTP_RESPONSE_CODE);
assertEquals(responseCode, 500);
assertNotNull(nslf.getFaultInfo());
assertNotNull(nslf.getFaultInfo().getCode());
}
try {
greeter.testDocLitFault(illegalArgumentException);
fail("Should have thrown SOAPFaultException exception");
} catch (SOAPFaultException sfe) {
assertEquals("TestIllegalArgumentException", sfe.getCause().getMessage());
sfe.printStackTrace();
}
try {
greeter.testDocLitFault(badRecordFault);
fail("Should have thrown BadRecordLitFault exception");
} catch (BadRecordLitFault brlf) {
BindingProvider bp = (BindingProvider) greeter;
Map<String, Object> responseContext = bp.getResponseContext();
String contentType = (String) responseContext.get(Message.CONTENT_TYPE);
assertEquals("text/xml;charset=utf-8", stripSpaces(contentType.toLowerCase()));
Integer responseCode = (Integer) responseContext.get(Message.RESPONSE_CODE);
assertEquals(500, responseCode.intValue());
assertNotNull(brlf.getFaultInfo());
assertEquals("BadRecordLitFault", brlf.getFaultInfo());
}
try {
greeter.testDocLitFaultAsync(noSuchCodeFault).get();
fail("Should have thrown NoSuchCodeLitFault exception");
} catch (ExecutionException ee) {
NoSuchCodeLitFault nslf = (NoSuchCodeLitFault) ee.getCause();
assertNotNull(nslf.getFaultInfo());
assertNotNull(nslf.getFaultInfo().getCode());
}
try {
greeter.testDocLitFaultAsync(illegalArgumentException).get();
fail("Should have thrown SOAPFaultException exception");
} catch (ExecutionException ee) {
SOAPFaultException sfe = (SOAPFaultException) ee.getCause();
assertEquals("TestIllegalArgumentException", sfe.getCause().getMessage());
}
}
}
use of org.apache.hello_world_soap_http.BadRecordLitFault in project cxf by apache.
the class AbstractGreeterImpl method testDocLitFault.
public void testDocLitFault(String faultType) throws BadRecordLitFault, NoSuchCodeLitFault {
verifyMAPs();
if (faultType.equals(BadRecordLitFault.class.getSimpleName())) {
throw new BadRecordLitFault("TestBadRecordLit", "BadRecordLitFault");
}
if (faultType.equals(NoSuchCodeLitFault.class.getSimpleName())) {
ErrorCode ec = new ErrorCode();
ec.setMajor((short) 1);
ec.setMinor((short) 1);
NoSuchCodeLit nscl = new NoSuchCodeLit();
nscl.setCode(ec);
throw new NoSuchCodeLitFault("TestNoSuchCodeLit", nscl);
}
}
use of org.apache.hello_world_soap_http.BadRecordLitFault in project cxf by apache.
the class ClientServerWebSocketTest method testFaults.
@Test
public void testFaults() throws Exception {
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
SOAPService service = new SOAPService(wsdl, serviceName);
ExecutorService ex = Executors.newFixedThreadPool(1);
service.setExecutor(ex);
assertNotNull(service);
String noSuchCodeFault = "NoSuchCodeLitFault";
String badRecordFault = "BadRecordLitFault";
Greeter greeter = service.getPort(portName, Greeter.class);
updateGreeterAddress(greeter, PORT);
for (int idx = 0; idx < 2; idx++) {
try {
greeter.testDocLitFault(noSuchCodeFault);
fail("Should have thrown NoSuchCodeLitFault exception");
} catch (NoSuchCodeLitFault nslf) {
assertNotNull(nslf.getFaultInfo());
assertNotNull(nslf.getFaultInfo().getCode());
}
try {
greeter.testDocLitFault(badRecordFault);
fail("Should have thrown BadRecordLitFault exception");
} catch (BadRecordLitFault brlf) {
BindingProvider bp = (BindingProvider) greeter;
Map<String, Object> responseContext = bp.getResponseContext();
String contentType = (String) responseContext.get(Message.CONTENT_TYPE);
assertEquals("text/xml; charset=utf-8", contentType.toLowerCase());
Integer responseCode = (Integer) responseContext.get(Message.RESPONSE_CODE);
assertEquals(500, responseCode.intValue());
assertNotNull(brlf.getFaultInfo());
assertEquals("BadRecordLitFault", brlf.getFaultInfo());
}
}
}
use of org.apache.hello_world_soap_http.BadRecordLitFault in project camel by apache.
the class CxfProducerSoapFaultTest method invokeSoapFault.
private void invokeSoapFault(boolean sync) throws Exception {
String cxfEndpointURI = JAXWS_ENDPOINT_URI;
if (sync) {
cxfEndpointURI = cxfEndpointURI + "&synchronous=true";
}
Exchange exchange = sendJaxWsMessage(cxfEndpointURI, "BadRecordLitFault", "testDocLitFault");
Exception exception = exchange.getException();
// assert we got the exception first
assertNotNull("except to get the exception", exception);
assertTrue("Get a wrong soap fault", exception instanceof BadRecordLitFault);
// check out the message header which is copied from in message
String fileName = exchange.getOut().getHeader(Exchange.FILE_NAME, String.class);
assertEquals("Should get the file name from out message header", "testFile", fileName);
}
use of org.apache.hello_world_soap_http.BadRecordLitFault in project cxf by apache.
the class JaxWsClientTest method testEndpoint.
@Test
public void testEndpoint() throws Exception {
ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(resource);
bean.setWsdlURL(resource.toString());
bean.setBus(getBus());
bean.setServiceClass(GreeterImpl.class);
GreeterImpl greeter = new GreeterImpl();
BeanInvoker invoker = new BeanInvoker(greeter);
bean.setInvoker(invoker);
Service service = bean.create();
String namespace = "http://apache.org/hello_world_soap_http";
EndpointInfo ei = service.getServiceInfos().get(0).getEndpoint(new QName(namespace, "SoapPort"));
JaxWsEndpointImpl endpoint = new JaxWsEndpointImpl(getBus(), service, ei);
ClientImpl client = new ClientImpl(getBus(), endpoint);
BindingOperationInfo bop = ei.getBinding().getOperation(new QName(namespace, "sayHi"));
assertNotNull(bop);
bop = bop.getUnwrappedOperation();
assertNotNull(bop);
MessagePartInfo part = bop.getOutput().getMessageParts().get(0);
assertEquals(0, part.getIndex());
d.setMessageObserver(new MessageReplayObserver("sayHiResponse.xml"));
Object[] ret = client.invoke(bop, new Object[] { "hi" }, null);
assertNotNull(ret);
assertEquals("Wrong number of return objects", 1, ret.length);
// test fault handling
bop = ei.getBinding().getOperation(new QName(namespace, "testDocLitFault"));
bop = bop.getUnwrappedOperation();
d.setMessageObserver(new MessageReplayObserver("testDocLitFault.xml"));
try {
client.invoke(bop, new Object[] { "BadRecordLitFault" }, null);
fail("Should have returned a fault!");
} catch (BadRecordLitFault fault) {
assertEquals("foo", fault.getFaultInfo().trim());
assertEquals("Hadrian did it.", fault.getMessage());
}
try {
client.getEndpoint().getOutInterceptors().add(new NestedFaultThrower());
client.getEndpoint().getOutInterceptors().add(new FaultThrower());
client.invoke(bop, new Object[] { "BadRecordLitFault" }, null);
fail("Should have returned a fault!");
} catch (Fault fault) {
assertTrue(fault.getMessage().indexOf("Foo") >= 0);
}
client.close();
}
Aggregations