use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.
the class JAXWSMethodDispatcher method getImplementationMethod.
public Method getImplementationMethod(Method method) throws NoSuchMethodException {
Class<?> endpointClass = implInfo.getImplementorClass();
if (!endpointClass.isAssignableFrom(method.getDeclaringClass())) {
try {
Method m2 = endpointClass.getMethod(method.getName(), method.getParameterTypes());
if (Modifier.isVolatile(m2.getModifiers())) {
// bridge method, need to map the generics
Class<?>[] params = method.getParameterTypes();
for (Type t : method.getGenericParameterTypes()) {
if (t instanceof TypeVariable) {
TypeVariable<?> tv = (TypeVariable<?>) t;
for (int x = 0; x < implInfo.getSEIClass().getTypeParameters().length; x++) {
TypeVariable<?> t2 = implInfo.getSEIClass().getTypeParameters()[x];
if (t2.getName().equals(tv.getName())) {
params[x] = (Class<?>) implInfo.getSEIType().getActualTypeArguments()[x];
}
}
}
}
method = endpointClass.getMethod(method.getName(), params);
} else {
method = m2;
}
try {
ReflectionUtil.setAccessible(method);
} catch (Throwable t) {
// ignore
}
} catch (SecurityException e) {
throw new ServiceConstructionException(e);
}
}
return method;
}
use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.
the class ServiceImpl method createDispatch.
public <T> Dispatch<T> createDispatch(QName portName, Class<T> type, JAXBContext context, Mode mode, WebServiceFeature... features) {
// using this instead of JaxWsClientFactoryBean so that handlers are configured
JaxWsProxyFactoryBean clientFac = new JaxWsProxyFactoryBean();
// Initialize Features.
configureObject(portName.toString() + ".jaxws-client.proxyFactory", clientFac);
final AbstractServiceFactoryBean sf;
try {
DataBinding db;
if (context != null) {
db = new JAXBDataBinding(context);
} else {
db = new SourceDataBinding(type);
}
sf = createDispatchService(db);
} catch (ServiceConstructionException e) {
throw new WebServiceException(e);
}
JaxWsEndpointImpl endpoint = getJaxwsEndpoint(portName, sf, features);
// if the client factory has properties specified, then set those into the endpoint
if (clientFac.getProperties() != null) {
endpoint.putAll(clientFac.getProperties());
}
// add all the client factory features onto the endpoint feature list
endpoint.getFeatures().addAll(clientFac.getFeatures());
// if the client factory has a bus specified (other than the thread default),
// then use that for the client. Otherwise use the bus from this service.
Bus clientBus = getBus();
if (clientFac.getBus() != BusFactory.getThreadDefaultBus(false) && clientFac.getBus() != null) {
clientBus = clientFac.getBus();
}
@SuppressWarnings("rawtypes") List<Handler> hc = clientFac.getHandlers();
// CXF-3956
hc.addAll(handlerResolver.getHandlerChain(portInfos.get(portName)));
endpoint.getJaxwsBinding().setHandlerChain(hc);
// create the client object, then initialize the endpoint features against it
Client client = new ClientImpl(clientBus, endpoint, clientFac.getConduitSelector());
for (Feature af : endpoint.getFeatures()) {
af.initialize(client, clientBus);
}
// CXF-2822
initIntercepors(client, clientFac);
if (executor != null) {
client.getEndpoint().setExecutor(executor);
}
// then try to get it from the wsdl
if (!StringUtils.isEmpty(clientFac.getAddress())) {
client.getEndpoint().getEndpointInfo().setAddress(clientFac.getAddress());
} else {
// Set the the EPR's address in EndpointInfo
PortInfoImpl portInfo = portInfos.get(portName);
if (portInfo != null && !StringUtils.isEmpty(portInfo.getAddress())) {
client.getEndpoint().getEndpointInfo().setAddress(portInfo.getAddress());
}
}
Dispatch<T> disp = new DispatchImpl<>(client, mode, context, type);
configureObject(disp);
return disp;
}
use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.
the class AbstractJAXRSFactoryBean method checkResources.
protected void checkResources(boolean server) {
List<ClassResourceInfo> list = serviceFactory.getRealClassResourceInfo();
if (server) {
for (Iterator<ClassResourceInfo> it = list.iterator(); it.hasNext(); ) {
ClassResourceInfo cri = it.next();
if (!isValidClassResourceInfo(cri)) {
it.remove();
}
}
}
if (list.isEmpty()) {
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("NO_RESOURCES_AVAILABLE", BUNDLE);
LOG.severe(msg.toString());
throw new ServiceConstructionException(msg);
}
}
use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.
the class AbstractSpringComponentScanServer method createJaxRsServer.
@Override
protected Server createJaxRsServer() {
JAXRSServerFactoryBean factoryBean = null;
String[] beanNames = applicationContext.getBeanNamesForAnnotation(ApplicationPath.class);
if (beanNames.length > 0) {
Set<String> componentScanPackagesSet = parseSetProperty(componentScanPackages);
Set<String> componentScanBeansSet = parseSetProperty(componentScanBeans);
for (String beanName : beanNames) {
if (isComponentMatched(beanName, componentScanPackagesSet, componentScanBeansSet)) {
Application app = applicationContext.getBean(beanName, Application.class);
factoryBean = createFactoryBeanFromApplication(app);
for (String cxfBeanName : applicationContext.getBeanNamesForAnnotation(org.apache.cxf.annotations.Provider.class)) {
if (isComponentMatched(cxfBeanName, componentScanPackagesSet, componentScanBeansSet)) {
addCxfProvider(getProviderBean(cxfBeanName));
}
}
break;
}
}
}
if (!StringUtils.isEmpty(classesScanPackages)) {
try {
final Map<Class<? extends Annotation>, Collection<Class<?>>> appClasses = ClasspathScanner.findClasses(classesScanPackages, ApplicationPath.class);
List<Application> apps = CastUtils.cast(JAXRSServerFactoryBeanDefinitionParser.createBeansFromDiscoveredClasses(super.applicationContext, appClasses.get(ApplicationPath.class), null));
if (!apps.isEmpty()) {
factoryBean = createFactoryBeanFromApplication(apps.get(0));
final Map<Class<? extends Annotation>, Collection<Class<?>>> cxfClasses = ClasspathScanner.findClasses(classesScanPackages, org.apache.cxf.annotations.Provider.class);
addCxfProvidersFromClasses(cxfClasses.get(org.apache.cxf.annotations.Provider.class));
}
} catch (Exception ex) {
throw new ServiceConstructionException(ex);
}
}
if (factoryBean != null) {
setFactoryCxfProviders(factoryBean);
return factoryBean.create();
}
return super.createJaxRsServer();
}
use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.
the class JaxWsServiceFactoryBean method setServiceClass.
@Override
public void setServiceClass(Class<?> serviceClass) {
if (serviceClass == null) {
Message message = new Message("SERVICECLASS_MUST_BE_SET", LOG);
throw new ServiceConstructionException(message);
}
setJaxWsImplementorInfo(new JaxWsImplementorInfo(serviceClass));
super.setServiceClass(getJaxWsImplementorInfo().getEndpointClass());
super.setServiceType(getJaxWsImplementorInfo().getSEIType());
}
Aggregations