use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class ServerProviderFactory method doApplyDynamicFeatures.
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);
}
}
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class Swagger2Customizer method customize.
public Swagger customize(Swagger data) {
if (dynamicBasePath) {
MessageContext ctx = createMessageContext();
String currentBasePath = StringUtils.substringBeforeLast(ctx.getHttpServletRequest().getRequestURI(), "/");
data.setBasePath(currentBasePath);
if (data.getHost() == null) {
data.setHost(beanConfig.getHost());
}
if (data.getInfo() == null) {
data.setInfo(beanConfig.getInfo());
}
if (beanConfig.getSwagger() != null && beanConfig.getSwagger().getSecurityDefinitions() != null && data.getSecurityDefinitions() == null) {
data.setSecurityDefinitions(beanConfig.getSwagger().getSecurityDefinitions());
}
}
if (replaceTags || javadocProvider != null) {
Map<String, ClassResourceInfo> operations = new HashMap<>();
Map<Pair<String, String>, OperationResourceInfo> methods = new HashMap<>();
for (ClassResourceInfo cri : cris) {
for (OperationResourceInfo ori : cri.getMethodDispatcher().getOperationResourceInfos()) {
String normalizedPath = getNormalizedPath(cri.getURITemplate().getValue(), ori.getURITemplate().getValue());
operations.put(normalizedPath, cri);
methods.put(ImmutablePair.of(ori.getHttpMethod(), normalizedPath), ori);
}
}
if (replaceTags && data.getTags() != null) {
data.getTags().clear();
}
for (final Map.Entry<String, Path> entry : data.getPaths().entrySet()) {
Tag tag = null;
if (replaceTags && operations.containsKey(entry.getKey())) {
ClassResourceInfo cri = operations.get(entry.getKey());
tag = new Tag();
tag.setName(cri.getURITemplate().getValue().replaceAll("/", "_"));
if (javadocProvider != null) {
tag.setDescription(javadocProvider.getClassDoc(cri));
}
data.addTag(tag);
}
for (Map.Entry<HttpMethod, Operation> subentry : entry.getValue().getOperationMap().entrySet()) {
if (replaceTags && tag != null) {
subentry.getValue().setTags(Collections.singletonList(tag.getName()));
}
Pair<String, String> key = ImmutablePair.of(subentry.getKey().name(), entry.getKey());
if (methods.containsKey(key) && javadocProvider != null) {
OperationResourceInfo ori = methods.get(key);
subentry.getValue().setSummary(javadocProvider.getMethodDoc(ori));
for (int i = 0; i < subentry.getValue().getParameters().size(); i++) {
subentry.getValue().getParameters().get(i).setDescription(javadocProvider.getMethodParameterDoc(ori, i));
}
addParameters(subentry.getValue().getParameters());
if (subentry.getValue().getResponses() != null && !subentry.getValue().getResponses().isEmpty()) {
subentry.getValue().getResponses().entrySet().iterator().next().getValue().setDescription(javadocProvider.getMethodResponseDoc(ori));
}
}
}
}
}
if (replaceTags && data.getTags() != null) {
Collections.sort(data.getTags(), new Comparator<Tag>() {
@Override
public int compare(final Tag tag1, final Tag tag2) {
return tag1.getName().compareTo(tag2.getName());
}
});
}
applyDefaultVersion(data);
return data;
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class JAXRSUtils method createContextValue.
public static <T> T createContextValue(Message m, Type genericType, Class<T> clazz) {
Message contextMessage = getContextMessage(m);
Object o = null;
if (UriInfo.class.isAssignableFrom(clazz)) {
o = createUriInfo(contextMessage);
} else if (HttpHeaders.class.isAssignableFrom(clazz) || ProtocolHeaders.class.isAssignableFrom(clazz)) {
o = createHttpHeaders(contextMessage, clazz);
} else if (SecurityContext.class.isAssignableFrom(clazz)) {
SecurityContext customContext = contextMessage.get(SecurityContext.class);
o = customContext == null ? new SecurityContextImpl(contextMessage) : customContext;
} else if (MessageContext.class.isAssignableFrom(clazz)) {
o = new MessageContextImpl(m);
} else if (ResourceInfo.class.isAssignableFrom(clazz)) {
o = new ResourceInfoImpl(contextMessage);
} else if (ResourceContext.class.isAssignableFrom(clazz)) {
final OperationResourceInfo ori = contextMessage.getExchange().get(OperationResourceInfo.class);
if (ori != null) {
o = new ResourceContextImpl(contextMessage, ori);
}
} else if (Request.class.isAssignableFrom(clazz)) {
o = new RequestImpl(contextMessage);
} else if (Providers.class.isAssignableFrom(clazz)) {
o = new ProvidersImpl(contextMessage);
} else if (ContextResolver.class.isAssignableFrom(clazz)) {
o = createContextResolver(genericType, contextMessage);
} else if (Configuration.class.isAssignableFrom(clazz)) {
o = ProviderFactory.getInstance(contextMessage).getConfiguration(contextMessage);
} else if (Application.class.isAssignableFrom(clazz)) {
ProviderInfo<?> providerInfo = (ProviderInfo<?>) contextMessage.getExchange().getEndpoint().get(Application.class.getName());
o = providerInfo == null ? null : providerInfo.getProvider();
} else if (contextMessage != null) {
ContextProvider<?> provider = ProviderFactory.getInstance(contextMessage).createContextProvider(clazz, contextMessage);
if (provider != null) {
o = provider.createContext(contextMessage);
}
}
if (o == null && contextMessage != null && !MessageUtils.isRequestor(contextMessage)) {
o = HttpUtils.createServletResourceValue(contextMessage, clazz);
}
return clazz.cast(o);
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf 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 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);
}
}
}
Aggregations