Java Code Examples for org.apache.cxf.common.util.ClassHelper#getRealClass()

The following examples show how to use org.apache.cxf.common.util.ClassHelper#getRealClass() . 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: BlueprintResourceFactory.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void init() {
    Class<?> type = ClassHelper.getRealClassFromClass(blueprintContainer.getComponentInstance(beanId)
                                                      .getClass());
    if (Proxy.isProxyClass(type)) {
        type = ClassHelper.getRealClass(blueprintContainer.getComponentInstance(beanId));
    }
    c = ResourceUtils.findResourceConstructor(type, !isSingleton());
    if (c == null) {
        throw new RuntimeException("Resource class " + type + " has no valid constructor");
    }
    postConstructMethod = ResourceUtils.findPostConstructMethod(type);
    preDestroyMethod = ResourceUtils.findPreDestroyMethod(type);

    Object component = blueprintContainer.getComponentMetadata(beanId);
    if (component instanceof BeanMetadata) {
        BeanMetadata local = (BeanMetadata) component;
        isSingleton = BeanMetadata.SCOPE_SINGLETON.equals(local.getScope())
            || (local.getScope() == null && local.getId() != null);
    }
}
 
Example 2
Source File: SpringResourceFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void init() {
    type = ClassHelper.getRealClassFromClass(ac.getType(beanId));
    if (Proxy.isProxyClass(type)) {
        type = ClassHelper.getRealClass(ac.getBean(beanId));
    }
    isSingleton = ac.isSingleton(beanId);
    postConstructMethod = ResourceUtils.findPostConstructMethod(type, postConstructMethodName);
    preDestroyMethod = ResourceUtils.findPreDestroyMethod(type, preDestroyMethodName);

    if (isSingleton()) {
        try {
            singletonInstance = ac.getBean(beanId);
        } catch (BeansException ex) {
            // ignore for now, try resolving resource constructor later
        }
        if (singletonInstance != null) {
            return;
        }
    } else {
        isPrototype = ac.isPrototype(beanId);
    }
    c = ResourceUtils.findResourceConstructor(type, !isSingleton());
    if (c == null) {
        throw new RuntimeException("Resource class " + type
                                   + " has no valid constructor");
    }

}
 
Example 3
Source File: ServerProviderFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Integer getPriority(Collection<?> list, Class<?> cls, Class<?> filterClass) {
    Collection<ProviderInfo<?>> list2 = CastUtils.cast(list);
    for (ProviderInfo<?> p : list2) {
        if (p instanceof FilterProviderInfo) {
            Class<?> pClass = ClassHelper.getRealClass(p.getBus(), p.getProvider());
            if (cls.isAssignableFrom(pClass)) {
                return ((FilterProviderInfo<?>)p).getPriority(filterClass);
            }
        }
    }
    return Priorities.USER;
}
 
