use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project ddf by codice.
the class BodyWriter method doWriteBody.
void doWriteBody(Message outMessage, Object body, Type bodyType, Annotation[] customAnns, OutputStream os) throws Fault {
OperationResourceInfo ori = outMessage.getContent(OperationResourceInfo.class);
if (ori == null) {
return;
}
Method method = ori.getMethodToInvoke();
int bodyIndex = (Integer) outMessage.get("BODY_INDEX");
Annotation[] anns = customAnns != null ? customAnns : getMethodAnnotations(ori.getAnnotatedMethod(), bodyIndex);
try {
if (bodyIndex != -1) {
Class<?> paramClass = method.getParameterTypes()[bodyIndex];
Class<?> bodyClass = paramClass.isAssignableFrom(body.getClass()) ? paramClass : body.getClass();
Type genericType = method.getGenericParameterTypes()[bodyIndex];
if (bodyType != null) {
genericType = bodyType;
}
genericType = InjectionUtils.processGenericTypeIfNeeded(ori.getClassResourceInfo().getServiceClass(), bodyClass, genericType);
bodyClass = InjectionUtils.updateParamClassToTypeIfNeeded(bodyClass, genericType);
writeBody(body, outMessage, bodyClass, genericType, anns, os);
} else {
Type paramType = body.getClass();
if (bodyType != null) {
paramType = bodyType;
}
writeBody(body, outMessage, body.getClass(), paramType, anns, os);
}
} catch (Exception ex) {
throw new Fault(ex);
}
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project tomee 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)) {
OperationResourceInfo operationResourceInfo = contextMessage.getExchange().get(OperationResourceInfo.class);
if (operationResourceInfo != null) {
o = new ResourceContextImpl(contextMessage, operationResourceInfo);
}
} 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 tomee by apache.
the class ResourceUtils method createServiceClassResourceInfo.
public static ClassResourceInfo createServiceClassResourceInfo(Map<String, UserResource> resources, UserResource model, Class<?> sClass, boolean isRoot, boolean enableStatic, Bus bus) {
if (model == null) {
throw new RuntimeException("Resource class " + sClass.getName() + " has no model info");
}
ClassResourceInfo cri = new ClassResourceInfo(sClass, sClass, isRoot, enableStatic, true, model.getConsumes(), model.getProduces(), bus);
URITemplate t = URITemplate.createTemplate(model.getPath());
cri.setURITemplate(t);
MethodDispatcher md = new MethodDispatcher();
Map<String, UserOperation> ops = model.getOperationsAsMap();
Method defaultMethod = null;
Map<String, Method> methodNames = new HashMap<>();
for (Method m : cri.getServiceClass().getMethods()) {
if (m.getAnnotation(DefaultMethod.class) != null) {
// if needed we can also support multiple default methods
defaultMethod = m;
}
methodNames.put(m.getName(), m);
}
for (Map.Entry<String, UserOperation> entry : ops.entrySet()) {
UserOperation op = entry.getValue();
Method actualMethod = methodNames.get(op.getName());
if (actualMethod == null) {
actualMethod = defaultMethod;
}
if (actualMethod == null) {
continue;
}
OperationResourceInfo ori = new OperationResourceInfo(actualMethod, cri, URITemplate.createTemplate(op.getPath()), op.getVerb(), op.getConsumes(), op.getProduces(), op.getParameters(), op.isOneway());
String rClassName = actualMethod.getReturnType().getName();
if (op.getVerb() == null) {
if (resources.containsKey(rClassName)) {
ClassResourceInfo subCri = rClassName.equals(model.getName()) ? cri : createServiceClassResourceInfo(resources, resources.get(rClassName), actualMethod.getReturnType(), false, enableStatic, bus);
if (subCri != null) {
cri.addSubClassResourceInfo(subCri);
md.bind(ori, actualMethod);
}
}
} else {
md.bind(ori, actualMethod);
}
}
cri.setMethodDispatcher(md);
return checkMethodDispatcher(cri) ? cri : null;
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project tomee by apache.
the class JAXRSOutInterceptor method processResponse.
// Response shouldn't be closed here
@SuppressWarnings("resource")
private void processResponse(ServerProviderFactory providerFactory, Message message) {
if (isResponseAlreadyHandled(message)) {
return;
}
MessageContentsList objs = MessageContentsList.getContentsList(message);
if (objs == null || objs.isEmpty()) {
return;
}
Object responseObj = objs.get(0);
final Response response;
if (responseObj instanceof Response) {
response = (Response) responseObj;
if (response.getStatus() == 500 && message.getExchange().get(JAXRSUtils.EXCEPTION_FROM_MAPPER) != null) {
message.put(Message.RESPONSE_CODE, 500);
return;
}
} else {
int status = getStatus(message, responseObj != null ? 200 : 204);
response = JAXRSUtils.toResponseBuilder(status).entity(responseObj).build();
}
Exchange exchange = message.getExchange();
OperationResourceInfo ori = (OperationResourceInfo) exchange.get(OperationResourceInfo.class.getName());
serializeMessage(providerFactory, message, response, ori, true);
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project tomee by apache.
the class JAXRSInvoker method getResourceProvider.
private ResourceProvider getResourceProvider(Exchange exchange) {
Object provider = exchange.remove(JAXRSUtils.ROOT_PROVIDER);
if (provider == null) {
OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
ClassResourceInfo cri = ori.getClassResourceInfo();
return cri.getResourceProvider();
}
return (ResourceProvider) provider;
}
Aggregations