use of org.apache.cxf.jaxws.support.JaxWsImplementorInfo in project cxf by apache.
the class WrapperClassGeneratorTest method testForXmlList.
@org.junit.Test
public void testForXmlList() throws Exception {
JaxWsImplementorInfo implInfo = new JaxWsImplementorInfo(AddNumbersImpl.class);
JaxWsServiceFactoryBean jaxwsFac = new JaxWsServiceFactoryBean(implInfo);
jaxwsFac.setBus(BusFactory.getDefaultBus());
Service service = jaxwsFac.create();
ServiceInfo serviceInfo = service.getServiceInfos().get(0);
InterfaceInfo interfaceInfo = serviceInfo.getInterface();
OperationInfo inf = interfaceInfo.getOperations().iterator().next();
Class<?> requestClass = inf.getInput().getMessagePart(0).getTypeClass();
Class<?> responseClass = inf.getOutput().getMessagePart(0).getTypeClass();
// Create request wrapper Object
List<String> partNames = Arrays.asList(new String[] { "arg0" });
List<String> elTypeNames = Arrays.asList(new String[] { "list" });
List<Class<?>> partClasses = Arrays.asList(new Class<?>[] { List.class });
String className = requestClass.getName();
className = className.substring(0, className.lastIndexOf(".") + 1);
WrapperHelper wh = new JAXBDataBinding().createWrapperHelper(requestClass, null, partNames, elTypeNames, partClasses);
List<Object> paraList = new ArrayList<>();
List<String> valueList = new ArrayList<>();
valueList.add("str1");
valueList.add("str2");
valueList.add("str3");
paraList.add(valueList);
Object requestObj = wh.createWrapperObject(paraList);
// Create response wrapper Object
partNames = Arrays.asList(new String[] { "return" });
elTypeNames = Arrays.asList(new String[] { "list" });
partClasses = Arrays.asList(new Class<?>[] { List.class });
className = responseClass.getName();
className = className.substring(0, className.lastIndexOf(".") + 1);
wh = new JAXBDataBinding().createWrapperHelper(responseClass, null, partNames, elTypeNames, partClasses);
List<Object> resPara = new ArrayList<>();
List<Integer> intValueList = new ArrayList<>();
intValueList.add(1);
intValueList.add(2);
intValueList.add(3);
resPara.add(intValueList);
Object responseObj = wh.createWrapperObject(resPara);
JAXBContext jaxbContext = JAXBContext.newInstance(requestClass, responseClass);
java.io.ByteArrayOutputStream bout = new java.io.ByteArrayOutputStream();
Marshaller marshaller = jaxbContext.createMarshaller();
// check marshall wrapper
marshaller.marshal(requestObj, bout);
String expected = "<arg0>str1 str2 str3</arg0>";
assertTrue("The generated request wrapper class does not contain the correct annotations", bout.toString().contains(expected));
bout.reset();
marshaller.marshal(responseObj, bout);
expected = "<return>1</return><return>2</return><return>3</return>";
assertTrue("The generated response wrapper class is not correct", bout.toString().contains(expected));
}
use of org.apache.cxf.jaxws.support.JaxWsImplementorInfo in project cxf by apache.
the class EndpointImpl method getServer.
public synchronized ServerImpl getServer(String addr) {
if (server == null) {
checkProperties();
ClassLoaderHolder loader = null;
try {
if (bus != null) {
ClassLoader newLoader = bus.getExtension(ClassLoader.class);
if (newLoader != null) {
loader = ClassLoaderUtils.setThreadContextClassloader(newLoader);
}
}
// Initialize the endpointName so we can do configureObject
QName origEpn = endpointName;
if (endpointName == null) {
JaxWsImplementorInfo implInfo = new JaxWsImplementorInfo(getImplementorClass());
endpointName = implInfo.getEndpointName();
}
if (serviceFactory != null) {
serverFactory.setServiceFactory(serviceFactory);
}
/*if (serviceName != null) {
serverFactory.getServiceFactory().setServiceName(serviceName);
}*/
configureObject(this);
endpointName = origEpn;
// Set up the server factory
serverFactory.setAddress(addr);
serverFactory.setStart(false);
serverFactory.setEndpointName(endpointName);
serverFactory.setServiceBean(implementor);
serverFactory.setBus(bus);
serverFactory.setFeatures(getFeatures());
serverFactory.setInvoker(invoker);
serverFactory.setSchemaLocations(schemaLocations);
if (serverFactory.getProperties() != null) {
serverFactory.getProperties().putAll(properties);
} else {
serverFactory.setProperties(properties);
}
// have supplied their own.
if (getWsdlLocation() != null) {
serverFactory.setWsdlURL(getWsdlLocation());
}
if (bindingUri != null) {
serverFactory.setBindingId(bindingUri);
}
if (serviceName != null) {
serverFactory.getServiceFactory().setServiceName(serviceName);
}
if (implementorClass != null) {
serverFactory.setServiceClass(implementorClass);
}
if (executor != null) {
serverFactory.getServiceFactory().setExecutor(executor);
}
if (!handlers.isEmpty()) {
serverFactory.addHandlers(handlers);
}
configureObject(serverFactory);
server = serverFactory.create();
org.apache.cxf.endpoint.Endpoint endpoint = getEndpoint();
if (in != null) {
endpoint.getInInterceptors().addAll(in);
}
if (out != null) {
endpoint.getOutInterceptors().addAll(out);
}
if (inFault != null) {
endpoint.getInFaultInterceptors().addAll(inFault);
}
if (outFault != null) {
endpoint.getOutFaultInterceptors().addAll(outFault);
}
if (properties != null) {
endpoint.putAll(properties);
}
configureObject(endpoint.getService());
configureObject(endpoint);
this.service = endpoint.getService();
if (getWsdlLocation() == null) {
// hold onto the wsdl location so cache won't clear till we go away
setWsdlLocation(serverFactory.getWsdlURL());
}
if (serviceName == null) {
setServiceName(serverFactory.getServiceFactory().getServiceQName());
}
if (endpointName == null) {
endpointName = endpoint.getEndpointInfo().getName();
}
} finally {
if (loader != null) {
loader.reset();
}
}
}
return (ServerImpl) server;
}
use of org.apache.cxf.jaxws.support.JaxWsImplementorInfo in project cxf by apache.
the class JaxWsServerFactoryBean method createBindingInfo.
@Override
protected BindingInfo createBindingInfo() {
JaxWsServiceFactoryBean sf = (JaxWsServiceFactoryBean) getServiceFactory();
JaxWsImplementorInfo implInfo = sf.getJaxWsImplementorInfo();
String jaxBid = implInfo.getBindingType();
String binding = getBindingId();
if (binding == null) {
binding = jaxBid;
setBindingId(binding);
}
if (binding.equals(SOAPBinding.SOAP11HTTP_BINDING) || binding.equals(SOAPBinding.SOAP11HTTP_MTOM_BINDING)) {
binding = "http://schemas.xmlsoap.org/wsdl/soap/";
setBindingId(binding);
if (getBindingConfig() == null) {
setBindingConfig(new JaxWsSoapBindingConfiguration(sf));
}
} else if (binding.equals(SOAPBinding.SOAP12HTTP_MTOM_BINDING)) {
binding = SOAPBinding.SOAP12HTTP_BINDING;
setBindingId(binding);
if (getBindingConfig() == null) {
setBindingConfig(new JaxWsSoapBindingConfiguration(sf));
}
}
if (getBindingConfig() instanceof JaxWsSoapBindingConfiguration) {
JaxWsSoapBindingConfiguration conf = (JaxWsSoapBindingConfiguration) getBindingConfig();
if (jaxBid.equals(SOAPBinding.SOAP12HTTP_BINDING)) {
conf.setVersion(Soap12.getInstance());
}
if (jaxBid.equals(SOAPBinding.SOAP12HTTP_MTOM_BINDING)) {
conf.setVersion(Soap12.getInstance());
conf.setMtomEnabled(true);
}
if (jaxBid.equals(SOAPBinding.SOAP11HTTP_MTOM_BINDING)) {
conf.setMtomEnabled(true);
}
if (transportId != null) {
conf.setTransportURI(transportId);
}
conf.setJaxWsServiceFactoryBean(sf);
}
BindingInfo bindingInfo = super.createBindingInfo();
if (implInfo.isWebServiceProvider()) {
bindingInfo.getService().setProperty("soap.force.doclit.bare", Boolean.TRUE);
if (this.getServiceFactory().isPopulateFromClass()) {
for (EndpointInfo ei : bindingInfo.getService().getEndpoints()) {
ei.setProperty("soap.no.validate.parts", Boolean.TRUE);
}
// Provider, but no wsdl. Synthetic ops
for (BindingOperationInfo op : bindingInfo.getOperations()) {
op.setProperty("operation.is.synthetic", Boolean.TRUE);
op.getOperationInfo().setProperty("operation.is.synthetic", Boolean.TRUE);
}
}
}
return bindingInfo;
}
use of org.apache.cxf.jaxws.support.JaxWsImplementorInfo in project cxf by apache.
the class ProviderServiceFactoryTest method testFromWSDL.
@Test
public void testFromWSDL() throws Exception {
URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(resource);
JaxWsImplementorInfo implInfo = new JaxWsImplementorInfo(HWSoapMessageProvider.class);
JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean(implInfo);
bean.setWsdlURL(resource.toString());
Bus bus = getBus();
bean.setBus(bus);
bean.setServiceClass(HWSoapMessageProvider.class);
Service service = bean.create();
assertTrue(service.getInvoker() instanceof JAXWSMethodInvoker);
assertEquals("SOAPService", service.getName().getLocalPart());
assertEquals("http://apache.org/hello_world_soap_http", service.getName().getNamespaceURI());
InterfaceInfo intf = service.getServiceInfos().get(0).getInterface();
assertNotNull(intf);
JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
svrFactory.setBus(bus);
svrFactory.setServiceFactory(bean);
svrFactory.setStart(false);
ServerImpl server = (ServerImpl) svrFactory.create();
assertTrue(server.getEndpoint().getService().getInvoker() instanceof JAXWSMethodInvoker);
Endpoint endpoint = server.getEndpoint();
Binding binding = endpoint.getBinding();
assertTrue(binding instanceof SoapBinding);
}
use of org.apache.cxf.jaxws.support.JaxWsImplementorInfo in project cxf by apache.
the class CodeFirstWSDLTest method createService.
private Definition createService(Class<?> clazz) throws Exception {
JaxWsImplementorInfo info = new JaxWsImplementorInfo(clazz);
ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean(info);
Bus bus = getBus();
bean.setBus(bus);
Service service = bean.create();
InterfaceInfo i = service.getServiceInfos().get(0).getInterface();
assertEquals(5, i.getOperations().size());
ServerFactoryBean svrFactory = new ServerFactoryBean();
svrFactory.setBus(bus);
svrFactory.setServiceFactory(bean);
svrFactory.setServiceBean(clazz.newInstance());
svrFactory.setAddress(address);
svrFactory.create();
Collection<BindingInfo> bindings = service.getServiceInfos().get(0).getBindings();
assertEquals(1, bindings.size());
ServiceWSDLBuilder wsdlBuilder = new ServiceWSDLBuilder(bus, service.getServiceInfos().get(0));
return wsdlBuilder.build();
}
Aggregations