Search in sources :

Example 1 with ClassResourceInfo

use of org.apache.cxf.jaxrs.model.ClassResourceInfo in project tomee by apache.

the class Contexts method bind.

@SuppressWarnings("UnusedDeclaration")
public static void bind(final Exchange exchange) {
    if (exchange == null) {
        return;
    }
    final ClassResourceInfo cri = exchange.get(OperationResourceInfo.class).getClassResourceInfo();
    // binding context fields
    final Set<Class<?>> types = new HashSet<>();
    for (final Field field : cri.getContextFields()) {
        types.add(field.getType());
    }
    bind(exchange, types);
}
Also used : Field(java.lang.reflect.Field) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) HashSet(java.util.HashSet)

Example 2 with ClassResourceInfo

use of org.apache.cxf.jaxrs.model.ClassResourceInfo in project tomee by apache.

the class AutoJAXRSInvoker method invoke.

@Override
public Object invoke(final Exchange exchange, final Object o) {
    // mainly a select the right invoker impl
    final ClassResourceInfo cri = (ClassResourceInfo) exchange.get("root.resource.class");
    if (cri != null) {
        final String clazz = cri.getServiceClass().getName();
        final EJBRestServiceInfo restServiceInfo = ejbs.get(clazz);
        if (restServiceInfo != null && !BeanType.MANAGED.equals(restServiceInfo.context.getComponentType())) {
            return ejbInvoker.invoke(exchange, o);
        }
    }
    return jaxrsInvoker.invoke(exchange, o);
}
Also used : ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) EJBRestServiceInfo(org.apache.openejb.server.rest.EJBRestServiceInfo)

Example 3 with ClassResourceInfo

use of org.apache.cxf.jaxrs.model.ClassResourceInfo in project camel by apache.

the class CxfRsEndpoint method setupJAXRSServerFactoryBean.

protected void setupJAXRSServerFactoryBean(JAXRSServerFactoryBean sfb) {
    // address
    if (getAddress() != null) {
        sfb.setAddress(getAddress());
    }
    processResourceModel(sfb);
    if (getResourceClasses() != null) {
        sfb.setResourceClasses(getResourceClasses());
    }
    // setup the resource providers for interfaces
    List<ClassResourceInfo> cris = sfb.getServiceFactory().getClassResourceInfo();
    for (ClassResourceInfo cri : cris) {
        final Class<?> serviceClass = cri.getServiceClass();
        if (serviceClass.isInterface()) {
            cri.setResourceProvider(new CamelResourceProvider(serviceClass));
        }
    }
    setupCommonFactoryProperties(sfb);
    sfb.setStart(false);
    getNullSafeCxfRsEndpointConfigurer().configure(sfb);
}
Also used : ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo)

Example 4 with ClassResourceInfo

use of org.apache.cxf.jaxrs.model.ClassResourceInfo in project tomee by apache.

the class CxfRsHttpListener method logEndpoints.

private void logEndpoints(final Application application, final String prefix, final Map<String, EJBRestServiceInfo> restEjbs, final JAXRSServerFactoryBean factory, final String base) {
    final List<Logs.LogResourceEndpointInfo> resourcesToLog = new ArrayList<>();
    int classSize = 0;
    int addressSize = 0;
    final JAXRSServiceImpl service = (JAXRSServiceImpl) factory.getServiceFactory().getService();
    final List<ClassResourceInfo> resources = service.getClassResourceInfos();
    for (final ClassResourceInfo info : resources) {
        if (info.getResourceClass() == null) {
            // possible?
            continue;
        }
        final String address = Logs.singleSlash(base, info.getURITemplate().getValue());
        final String clazz = info.getResourceClass().getName();
        final String type;
        if (restEjbs.containsKey(clazz)) {
            type = "EJB";
        } else {
            type = "Pojo";
        }
        classSize = Math.max(classSize, clazz.length());
        addressSize = Math.max(addressSize, address.length());
        int methodSize = 7;
        int methodStrSize = 0;
        final List<Logs.LogOperationEndpointInfo> toLog = new ArrayList<>();
        final MethodDispatcher md = info.getMethodDispatcher();
        for (final OperationResourceInfo ori : md.getOperationResourceInfos()) {
            final String httpMethod = ori.getHttpMethod();
            final String currentAddress = Logs.singleSlash(address, ori.getURITemplate().getValue());
            final String methodToStr = Logs.toSimpleString(ori.getMethodToInvoke());
            toLog.add(new Logs.LogOperationEndpointInfo(httpMethod, currentAddress, methodToStr));
            if (httpMethod != null) {
                methodSize = Math.max(methodSize, httpMethod.length());
            }
            addressSize = Math.max(addressSize, currentAddress.length());
            methodStrSize = Math.max(methodStrSize, methodToStr.length());
        }
        Collections.sort(toLog);
        resourcesToLog.add(new Logs.LogResourceEndpointInfo(type, address, clazz, toLog, methodSize, methodStrSize));
    }
    // effective logging
    LOGGER.info("REST Application: " + Logs.forceLength(prefix, addressSize, true) + " -> " + (InternalApplication.class.isInstance(application) && InternalApplication.class.cast(application).getOriginal() != null ? InternalApplication.class.cast(application).getOriginal() : application));
    Collections.sort(resourcesToLog);
    for (final Logs.LogResourceEndpointInfo resource : resourcesToLog) {
        // Init and register MBeans
        final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management").set("j2eeType", "JAX-RS").set("J2EEServer", "openejb").set("J2EEApplication", base).set("EndpointType", resource.type).set("name", resource.classname);
        final ObjectName jmxObjectName = jmxName.build();
        LocalMBeanServer.registerDynamicWrapperSilently(new RestServiceMBean(resource), jmxObjectName);
        jmxNames.add(jmxObjectName);
        LOGGER.info("     Service URI: " + Logs.forceLength(resource.address, addressSize, true) + " -> " + Logs.forceLength(resource.type, 4, false) + " " + Logs.forceLength(resource.classname, classSize, true));
        for (final Logs.LogOperationEndpointInfo log : resource.operations) {
            LOGGER.info("          " + Logs.forceLength(log.http, resource.methodSize, false) + " " + Logs.forceLength(log.address, addressSize, true) + " ->      " + Logs.forceLength(log.method, resource.methodStrSize, true));
        }
        resource.operations.clear();
    }
    resourcesToLog.clear();
}
Also used : InternalApplication(org.apache.openejb.server.rest.InternalApplication) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) ManagedEndpoint(org.apache.cxf.endpoint.ManagedEndpoint) Endpoint(org.apache.cxf.endpoint.Endpoint) ObjectName(javax.management.ObjectName) JAXRSServiceImpl(org.apache.cxf.jaxrs.JAXRSServiceImpl) ObjectNameBuilder(org.apache.openejb.monitoring.ObjectNameBuilder) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MethodDispatcher(org.apache.cxf.jaxrs.model.MethodDispatcher)

Aggregations

ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)4 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ObjectName (javax.management.ObjectName)1 Endpoint (org.apache.cxf.endpoint.Endpoint)1 ManagedEndpoint (org.apache.cxf.endpoint.ManagedEndpoint)1 JAXRSServiceImpl (org.apache.cxf.jaxrs.JAXRSServiceImpl)1 MethodDispatcher (org.apache.cxf.jaxrs.model.MethodDispatcher)1 ObjectNameBuilder (org.apache.openejb.monitoring.ObjectNameBuilder)1 EJBRestServiceInfo (org.apache.openejb.server.rest.EJBRestServiceInfo)1 InternalApplication (org.apache.openejb.server.rest.InternalApplication)1