use of org.apache.cxf.jaxrs.model.OperationResourceInfo 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();
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project tomee by apache.
the class ResourceUtils method getAllTypesForResource.
private static void getAllTypesForResource(ClassResourceInfo resource, ResourceTypes types, boolean jaxbOnly, MessageBodyWriter<?> jaxbWriter) {
Class<?> jaxbElement = null;
try {
jaxbElement = ClassLoaderUtils.loadClass("javax.xml.bind.JAXBElement", ResourceUtils.class);
} catch (final ClassNotFoundException e) {
// no-op
}
for (OperationResourceInfo ori : resource.getMethodDispatcher().getOperationResourceInfos()) {
Method method = ori.getAnnotatedMethod() == null ? ori.getMethodToInvoke() : ori.getAnnotatedMethod();
Class<?> realReturnType = method.getReturnType();
Class<?> cls = realReturnType;
if (cls == Response.class || ori.isAsync()) {
cls = getActualJaxbType(cls, method, false);
}
Type type = method.getGenericReturnType();
if (jaxbOnly) {
checkJaxbType(resource.getServiceClass(), cls, realReturnType == Response.class || ori.isAsync() ? cls : type, types, method.getAnnotations(), jaxbWriter, jaxbElement);
} else {
types.getAllTypes().put(cls, type);
}
for (Parameter pm : ori.getParameters()) {
if (pm.getType() == ParameterType.REQUEST_BODY) {
Class<?> inType = method.getParameterTypes()[pm.getIndex()];
if (inType != AsyncResponse.class) {
Type paramType = method.getGenericParameterTypes()[pm.getIndex()];
if (jaxbOnly) {
checkJaxbType(resource.getServiceClass(), inType, paramType, types, method.getParameterAnnotations()[pm.getIndex()], jaxbWriter, jaxbElement);
} else {
types.getAllTypes().put(inType, paramType);
}
}
}
}
}
for (ClassResourceInfo sub : resource.getSubResources()) {
if (!isRecursiveSubResource(resource, sub)) {
getAllTypesForResource(sub, types, jaxbOnly, jaxbWriter);
}
}
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project tomee by apache.
the class ResourceUtils method createOperationInfo.
// CHECKSTYLE:ON
private static OperationResourceInfo createOperationInfo(Method m, Method annotatedMethod, ClassResourceInfo cri, Path path, String httpMethod) {
OperationResourceInfo ori = new OperationResourceInfo(m, annotatedMethod, cri);
URITemplate t = URITemplate.createTemplate(path);
ori.setURITemplate(t);
ori.setHttpMethod(httpMethod);
return ori;
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class ClientProxyImpl method retryInvoke.
@Override
protected Object retryInvoke(URI newRequestURI, MultivaluedMap<String, String> headers, Object body, Exchange exchange, Map<String, Object> invContext) throws Throwable {
Map<String, Object> reqContext = CastUtils.cast((Map<?, ?>) invContext.get(REQUEST_CONTEXT));
int bodyIndex = body != null ? (Integer) reqContext.get(PROXY_METHOD_PARAM_BODY_INDEX) : -1;
OperationResourceInfo ori = (OperationResourceInfo) reqContext.get(OperationResourceInfo.class.getName());
return doChainedInvocation(newRequestURI, headers, ori, null, body, bodyIndex, exchange, invContext);
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class OpenApiCustomizer method customize.
public void customize(final OpenAPI oas) {
if (replaceTags || javadocProvider != null) {
Map<String, ClassResourceInfo> operations = new HashMap<>();
Map<Pair<String, String>, OperationResourceInfo> methods = new HashMap<>();
cris.forEach(cri -> {
cri.getMethodDispatcher().getOperationResourceInfos().forEach(ori -> {
String normalizedPath = getNormalizedPath(cri.getURITemplate().getValue(), ori.getURITemplate().getValue());
operations.put(normalizedPath, cri);
methods.put(Pair.of(ori.getHttpMethod(), normalizedPath), ori);
});
});
List<Tag> tags = new ArrayList<>();
oas.getPaths().forEach((pathKey, pathItem) -> {
Optional<Tag> tag;
if (replaceTags && operations.containsKey(pathKey)) {
ClassResourceInfo cri = operations.get(pathKey);
tag = Optional.of(new Tag());
tag.get().setName(cri.getURITemplate().getValue().replaceAll("/", "_"));
if (javadocProvider != null) {
tag.get().setDescription(javadocProvider.getClassDoc(cri));
}
if (!tags.contains(tag.get())) {
tags.add(tag.get());
}
} else {
tag = Optional.empty();
}
pathItem.readOperationsMap().forEach((method, operation) -> {
if (replaceTags && tag.isPresent()) {
operation.setTags(Collections.singletonList(tag.get().getName()));
}
Pair<String, String> key = Pair.of(method.name(), pathKey);
if (methods.containsKey(key) && javadocProvider != null) {
OperationResourceInfo ori = methods.get(key);
if (StringUtils.isBlank(operation.getSummary())) {
operation.setSummary(javadocProvider.getMethodDoc(ori));
}
if (operation.getParameters() == null) {
List<Parameter> parameters = new ArrayList<>();
addParameters(parameters);
operation.setParameters(parameters);
}
for (int i = 0; i < operation.getParameters().size(); i++) {
if (StringUtils.isBlank(operation.getParameters().get(i).getDescription())) {
operation.getParameters().get(i).setDescription(extractJavadoc(operation, ori, i));
}
}
addParameters(operation.getParameters());
customizeResponses(operation, ori);
}
});
});
if (replaceTags && oas.getTags() != null) {
oas.setTags(tags);
}
}
}
Aggregations