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/2014.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 | UnexpectedErrorFault | ExceededRequestSizeFault e) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.failedToInitClient", e.getLocalizedMessage()), e);
}
}
use of javax.xml.ws.WebServiceFeature in project scout.rt by eclipse.
the class PortProducer method provide.
/**
* Creates a new Port to interact with the webservice endpoint.
*/
@Override
public PORT provide() {
try {
// Create the service
final Constructor<? extends Service> constructor = m_serviceClazz.getConstructor(URL.class, QName.class);
@SuppressWarnings("unchecked") final SERVICE service = (SERVICE) constructor.newInstance(m_wsdlLocation, new QName(m_targetNamespace, m_serviceName));
// Install the handler chain
service.setHandlerResolver(new HandlerResolver() {
@Override
public List<Handler> getHandlerChain(final PortInfo portInfo) {
final List<Handler<? extends MessageContext>> handlerChain = new ArrayList<>();
m_initializer.initHandlers(handlerChain);
for (int i = 0; i < handlerChain.size(); i++) {
handlerChain.set(i, proxyHandler(handlerChain.get(i)));
}
@SuppressWarnings("unchecked") final List<Handler> handlers = TypeCastUtility.castValue(handlerChain, List.class);
return handlers;
}
});
// Install implementor specific webservice features
final List<WebServiceFeature> webServiceFeatures = new ArrayList<>();
m_initializer.initWebServiceFeatures(webServiceFeatures);
// Create the port
return service.getPort(m_portTypeClazz, CollectionUtility.toArray(webServiceFeatures, WebServiceFeature.class));
} catch (final ReflectiveOperationException e) {
throw new WebServiceException("Failed to instantiate webservice stub.", e);
}
}
use of javax.xml.ws.WebServiceFeature in project jbossws-cxf by jbossws.
the class HelperUsignThreadLocal method run.
public Integer run(final URL wsdlURL, final String strategyName, final int size, final int calls) {
final WebServiceFeature feature;
final String strategy;
if (strategyName != null) {
feature = convertToFeature(strategyName);
strategy = strategyName;
} else {
feature = null;
strategy = System.getProperty(Constants.JBWS_CXF_JAXWS_CLIENT_BUS_STRATEGY, null);
}
final BusCounter busCounter = new BusCounter();
final ThreadLocal<HelloWs> port = createPortThreadLocal(wsdlURL, feature, busCounter);
final ThreadFactory threadFactory = new ThreadFactory() {
private AtomicInteger i = new AtomicInteger(0);
@Override
public Thread newThread(Runnable r) {
return new Thread(r, "JBWS3373-TL-thread-" + i.getAndIncrement() + "-" + strategy);
}
};
ExecutorService es = Executors.newFixedThreadPool(size, threadFactory);
List<Client> clients = new ArrayList<HelperUsignThreadLocal.Client>();
for (int i = 0; i < calls; i++) {
clients.add(new Client(port));
}
int count = 0;
try {
List<Future<Boolean>> futures = es.invokeAll(clients);
for (Future<Boolean> f : futures) {
if (f.get()) {
count++;
}
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
es.shutdown();
}
if (count != calls) {
throw new RuntimeException((calls - count) + " client invocation(s) failed!");
}
return busCounter.getCount();
}
use of javax.xml.ws.WebServiceFeature in project jbossws-cxf by jbossws.
the class CXFServiceObjectFactoryJAXWS method getFeatures.
private WebServiceFeature[] getFeatures(final UnifiedPortComponentRefMetaData portComponentRefMD) {
List<WebServiceFeature> features = new LinkedList<WebServiceFeature>();
// configure @Addressing feature
if (portComponentRefMD.isAddressingAnnotationSpecified()) {
final boolean enabled = portComponentRefMD.isAddressingEnabled();
final boolean required = portComponentRefMD.isAddressingRequired();
final String refResponses = portComponentRefMD.getAddressingResponses();
AddressingFeature.Responses responses = AddressingFeature.Responses.ALL;
if ("ANONYMOUS".equals(refResponses))
responses = AddressingFeature.Responses.ANONYMOUS;
if ("NON_ANONYMOUS".equals(refResponses))
responses = AddressingFeature.Responses.NON_ANONYMOUS;
features.add(new AddressingFeature(enabled, required, responses));
}
// configure @MTOM feature
if (portComponentRefMD.isMtomEnabled()) {
features.add(new MTOMFeature(true, portComponentRefMD.getMtomThreshold()));
}
// configure @RespectBinding feature
if (portComponentRefMD.isRespectBindingAnnotationSpecified()) {
final boolean enabled = portComponentRefMD.isRespectBindingEnabled();
features.add(new RespectBindingFeature(enabled));
}
return features.size() == 0 ? null : features.toArray(new WebServiceFeature[] {});
}
use of javax.xml.ws.WebServiceFeature 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;
}
Aggregations