use of org.apache.cxf.jaxrs.ext.MessageContext in project midpoint by Evolveum.
the class ModelRestService method searchObjectsByType.
@GET
@Path("/{type}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/yaml" })
public <T extends ObjectType> Response searchObjectsByType(@PathParam("type") String type, @QueryParam("options") List<String> options, @Context UriInfo uriInfo, @Context MessageContext mc) {
Task task = RestServiceUtil.initRequest(mc);
OperationResult parentResult = task.getResult().createSubresult(OPERATION_SEARCH_OBJECTS);
Class<T> clazz = ObjectTypes.getClassFromRestType(type);
Response response;
try {
Collection<SelectorOptions<GetOperationOptions>> searchOptions = GetOperationOptions.fromRestOptions(options, null, null);
List<PrismObject<T>> objects = model.searchObjects(clazz, null, searchOptions, task, parentResult);
ObjectListType listType = new ObjectListType();
if (objects != null) {
List<ObjectType> list = objects.stream().map(o -> convert(clazz, o, parentResult.createOperationResultType())).collect(Collectors.toList());
listType.getObject().addAll(list);
}
response = RestServiceUtil.createResponse(Response.Status.OK, listType, parentResult, true);
// response = Response.ok().entity(listType).build();
} catch (Exception ex) {
response = RestServiceUtil.handleException(parentResult, ex);
}
parentResult.computeStatus();
finishRequest(task);
return response;
}
use of org.apache.cxf.jaxrs.ext.MessageContext in project cxf by apache.
the class OAuthRequestFilter method filter.
@Override
public void filter(ContainerRequestContext context) {
try {
Message m = JAXRSUtils.getCurrentMessage();
MessageContext mc = new MessageContextImpl(m);
OAuthInfo info = handleOAuthRequest(mc.getHttpServletRequest());
setSecurityContext(mc, m, info);
} catch (OAuthProblemException e) {
context.abortWith(Response.status(401).header("WWW-Authenticate", "OAuth").build());
} catch (Exception e) {
context.abortWith(Response.status(401).header("WWW-Authenticate", "OAuth").build());
}
}
use of org.apache.cxf.jaxrs.ext.MessageContext in project tomee by apache.
the class JAXBElementProvider method resolveXMLResourceURI.
protected String resolveXMLResourceURI(String path) {
MessageContext mc = getContext();
if (mc != null) {
String httpBasePath = (String) mc.get("http.base.path");
final UriBuilder builder;
if (httpBasePath != null) {
builder = UriBuilder.fromPath(httpBasePath);
} else {
builder = mc.getUriInfo().getBaseUriBuilder();
}
return builder.path(path).path(xmlResourceOffset).build().toString();
}
return path;
}
use of org.apache.cxf.jaxrs.ext.MessageContext in project tomee by apache.
the class JAXBElementProvider method getStreamWriter.
protected XMLStreamWriter getStreamWriter(Object obj, OutputStream os, MediaType mt) {
XMLStreamWriter writer = null;
MessageContext mc = getContext();
if (mc != null) {
writer = mc.getContent(XMLStreamWriter.class);
if (writer == null) {
XMLOutputFactory factory = (XMLOutputFactory) mc.get(XMLOutputFactory.class.getName());
if (factory != null) {
try {
writer = factory.createXMLStreamWriter(os);
} catch (XMLStreamException e) {
throw ExceptionUtils.toInternalServerErrorException(new RuntimeException("Cant' create XMLStreamWriter", e), null);
}
}
}
if (writer == null && getEnableStreaming()) {
writer = StaxUtils.createXMLStreamWriter(os);
}
}
if (writer == null && os == null) {
writer = getStreamHandlerFromCurrentMessage(XMLStreamWriter.class);
}
return createTransformWriterIfNeeded(writer, os, true);
}
use of org.apache.cxf.jaxrs.ext.MessageContext in project tomee by apache.
the class JAXBElementProvider method getStreamReader.
protected XMLStreamReader getStreamReader(InputStream is, Class<?> type, MediaType mt) {
MessageContext mc = getContext();
XMLStreamReader reader = mc != null ? mc.getContent(XMLStreamReader.class) : null;
if (reader == null && mc != null) {
XMLInputFactory factory = (XMLInputFactory) mc.get(XMLInputFactory.class.getName());
if (factory != null) {
try {
reader = factory.createXMLStreamReader(is);
} catch (XMLStreamException e) {
throw ExceptionUtils.toInternalServerErrorException(new RuntimeException("Can not create XMLStreamReader", e), null);
}
}
}
if (reader == null && is == null) {
reader = getStreamHandlerFromCurrentMessage(XMLStreamReader.class);
}
reader = createTransformReaderIfNeeded(reader, is);
reader = createDepthReaderIfNeeded(reader, is);
if (InjectionUtils.isSupportedCollectionOrArray(type)) {
return new JAXBCollectionWrapperReader(TransformUtils.createNewReaderIfNeeded(reader, is));
}
return reader;
}
Aggregations