use of org.apache.hello_world_soap_http.NoSuchCodeLitFault in project camel by apache.
the class AbstractCXFGreeterRouterTest method testInvokingServiceFromCXFClient.
@Test
public void testInvokingServiceFromCXFClient() throws Exception {
Service service = Service.create(serviceName);
service.addPort(routerPortName, "http://schemas.xmlsoap.org/soap/", "http://localhost:" + getPort2() + "/" + getClass().getSimpleName() + "/CamelContext/RouterPort");
Greeter greeter = service.getPort(routerPortName, Greeter.class);
String reply = greeter.greetMe("test");
assertNotNull("No response received from service", reply);
assertEquals("Got the wrong reply ", "Hello test", reply);
reply = greeter.sayHi();
assertNotNull("No response received from service", reply);
assertEquals("Got the wrong reply ", "Bonjour", reply);
greeter.greetMeOneWay("call greetMe OneWay !");
// test throw the exception
try {
greeter.testDocLitFault("NoSuchCodeLitFault");
// should get the exception here
fail("Should get the NoSuchCodeLitFault here.");
} catch (NoSuchCodeLitFault fault) {
// expect the fault here
assertNotNull("The fault info should not be null", fault.getFaultInfo());
}
}
use of org.apache.hello_world_soap_http.NoSuchCodeLitFault 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.NoSuchCodeLitFault 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.NoSuchCodeLitFault 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());
}
}
}
Aggregations