Example 4
Source File: ServerProviderFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
private boolean isRegistered(Collection<?> list, Class<?> cls) {
    Collection<ProviderInfo<?>> list2 = CastUtils.cast(list);
    for (ProviderInfo<?> p : list2) {
        Class<?> pClass = ClassHelper.getRealClass(p.getBus(), p.getProvider());
        if (cls.isAssignableFrom(pClass)) {
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: ServerProviderFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void doApplyDynamicFeatures(ClassResourceInfo cri) {
    Set<OperationResourceInfo> oris = cri.getMethodDispatcher().getOperationResourceInfos();
    for (OperationResourceInfo ori : oris) {
        String nameBinding = DEFAULT_FILTER_NAME_BINDING
            + ori.getClassResourceInfo().getServiceClass().getName()
            + "."
            + ori.getMethodToInvoke().toString();
        for (DynamicFeature feature : dynamicFeatures) {
            FeatureContext featureContext = createServerFeatureContext();
            feature.configure(new ResourceInfoImpl(ori), featureContext);
            Configuration cfg = featureContext.getConfiguration();
            for (Object provider : cfg.getInstances()) {
                Map<Class<?>, Integer> contracts = cfg.getContracts(provider.getClass());
                if (contracts != null && !contracts.isEmpty()) {
                    Class<?> providerCls = ClassHelper.getRealClass(getBus(), provider);
                    registerUserProvider(new FilterProviderInfo<Object>(provider.getClass(),
                        providerCls,
                        provider,
                        getBus(),
                        Collections.singleton(nameBinding),
                        true,
                        contracts));
                    ori.addNameBindings(Collections.singletonList(nameBinding));
                }
            }
        }
    }
    Collection<ClassResourceInfo> subs = cri.getSubResources();
    for (ClassResourceInfo sub : subs) {
        if (sub != cri) {
            doApplyDynamicFeatures(sub);
        }
    }
}
 
Example 6
Source File: ServerProviderFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void injectApplicationIntoFeature(Feature feature) {
    if (application != null) {
        AbstractResourceInfo info = new AbstractResourceInfo(feature.getClass(),
                                                             ClassHelper.getRealClass(feature),
                                                             true,
                                                             true,
                                                             getBus()) {
            @Override
            public boolean isSingleton() {
                return false;
            }
        };
        Method contextMethod = info.getContextMethods().get(Application.class);
        if (contextMethod != null) {
            InjectionUtils.injectThroughMethod(feature, contextMethod, application.getProvider());
            return;
        }
        for (Field contextField : info.getContextFields()) {
            if (Application.class == contextField.getType()) {
                InjectionUtils.injectContextField(info, contextField, feature, application.getProvider());
                break;
            }
        }
        
    }
    
}
 
Example 7
Source File: ProviderFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected static Set<String> getFilterNameBindings(Bus bus, Object provider) {
    Class<?> pClass = ClassHelper.getRealClass(bus, provider);
    Set<String> names = AnnotationUtils.getNameBindings(pClass.getAnnotations());
    if (names.isEmpty()) {
        names = Collections.singleton(DEFAULT_FILTER_NAME_BINDING);
    }
    return names;
}
 
Example 8
Source File: SecureAnnotationsInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void setSecuredObject(Object object) {
    Class<?> cls = ClassHelper.getRealClass(object);
    Map<String, String> rolesMap = new HashMap<>();
    findRoles(cls, rolesMap);
    if (rolesMap.isEmpty()) {
        LOG.warning("The roles map is empty, the service object is not protected");
    } else if (LOG.isLoggable(Level.FINE)) {
        for (Map.Entry<String, String> entry : rolesMap.entrySet()) {
            LOG.fine("Method: " + entry.getKey() + ", roles: " + entry.getValue());
        }
    }
    super.setMethodRolesMap(rolesMap);
}
 
Example 9
Source File: MicroProfileClientFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Set<Object> processProviders() {
    Set<Object> providers = new LinkedHashSet<>();
    for (Object provider : configuration.getInstances()) {
        Class<?> providerCls = ClassHelper.getRealClass(getBus(), provider);
        if (provider instanceof ClientRequestFilter || provider instanceof ClientResponseFilter) {
            FilterProviderInfo<Object> filter = new FilterProviderInfo<>(providerCls, providerCls,
                    provider, getBus(), configuration.getContracts(providerCls));
            providers.add(filter);
        } else {
            providers.add(provider);
        }
    }
    return providers;
}
 
Example 10
Source File: ClientProviderFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void setProviders(boolean custom, boolean busGlobal, Object... providers) {
    List<ProviderInfo<? extends Object>> theProviders =
        prepareProviders(custom, busGlobal, providers, null);
    super.setCommonProviders(theProviders);
    for (ProviderInfo<? extends Object> provider : theProviders) {
        Class<?> providerCls = ClassHelper.getRealClass(getBus(), provider.getProvider());
        if (providerCls == Object.class) {
            // If the provider is a lambda, ClassHelper.getRealClass returns Object.class
            providerCls = provider.getProvider().getClass();
        }
        if (filterContractSupported(provider, providerCls, ClientRequestFilter.class)) {
            addProviderToList(clientRequestFilters, provider);
        }

        if (filterContractSupported(provider, providerCls, ClientResponseFilter.class)) {
            addProviderToList(clientResponseFilters, provider);
        }

        if (ResponseExceptionMapper.class.isAssignableFrom(providerCls)) {
            addProviderToList(responseExceptionMappers, provider);
        }

        if (RxInvokerProvider.class.isAssignableFrom(providerCls)) {
            this.rxInvokerProvider = RxInvokerProvider.class.cast(provider.getProvider());
        }
    }
    Collections.sort(clientRequestFilters,
                     new BindingPriorityComparator(ClientRequestFilter.class, true));
    Collections.sort(clientResponseFilters,
                     new BindingPriorityComparator(ClientResponseFilter.class, false));

    injectContextProxies(responseExceptionMappers, clientRequestFilters, clientResponseFilters);
}
 
Example 11
Source File: CxfJaxrsServiceRegistrator.java    From aries-jax-rs-whiteboard with Apache License 2.0 5 votes vote down vote up
private static Set<String> getFilterNameBindings(
    Bus bus, Object provider) {
    Class<?> pClass = ClassHelper.getRealClass(bus, provider);
    Set<String> names = AnnotationUtils.getNameBindings(
        pClass.getAnnotations());
    if (names.isEmpty()) {
        names = Collections.singleton(DEFAULT_FILTER_NAME_BINDING);
    }
    return names;
}
 
Example 12
Source File: AbstractSpringComponentScanServer.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected boolean nonProxyClass(String beanName) {
    // JAX-RS runtime needs to be able to access the real component class to introspect it for
    // JAX-RS annotations; the following check ensures that the valid proxified components
    // are accepted while the client proxies are ignored.
    Class<?> type = ClassHelper.getRealClassFromClass(applicationContext.getType(beanName));
    if (Proxy.isProxyClass(type) && applicationContext.isSingleton(beanName)) {
        type = ClassHelper.getRealClass(applicationContext.getBean(beanName));
    }
    if (Proxy.isProxyClass(type)) {
        LOG.fine("Can not determine the real class of the component '" + beanName + "'");
        return false;
    }
    return true;
}
 
Example 13
Source File: MicroProfileClientProviderFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void setProviders(boolean custom, boolean busGlobal, Object... providers) {
    List<ProviderInfo<?>> theProviders =
            prepareProviders(custom, busGlobal, providers, null);
    super.setCommonProviders(theProviders);
    for (ProviderInfo<?> provider : theProviders) {
        Class<?> providerCls = ClassHelper.getRealClass(getBus(), provider.getProvider());

        if (ResponseExceptionMapper.class.isAssignableFrom(providerCls)) {
            addProviderToList(responseExceptionMappers, provider);
        }
        String className = "org.eclipse.microprofile.rest.client.ext.AsyncInvocationInterceptorFactory";
        try {
            
            Class<?> asyncIIFactoryClass = ClassLoaderUtils.loadClass(className,
                                                                      MicroProfileClientProviderFactory.class);
            if (asyncIIFactoryClass.isAssignableFrom(providerCls)) {
                addProviderToList(asyncInvocationInterceptorFactories, provider);
            }
        } catch (ClassNotFoundException ex) {
            // expected if using the MP Rest Client 1.0 APIs
            LOG.log(Level.FINEST, ex, () -> {
                return "Caught ClassNotFoundException - expected if using MP Rest Client 1.0 APIs"; });
        }

    }
    responseExceptionMappers.sort(comparator);
    asyncInvocationInterceptorFactories.sort(comparator);

    injectContextProxies(responseExceptionMappers);
    injectContextProxies(asyncInvocationInterceptorFactories);
}
 
Example 14
Source File: ClaimsAuthorizingInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void setSecuredObject(Object object) {
    Class<?> cls = ClassHelper.getRealClass(object);
    findClaims(cls);
    if (claims.isEmpty()) {
        LOG.warning("The claims list is empty, the service object is not protected");
    }
}
 
Example 15
Source File: StratosAuthorizingHandler.java    From product-private-paas with Apache License 2.0 5 votes vote down vote up
/**
 * The instance of the secured bean get injected by the IOC framework
 *
 * @param securedObject
 */
public void setSecuredObject(Object securedObject) {
    Class<?> clazz = ClassHelper.getRealClass(securedObject);
    authorizationActionMap = getAuthorizationActionMap(clazz);
    superTenantServiceSet = getSuperTenantServiceSet(clazz);

}
 
Example 16
Source File: StratosAuthorizingHandler.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
/**
 * The instance of the secured bean get injected by the IOC framework
 *
 * @param securedObject
 */
public void setSecuredObject(Object securedObject) {
    Class<?> clazz = ClassHelper.getRealClass(securedObject);
    authorizationActionMap = getAuthorizationActionMap(clazz);
    superTenantServiceSet = getSuperTenantServiceSet(clazz);

}
 
Example 17
Source File: StratosAuthorizingHandler.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
/**
 * The instance of the secured bean get injected by the IOC framework
 *
 * @param securedObject
 */
public void setSecuredObject(Object securedObject) {
    Class<?> clazz = ClassHelper.getRealClass(securedObject);
    authorizationActionMap = getAuthorizationActionMap(clazz);
    superTenantServiceSet = getSuperTenantServiceSet(clazz);

}
 
Example 18
Source File: SingletonResourceProvider.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Class<?> getResourceClass() {
    return ClassHelper.getRealClass(resourceInstance);
}
 
Example 19
Source File: ServerFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
public Class<?> getServiceBeanClass() {
    if (serviceBean != null) {
        return ClassHelper.getRealClass(getBus(), serviceBean);
    }
    return getServiceFactory().getServiceClass();
}
 
Example 20
Source File: ServerFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
public Server create() {
    ClassLoaderHolder orig = null;
    try {
        Server server = null;
        try {
            if (bus != null) {
                ClassLoader loader = bus.getExtension(ClassLoader.class);
                if (loader != null) {
                    orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                }
            }

            if (getServiceFactory().getProperties() == null) {
                getServiceFactory().setProperties(getProperties());
            } else if (getProperties() != null) {
                getServiceFactory().getProperties().putAll(getProperties());
            }
            if (serviceBean != null && getServiceClass() == null) {
                setServiceClass(ClassHelper.getRealClass(bus, serviceBean));
            }
            if (invoker != null) {
                getServiceFactory().setInvoker(invoker);
            } else if (serviceBean != null) {
                invoker = createInvoker();
                getServiceFactory().setInvoker(invoker);
            }

            Endpoint ep = createEndpoint();

            getServiceFactory().sendEvent(FactoryBeanListener.Event.PRE_SERVER_CREATE, server, serviceBean,
                                          serviceBean == null
                                          ? getServiceClass() == null
                                              ? getServiceFactory().getServiceClass()
                                              : getServiceClass()
                                          : getServiceClass() == null
                                              ? ClassHelper.getRealClass(getBus(), getServiceBean())
                                              : getServiceClass());

            server = new ServerImpl(getBus(),
                                    ep,
                                    getDestinationFactory(),
                                    getBindingFactory());

            if (ep.getService().getInvoker() == null) {
                if (invoker == null) {
                    ep.getService().setInvoker(createInvoker());
                } else {
                    ep.getService().setInvoker(invoker);
                }
            }

        } catch (EndpointException | BusException | IOException e) {
            throw new ServiceConstructionException(e);
        }

        if (serviceBean != null) {
            Class<?> cls = ClassHelper.getRealClass(getServiceBean());
            if (getServiceClass() == null || cls.equals(getServiceClass())) {
                initializeAnnotationInterceptors(server.getEndpoint(), cls);
            } else {
                initializeAnnotationInterceptors(server.getEndpoint(), cls, getServiceClass());
            }
        } else if (getServiceClass() != null) {
            initializeAnnotationInterceptors(server.getEndpoint(), getServiceClass());
        }

        applyFeatures(server);

        getServiceFactory().sendEvent(FactoryBeanListener.Event.SERVER_CREATED, server, serviceBean,
                                      serviceBean == null
                                      ? getServiceClass() == null
                                          ? getServiceFactory().getServiceClass()
                                          : getServiceClass()
                                      : getServiceClass() == null
                                          ? ClassHelper.getRealClass(getServiceBean())
                                          : getServiceClass());

        if (start) {
            try {
                server.start();
            } catch (RuntimeException re) {
                server.destroy(); // prevent resource leak
                throw re;
            }
        }
        getServiceFactory().reset();

        return server;
    } finally {
        if (orig != null) {
            orig.reset();
        }
    }
}