javax.xml.ws.Provider Java Examples

The following examples show how to use javax.xml.ws.Provider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EndpointUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static boolean isValidImplementor(Class<?> implementorClass) {
    if (Provider.class.isAssignableFrom(implementorClass)
        && hasWebServiceProviderAnnotation(implementorClass)) {
        return true;
    }

    // implementor MUST be an instance of a class with a WebService
    // annotation
    // (that implements an SEI) OR a Provider

    if (hasWebServiceAnnotation(implementorClass)) {
        return true;
    }

    LOG.info("Implementor is not annotated with WebService annotation.");
    return false;
}
 
Example #2
Source File: JaxWsServiceFactoryBean.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Class<?> getProviderParameterType(Class<?> cls) {
    if (cls == null) {
        return null;
    }
    Type[] genericInterfaces = cls.getGenericInterfaces();
    for (Type type : genericInterfaces) {
        if (type instanceof ParameterizedType) {
            Class<?> rawCls = (Class<?>)((ParameterizedType)type).getRawType();
            if (Provider.class == rawCls) {
                return (Class<?>)((ParameterizedType)type).getActualTypeArguments()[0];
            }
        } else if (type instanceof Class && Provider.class.isAssignableFrom((Class<?>)type)) {
            return getProviderParameterType((Class<?>)type);
        }
    }
    return getProviderParameterType(cls.getSuperclass());
}
 
Example #3
Source File: JaxWsImplementorInfo.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static Class<?> doGetProviderParameterType(Class<?> c) {
    while (c != null) {
        Type[] intfTypes = c.getGenericInterfaces();
        for (Type t : intfTypes) {
            Class<?> clazz = JAXBEncoderDecoder.getClassFromType(t);
            if (Provider.class.isAssignableFrom(clazz)) {
                if (Provider.class == clazz) {
                    Type[] paramTypes = ((ParameterizedType)t).getActualTypeArguments();
                    return JAXBEncoderDecoder.getClassFromType(paramTypes[0]);
                }
                return doGetProviderParameterType(clazz);
            }
        }
        c = c.getSuperclass();
    }
    return null;
}
 
Example #4
Source File: AbstractJAXWSMethodInvoker.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Method getProviderServiceObjectMethod(Method m, Class<?> serviceObjectClass) {
    if (!Provider.class.isAssignableFrom(serviceObjectClass)) {
        return m;
    }
    Class<?> currentSvcClass = serviceObjectClass;
    Class<?> genericType = null;

    while (currentSvcClass != null) {
        genericType = getProviderGenericType(currentSvcClass);
        if (genericType != null) {
            break;
        }
        // Check superclass until top
        currentSvcClass = currentSvcClass.getSuperclass();
    }
    // Should never happens
    if (genericType == null) {
        return m;
    }
    try {
        return serviceObjectClass.getMethod("invoke", genericType);
    } catch (Exception e) {
        throw new ServiceConstructionException(e);
    }
}
 
Example #5
Source File: AbstractJAXWSMethodInvoker.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Class<?> getProviderGenericType(Class<?> svcClass) {
    Type[] interfaces = svcClass.getGenericInterfaces();
    for (Type interfaceType : interfaces) {
        if (interfaceType instanceof ParameterizedType) {
            ParameterizedType paramInterface = (ParameterizedType)interfaceType;
            if (!paramInterface.getRawType().equals(Provider.class)) {
                continue;
            }
            Type[] typeArgs = paramInterface.getActualTypeArguments();
            if (typeArgs.length > 0) {
                return (Class<?>)typeArgs[0];
            }
        }
    }
    return null;
}
 
Example #6
Source File: JAXWSProviderMethodDispatcher.java    From cxf with Apache License 2.0 5 votes vote down vote up
public JAXWSProviderMethodDispatcher(JaxWsImplementorInfo implInfo) {
    try {
        invoke = ReflectionUtil.getMethod(implInfo.getImplementorClass(), "invoke", 
                                          new Class[] {implInfo.getProviderParameterType()});
        ReflectionUtil.setAccessible(invoke);
    } catch (Exception e1) {
        //fall back to the raw Provider provided invoke method
        try {
            invoke = Provider.class.getMethod("invoke", new Class[] {Object.class});
        } catch (Exception e) {
            throw new ServiceConstructionException(e);
        }
    }
}
 
Example #7
Source File: JaxWsImplementorInfo.java    From cxf with Apache License 2.0 4 votes vote down vote up
public boolean isWebServiceProvider() {
    return Provider.class.isAssignableFrom(implementorClass);
}
 
Example #8
Source File: JAXWSMethodInvoker.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
protected Object invoke(Exchange exchange,
                        final Object serviceObject, Method m,
                        List<Object> params) {

    // set up the webservice request context
    WrappedMessageContext ctx = new WrappedMessageContext(exchange.getInMessage(), Scope.APPLICATION);

    Map<String, Object> handlerScopedStuff = removeHandlerProperties(ctx);

    final MessageContext oldCtx = WebServiceContextImpl.setMessageContext(ctx);
    List<Object> res = null;
    try {
        if ((params == null || params.isEmpty()) && serviceObject instanceof Provider) {
            params = Collections.singletonList(null);
        }
        res = CastUtils.cast((List<?>)super.invoke(exchange, serviceObject, m, params));

        if ((serviceObject instanceof Provider)
            && MessageUtils.getContextualBoolean(exchange.getInMessage(),
                                                 "jaxws.provider.interpretNullAsOneway",
                                                 true)
            && (res != null && !res.isEmpty() && res.get(0) == null)
            && exchange.getInMessage().getInterceptorChain().getState() == InterceptorChain.State.EXECUTING) {
            // treat the non-oneway call as oneway when a provider returns null
            // and the chain is not suspended due to a continuation suspend
            res = null;
            changeToOneway(exchange);
        }
        //update the webservice response context
        updateWebServiceContext(exchange, ctx);
    } catch (Fault f) {
        //get chance to copy over customer's header
        if (MessageUtils.getContextualBoolean(exchange.getInMessage(), COPY_SOAP_HEADERS_BY_FAULT, true)) {
            updateHeader(exchange, ctx);
        }
        throw f;
    } finally {
        //restore the WebServiceContextImpl's ThreadLocal variable to the previous value
        if (oldCtx == null) {
            WebServiceContextImpl.clear();
        } else {
            WebServiceContextImpl.setMessageContext(oldCtx);
        }

        addHandlerProperties(ctx, handlerScopedStuff);
    }
    return res;
}