use of javax.xml.ws.WebServiceFeature in project cxf by apache.
the class ServiceImpl method createPort.
protected <T> T createPort(QName portName, EndpointReferenceType epr, Class<T> serviceEndpointInterface, WebServiceFeature... features) {
LOG.log(Level.FINE, "creating port for portName", portName);
LOG.log(Level.FINE, "endpoint reference:", epr);
LOG.log(Level.FINE, "endpoint interface:", serviceEndpointInterface);
JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
JaxWsClientFactoryBean clientFac = (JaxWsClientFactoryBean) proxyFac.getClientFactoryBean();
JaxWsServiceFactoryBean serviceFactory = (JaxWsServiceFactoryBean) proxyFac.getServiceFactory();
List<WebServiceFeature> f = getAllFeatures(features);
proxyFac.initFeatures();
if (f != null) {
serviceFactory.setWsFeatures(f);
}
proxyFac.setBus(bus);
proxyFac.setServiceClass(serviceEndpointInterface);
proxyFac.setServiceName(serviceName);
if (epr != null && epr.getAddress() != null && epr.getAddress().getValue() != null) {
clientFac.setAddress(epr.getAddress().getValue());
}
if (wsdlURL != null) {
proxyFac.setWsdlURL(wsdlURL);
}
configureObject(proxyFac);
configureObject(clientFac);
if (portName == null) {
QName portTypeName = getPortTypeName(serviceEndpointInterface);
Service service = serviceFactory.getService();
if (service == null) {
serviceFactory.setServiceClass(serviceEndpointInterface);
serviceFactory.setBus(getBus());
service = serviceFactory.create();
}
EndpointInfo ei = ServiceModelUtil.findBestEndpointInfo(portTypeName, service.getServiceInfos());
if (ei != null) {
portName = ei.getName();
} else {
portName = serviceFactory.getEndpointName();
}
}
serviceFactory.setEndpointName(portName);
if (epr != null) {
clientFac.setEndpointReference(epr);
}
PortInfoImpl portInfo = portInfos.get(portName);
if (portInfo != null) {
clientFac.setBindingId(portInfo.getBindingID());
clientFac.setAddress(portInfo.getAddress());
}
// configureObject(portName.toString() + ".jaxws-client.proxyFactory", proxyFac);
if (clazz != ServiceImpl.class) {
// handlerchain should be on the generated Service object
proxyFac.setLoadHandlers(false);
}
Object obj = proxyFac.create();
// Configure the Service
Service service = serviceFactory.getService();
configureObject(service);
// Configure the JaxWsEndpoitnImpl
Client client = ClientProxy.getClient(obj);
client.getEndpoint().setExecutor(executor);
client.setExecutor(executor);
JaxWsEndpointImpl jaxwsEndpoint = (JaxWsEndpointImpl) client.getEndpoint();
configureObject(jaxwsEndpoint);
@SuppressWarnings("rawtypes") List<Handler> hc = jaxwsEndpoint.getJaxwsBinding().getHandlerChain();
hc.addAll(handlerResolver.getHandlerChain(portInfos.get(portName)));
jaxwsEndpoint.getJaxwsBinding().setHandlerChain(hc);
LOG.log(Level.FINE, "created proxy", obj);
if (portInfo == null) {
addPort(portName, clientFac.getBindingId(), clientFac.getAddress());
}
return serviceEndpointInterface.cast(obj);
}
use of javax.xml.ws.WebServiceFeature in project cxf by apache.
the class JaxWsServiceFactoryBeanTest method testMtomFeature.
@Test
public void testMtomFeature() throws Exception {
JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();
bean.setBus(getBus());
bean.setServiceClass(GreeterImpl.class);
bean.setWsdlURL(getClass().getResource("/wsdl/hello_world.wsdl"));
bean.setWsFeatures(Arrays.asList(new WebServiceFeature[] { new MTOMFeature() }));
Service service = bean.create();
Endpoint endpoint = service.getEndpoints().values().iterator().next();
assertTrue(endpoint instanceof JaxWsEndpointImpl);
Binding binding = ((JaxWsEndpointImpl) endpoint).getJaxwsBinding();
assertTrue(binding instanceof SOAPBinding);
assertTrue(((SOAPBinding) binding).isMTOMEnabled());
}
use of javax.xml.ws.WebServiceFeature in project cxf by apache.
the class EndpointReferenceTest method testServiceGetPortUsingEndpointReference.
/*
* Any JAX-WS supported epr metadata MUST match the Service instances
* ServiceName, otherwise a WebServiceExeption MUST be thrown. Any JAX-WS
* supported epr metadata MUST match the PortName for the sei, otherwise a
* WebServiceException MUST be thrown. If the Service instance has an
* associated WSDL, its WSDL MUST be used to determine any binding
* information, anyWSDL in a JAX-WS suppported epr metadata MUST be ignored.
* If the Service instance does not have a WSDL, then any WSDL inlined in
* the JAX-WS supported metadata of the epr MUST be used to determine
* binding information. If there is not enough metadata in the Service
* instance or in the epr metadata to determine a port, then a
* WebServiceException MUST be thrown.
*/
@Test
public void testServiceGetPortUsingEndpointReference() throws Exception {
BusFactory.setDefaultBus(getBus());
GreeterImpl greeter1 = new GreeterImpl();
try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter1, (String) null)) {
endpoint.publish("http://localhost:8080/test");
javax.xml.ws.Service s = javax.xml.ws.Service.create(new QName("http://apache.org/hello_world_soap_http", "SoapPort"));
InputStream is = getClass().getResourceAsStream("resources/hello_world_soap_http_infoset.xml");
Document doc = StaxUtils.read(is);
DOMSource erXML = new DOMSource(doc);
EndpointReference endpointReference = EndpointReference.readFrom(erXML);
WebServiceFeature[] wfs = new WebServiceFeature[] {};
Greeter greeter = s.getPort(endpointReference, Greeter.class, wfs);
String response = greeter.greetMe("John");
assertEquals("Hello John", response);
}
}
use of javax.xml.ws.WebServiceFeature in project cxf by apache.
the class EndpointReferenceTest method testEndpointReferenceGetPort.
@Test
public void testEndpointReferenceGetPort() throws Exception {
BusFactory.setDefaultBus(getBus());
GreeterImpl greeter1 = new GreeterImpl();
try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter1, (String) null)) {
endpoint.publish("http://localhost:8080/test");
InputStream is = getClass().getResourceAsStream("resources/hello_world_soap_http_infoset.xml");
Document doc = StaxUtils.read(is);
DOMSource erXML = new DOMSource(doc);
EndpointReference endpointReference = EndpointReference.readFrom(erXML);
WebServiceFeature[] wfs = new WebServiceFeature[] {};
Greeter greeter = endpointReference.getPort(Greeter.class, wfs);
String response = greeter.greetMe("John");
assertEquals("Hello John", response);
}
}
use of javax.xml.ws.WebServiceFeature in project components by Talend.
the class NetSuiteClientServiceImpl method getNetSuitePort.
protected NetSuitePortType getNetSuitePort(String defaultEndpointUrl, String account) throws NetSuiteException {
try {
URL wsdlLocationUrl = this.getClass().getResource("/wsdl/2016.2/netsuite.wsdl");
NetSuiteService service = new NetSuiteService(wsdlLocationUrl, NetSuiteService.SERVICE);
List<WebServiceFeature> features = new ArrayList<>(2);
if (isMessageLoggingEnabled()) {
features.add(new LoggingFeature());
}
NetSuitePortType port = service.getNetSuitePort(features.toArray(new WebServiceFeature[features.size()]));
BindingProvider provider = (BindingProvider) port;
Map<String, Object> requestContext = provider.getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, defaultEndpointUrl);
GetDataCenterUrlsRequest dataCenterRequest = new GetDataCenterUrlsRequest();
dataCenterRequest.setAccount(account);
DataCenterUrls urls = null;
GetDataCenterUrlsResponse response = port.getDataCenterUrls(dataCenterRequest);
if (response != null && response.getGetDataCenterUrlsResult() != null) {
urls = response.getGetDataCenterUrlsResult().getDataCenterUrls();
}
if (urls == null) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.couldNotGetWebServiceDomain", defaultEndpointUrl));
}
String wsDomain = urls.getWebservicesDomain();
String endpointUrl = wsDomain.concat(new URL(defaultEndpointUrl).getPath());
requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);
return port;
} catch (WebServiceException | MalformedURLException | InsufficientPermissionFault | InvalidCredentialsFault | InvalidSessionFault | UnexpectedErrorFault | ExceededRequestSizeFault e) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.failedToInitClient", e.getLocalizedMessage()), e);
}
}
Aggregations