use of org.jboss.wsf.stack.cxf.client.UseThreadBusFeature in project jbossws-cxf by jbossws.
the class Helper method getPort.
private HelloWorld getPort(WebServiceFeature... features) throws MalformedURLException {
URL wsdlURL = new URL(gzipFeatureEndpointURL + "?wsdl");
QName serviceName = new QName("http://org.jboss.ws/jaxws/cxf/jbws3879", "HelloWorldService");
Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
QName portQName = new QName("http://org.jboss.ws/jaxws/cxf/jbws3879", "HelloWorldImplPort");
return (HelloWorld) service.getPort(portQName, HelloWorld.class, features);
}
use of org.jboss.wsf.stack.cxf.client.UseThreadBusFeature in project jbossws-cxf by jbossws.
the class MessageLoggingTestCase method testClientLogging.
@Test
@RunAsClient
public void testClientLogging() throws Exception {
URL wsdlURL = new URL(baseURL + "/jaxws-cxf-logging/LoggingFeatureService/LoggingFeatureEndpoint?wsdl");
QName serviceName = new QName("http://logging.cxf.jaxws.ws.test.jboss.org/", "LoggingFeatureService");
Bus bus = BusFactory.newInstance().createBus();
try {
// install the a LoggingInInterceptor in the bus used for the client
LoggingInInterceptor myLoggingInterceptor = new LoggingInInterceptor();
OutputStream out = new ByteArrayOutputStream();
myLoggingInterceptor.setPrintWriter(new PrintWriter(out, true));
bus.getInInterceptors().add(myLoggingInterceptor);
BusFactory.setThreadDefaultBus(bus);
Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
QName portQName = new QName("http://logging.cxf.jaxws.ws.test.jboss.org/", "LoggingFeatureEndpointPort");
LoggingEndpoint port = (LoggingEndpoint) service.getPort(portQName, LoggingEndpoint.class);
String content = "foo";
port.echo(content);
String s = out.toString();
assertTrue("'" + content + "' not found in captured message: \n" + s, s.contains(content));
} finally {
bus.shutdown(true);
}
}
use of org.jboss.wsf.stack.cxf.client.UseThreadBusFeature in project jbossws-cxf by jbossws.
the class CXFServiceObjectFactoryJAXWS method instantiateService.
private Service instantiateService(final UnifiedServiceRefMetaData serviceRefMD, final Class<?> serviceClass) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, WSFException {
final List<WebServiceFeature> featuresList = getFeatures(serviceRefMD);
// force THREAD_BUS strategy so that the bus created before for this specific ref is used
if (!ClientBusSelector.getDefaultStrategy().equals(Constants.THREAD_BUS_STRATEGY)) {
featuresList.add(new UseThreadBusFeature());
}
final WebServiceFeature[] features = featuresList.size() == 0 ? null : featuresList.toArray(new WebServiceFeature[] {});
final QName serviceQName = this.getServiceQName(serviceRefMD, serviceClass);
URL wsdlURL = this.getWsdlURL(serviceRefMD, serviceClass);
if (wsdlURL == null) {
final String deployedServiceAddress = serviceRefMD.getDeployedServiceAddress(serviceQName);
if (deployedServiceAddress != null) {
try {
wsdlURL = new URL(deployedServiceAddress + "?wsdl");
} catch (MalformedURLException e) {
// ignore
Logger.getLogger(CXFServiceObjectFactoryJAXWS.class).trace(e);
}
}
}
Service target = null;
if (serviceClass == Service.class) {
// Generic javax.xml.ws.Service
if (wsdlURL != null) {
if (features != null) {
target = Service.create(wsdlURL, serviceQName, features);
} else {
target = Service.create(wsdlURL, serviceQName);
}
} else {
throw Messages.MESSAGES.cannotCreateServiceWithoutWsdlLocation(serviceRefMD);
}
} else {
// Generated javax.xml.ws.Service subclass
if (wsdlURL != null) {
if (features != null) {
try {
Constructor<?> ctor = serviceClass.getConstructor(new Class[] { URL.class, QName.class, WebServiceFeature[].class });
target = (Service) ctor.newInstance(new Object[] { wsdlURL, serviceQName, features });
} catch (NoSuchMethodException nsme) {
throw org.jboss.wsf.stack.cxf.Messages.MESSAGES.missingJAXWS22ServiceConstructor(serviceClass.getName(), nsme);
}
} else {
Constructor<?> ctor = serviceClass.getConstructor(new Class[] { URL.class, QName.class });
target = (Service) ctor.newInstance(new Object[] { wsdlURL, serviceQName });
}
} else {
if (features != null) {
try {
Constructor<?> ctor = serviceClass.getConstructor(new Class[] { WebServiceFeature[].class });
target = (Service) ctor.newInstance(new Object[] { features });
} catch (NoSuchMethodException nsme) {
throw org.jboss.wsf.stack.cxf.Messages.MESSAGES.missingJAXWS22ServiceConstructor(serviceClass.getName(), nsme);
}
} else {
target = (Service) serviceClass.newInstance();
}
}
}
return target;
}
use of org.jboss.wsf.stack.cxf.client.UseThreadBusFeature in project jbossws-cxf by jbossws.
the class BusTestCase method testReuse.
@Test
@RunAsClient
@OperateOnDeployment(WSDL_SERVER)
public void testReuse() throws Exception {
// odd wsdl GETs return WSDL doc with invalid soap:address
// even wsdl GETs return WSDL doc with valid soap:address
// invalid
final String wsdl1 = readWsdl(baseURL);
// valid
final String wsdl2 = readWsdl(baseURL);
// invalid
final String wsdl3 = readWsdl(baseURL);
// valid
final String wsdl4 = readWsdl(baseURL);
assertEquals(wsdl1, wsdl3);
assertEquals(wsdl2, wsdl4);
assertFalse(wsdl1.equals(wsdl2));
Bus bus = BusFactory.newInstance().createBus();
try {
BusFactory.setThreadDefaultBus(bus);
// invalid
Endpoint port = getPort(baseURL, bus, new UseThreadBusFeature());
try {
performInvocation(port);
fail("Failure expected, as the wsdl soap:address is not valid!");
} catch (WebServiceException wse) {
assertTrue(wse.getCause().getMessage().contains("InvalidEndpoint"));
}
// valid
port = getPort(baseURL, bus, new UseNewBusFeature());
// the port should now actually be built against the valid wsdl
// as a new bus should have been started (with a new WSDLManager)
// so the invocation is expected to succeed
performInvocation(port);
} finally {
bus.shutdown(true);
}
}
use of org.jboss.wsf.stack.cxf.client.UseThreadBusFeature in project jbossws-cxf by jbossws.
the class FastInfosetTestCase method testInfosetUsingFastInfosetAnnotation.
@Test
@RunAsClient
@OperateOnDeployment(DEP1)
public void testInfosetUsingFastInfosetAnnotation() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream in = new ByteArrayOutputStream();
PrintWriter pwIn = new PrintWriter(in);
PrintWriter pwOut = new PrintWriter(out);
Bus bus = BusFactory.newInstance().createBus();
BusFactory.setThreadDefaultBus(bus);
try {
bus.getInInterceptors().add(new LoggingInInterceptor(pwIn));
bus.getOutInterceptors().add(new LoggingOutInterceptor(pwOut));
URL wsdlURL = new URL(baseURL + "HelloWorldService/HelloWorldFIImpl?wsdl");
QName serviceName = new QName("http://org.jboss.ws/jaxws/cxf/fastinfoset", "HelloWorldFIService");
Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
QName portQName = new QName("http://org.jboss.ws/jaxws/cxf/fastinfoset", "HelloWorldFIImplPort");
HelloWorldFI port = (HelloWorldFI) service.getPort(portQName, HelloWorldFI.class);
assertEquals("helloworld", port.echo("helloworld"));
assertTrue("request is expected fastinfoset", out.toString().indexOf("application/fastinfoset") > -1);
assertTrue("response is expected fastinfoset", in.toString().indexOf("application/fastinfoset") > -1);
} finally {
bus.shutdown(true);
pwOut.close();
pwIn.close();
}
}
Aggregations