Java Code Examples for org.apache.cxf.jaxrs.model.ClassResourceInfo#getResourceClass()
The following examples show how to use
org.apache.cxf.jaxrs.model.ClassResourceInfo#getResourceClass() .
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: CxfRsHttpListener.java From tomee with Apache License 2.0 | 5 votes |
public boolean isCXFResource(final HttpServletRequest request) { try { Application application = findApplication(); if (!applicationProvidesResources(application)) { JAXRSServiceImpl service = (JAXRSServiceImpl)server.getEndpoint().getService(); if( service == null ) { return false; } String pathToMatch = HttpUtils.getPathToMatch(request.getServletPath(), pattern, true); final List<ClassResourceInfo> resources = service.getClassResourceInfos(); for (final ClassResourceInfo info : resources) { if (info.getResourceClass() == null || info.getURITemplate() == null) { // possible? continue; } final MultivaluedMap<String, String> parameters = new MultivaluedHashMap<>(); if (info.getURITemplate().match(pathToMatch, parameters)) { return true; } } } else { return true; } } catch (final Exception e) { LOGGER.info("No JAX-RS service"); } return false; }
Example 2
Source File: CxfCdiAutoSetup.java From openwebbeans-meecrowave with Apache License 2.0 | 4 votes |
private Function<ServletDestination, String> getServletDestinationPath(ServletConfig sc, LogFacade log) { return sd -> { final Endpoint endpoint = ChainInitiationObserver.class.cast(sd.getMessageObserver()).getEndpoint(); final ApplicationInfo app = ApplicationInfo.class.cast(endpoint.get(Application.class.getName())); final JAXRSServiceFactoryBean sfb = JAXRSServiceFactoryBean.class.cast(endpoint.get(JAXRSServiceFactoryBean.class.getName())); final String base = sd.getEndpointInfo().getAddress(); if (sfb != null) { final List<Logs.LogResourceEndpointInfo> resourcesToLog = new ArrayList<>(); int classSize = 0; int addressSize = 0; final List<ClassResourceInfo> resources = sfb.getClassResourceInfo(); for (final ClassResourceInfo info : resources) { if (info.getResourceClass() == null) { // possible? continue; } final String address = Logs.singleSlash(base, info.getURITemplate().getValue()); final String clazz = uproxyName(info.getResourceClass().getName()); 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(address, clazz, toLog, methodSize, methodStrSize)); } // effective logging log.info("REST Application: " + endpoint.getEndpointInfo().getAddress() + " -> " + ofNullable(app).map(ApplicationInfo::getResourceClass).map(Class::getName).map(CxfCdiAutoSetup::uproxyName).orElse("")); Collections.sort(resourcesToLog); final int fClassSize = classSize; final int fAddressSize = addressSize; resourcesToLog.forEach(resource -> { log.info(" Service URI: " + Logs.forceLength(resource.address, fAddressSize, true) + " -> " + Logs.forceLength(resource.classname, fClassSize, true)); resource.operations.forEach(info -> { log.info(" " + Logs.forceLength(info.http, resource.methodSize, false) + " " + Logs.forceLength(info.address, fAddressSize, true) + " -> " + Logs.forceLength(info.method, resource.methodStrSize, true)); }); resource.operations.clear(); }); resourcesToLog.clear(); // log @Providers if (Configuration.class.cast(sc.getServletContext().getAttribute("meecrowave.configuration")).isJaxrsLogProviders()) { final ServerProviderFactory spf = ServerProviderFactory.class.cast(endpoint.get(ServerProviderFactory.class.getName())); dump(log, spf, "MessageBodyReaders", "messageReaders"); dump(log, spf, "MessageBodyWriters", "messageWriters"); } } else { final EndpointInfo endpointInfo = endpoint.getEndpointInfo(); if (endpointInfo.getName() != null) { log.info("@WebService > " + endpointInfo.getName().toString() + " -> " + base); } } return base; }; }
Example 3
Source File: AbstractJAXRSFactoryBean.java From cxf with Apache License 2.0 | 4 votes |
protected boolean isValidClassResourceInfo(ClassResourceInfo cri) { Class<?> serviceCls = cri.getServiceClass(); return !(cri.isCreatedFromModel() && serviceCls == cri.getResourceClass() && !InjectionUtils.isConcreteClass(serviceCls)); }
Example 4
Source File: CxfRsHttpListener.java From tomee with Apache License 2.0 | 4 votes |
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(); }