use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.
the class SpringBeansTest method testClientFromFactory.
@Test
public void testClientFromFactory() throws Exception {
AbstractFactoryBeanDefinitionParser.setFactoriesAreAbstract(false);
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/jaxws/spring/clients.xml" });
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
Greeter g = factory.create(Greeter.class);
ClientImpl c = (ClientImpl) ClientProxy.getClient(g);
for (Interceptor<? extends Message> i : c.getInInterceptors()) {
if (i instanceof LoggingInInterceptor) {
ctx.close();
return;
}
}
ctx.close();
fail("Did not configure the client");
}
use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.
the class SpringBeansTest method testClients.
@Test
public void testClients() throws Exception {
AbstractFactoryBeanDefinitionParser.setFactoriesAreAbstract(false);
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/jaxws/spring/clients.xml" });
ClientHolderBean greeters = (ClientHolderBean) ctx.getBean("greeters");
assertEquals(4, greeters.greeterCount());
Object bean = ctx.getBean("client1.proxyFactory");
assertNotNull(bean);
Greeter greeter = (Greeter) ctx.getBean("client1");
Greeter greeter2 = (Greeter) ctx.getBean("client1");
assertNotNull(greeter);
assertNotNull(greeter2);
assertSame(greeter, greeter2);
Client client = ClientProxy.getClient(greeter);
assertNotNull("expected ConduitSelector", client.getConduitSelector());
assertTrue("unexpected ConduitSelector", client.getConduitSelector() instanceof NullConduitSelector);
List<Interceptor<? extends Message>> inInterceptors = client.getInInterceptors();
boolean saaj = false;
boolean logging = false;
for (Interceptor<? extends Message> i : inInterceptors) {
if (i instanceof SAAJInInterceptor) {
saaj = true;
} else if (i instanceof LoggingInInterceptor) {
logging = true;
}
}
assertTrue(saaj);
assertTrue(logging);
saaj = false;
logging = false;
for (Interceptor<?> i : client.getOutInterceptors()) {
if (i instanceof SAAJOutInterceptor) {
saaj = true;
} else if (i instanceof LoggingOutInterceptor) {
logging = true;
}
}
assertTrue(saaj);
assertTrue(logging);
assertTrue(client.getEndpoint().getService().getDataBinding() instanceof SourceDataBinding);
JaxWsProxyFactoryBean factory = (JaxWsProxyFactoryBean) ctx.getBean("wsdlLocation.proxyFactory");
assertNotNull(factory);
String wsdlLocation = factory.getWsdlLocation();
assertEquals("We should get the right wsdl location", wsdlLocation, "wsdl/hello_world.wsdl");
factory = (JaxWsProxyFactoryBean) ctx.getBean("inlineSoapBinding.proxyFactory");
assertNotNull(factory);
BindingConfiguration bc = factory.getBindingConfig();
assertTrue(bc instanceof SoapBindingConfiguration);
SoapBindingConfiguration sbc = (SoapBindingConfiguration) bc;
assertTrue(sbc.getVersion() instanceof Soap12);
assertTrue("the soap configure should set isMtomEnabled to be true", sbc.isMtomEnabled());
Greeter g1 = greeters.getGreet1();
Greeter g2 = greeters.getGreet2();
assertNotSame(g1, g2);
ctx.close();
}
use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.
the class JaxWsClientThreadTest method testRequestContextThreadSafety.
@Test
public void testRequestContextThreadSafety() throws Throwable {
URL url = getClass().getResource("/wsdl/hello_world.wsdl");
javax.xml.ws.Service s = javax.xml.ws.Service.create(url, serviceName);
final Greeter greeter = s.getPort(portName, Greeter.class);
final InvocationHandler handler = Proxy.getInvocationHandler(greeter);
((BindingProvider) handler).getRequestContext().put(JaxWsClientProxy.THREAD_LOCAL_REQUEST_CONTEXT, Boolean.TRUE);
Map<String, Object> requestContext = ((BindingProvider) handler).getRequestContext();
String address = (String) requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
final Throwable[] errorHolder = new Throwable[1];
Runnable r = new Runnable() {
public void run() {
try {
final String protocol = "http-" + Thread.currentThread().getId();
for (int i = 0; i < 10; i++) {
String threadSpecificaddress = protocol + "://localhost:80/" + i;
Map<String, Object> requestContext = ((BindingProvider) handler).getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, threadSpecificaddress);
assertEquals("we get what we set", threadSpecificaddress, requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY));
try {
greeter.greetMe("Hi");
} catch (WebServiceException expected) {
// expected.getCause().printStackTrace();
MalformedURLException mue = (MalformedURLException) expected.getCause();
if (mue == null || mue.getMessage() == null) {
throw expected;
}
assertTrue("protocol contains thread id from context", mue.getMessage().indexOf(protocol) != 0);
}
requestContext.remove(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
assertTrue("property is null", requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY) == null);
}
} catch (Throwable t) {
// capture assert failures
errorHolder[0] = t;
}
}
};
final int numThreads = 5;
Thread[] threads = new Thread[numThreads];
for (int i = 0; i < numThreads; i++) {
threads[i] = new Thread(r);
}
for (int i = 0; i < numThreads; i++) {
threads[i].start();
}
for (int i = 0; i < numThreads; i++) {
threads[i].join();
}
if (errorHolder[0] != null) {
throw errorHolder[0];
}
// main thread contextValues are un changed
assertTrue("address from existing context has not changed", address.equals(requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY)));
// get the latest values
((ClientImpl.EchoContext) ((WrappedMessageContext) requestContext).getWrappedMap()).reload();
assertTrue("address is different", !address.equals(requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY)));
// verify value reflects what other threads were doing
assertTrue("property is null from last thread execution", requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY) == null);
}
use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.
the class ClientServerWebSocketTest method testTimeoutConfigutation.
@Test
public void testTimeoutConfigutation() throws Exception {
SOAPService service = new SOAPService();
Greeter greeter = service.getPort(portName, Greeter.class);
updateGreeterAddress(greeter, PORT);
((javax.xml.ws.BindingProvider) greeter).getRequestContext().put("javax.xml.ws.client.receiveTimeout", "1");
try {
greeter.greetMe("test");
// remove fail() check to let this test pass in the powerful machine
} catch (Throwable ex) {
Object cause = null;
if (ex.getCause() != null) {
cause = ex.getCause();
}
assertTrue("Timeout cause is expected", cause instanceof java.net.SocketTimeoutException);
}
}
use of org.apache.hello_world_soap_http.Greeter 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