Search in sources :

Example 16 with MessageContext

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;
}
Also used : Convertor(com.evolveum.midpoint.model.impl.rest.Convertor) ConvertorInterface(com.evolveum.midpoint.model.impl.rest.ConvertorInterface) com.evolveum.midpoint.xml.ns._public.common.api_types_3(com.evolveum.midpoint.xml.ns._public.common.api_types_3) Autowired(org.springframework.beans.factory.annotation.Autowired) PATCH(com.evolveum.midpoint.model.impl.rest.PATCH) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) URI(java.net.URI) Scope(com.evolveum.midpoint.model.api.validator.Scope) ScriptingExpressionEvaluator(com.evolveum.midpoint.model.impl.scripting.ScriptingExpressionEvaluator) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) Collection(java.util.Collection) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) ValuePolicyProcessor(com.evolveum.midpoint.model.common.stringpolicy.ValuePolicyProcessor) List(java.util.List) javax.ws.rs(javax.ws.rs) ExecuteScriptType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExecuteScriptType) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) Validate(org.apache.commons.lang.Validate) RestServiceUtil(com.evolveum.midpoint.model.impl.util.RestServiceUtil) ExecuteScriptOutputType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExecuteScriptOutputType) ResourceValidator(com.evolveum.midpoint.model.api.validator.ResourceValidator) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) Item(com.evolveum.midpoint.prism.Item) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) TaskManager(com.evolveum.midpoint.task.api.TaskManager) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) com.evolveum.midpoint.model.api(com.evolveum.midpoint.model.api) MessageContext(org.apache.cxf.jaxrs.ext.MessageContext) DeltaConvertor(com.evolveum.midpoint.schema.DeltaConvertor) PrismContext(com.evolveum.midpoint.prism.PrismContext) Service(org.springframework.stereotype.Service) Status(javax.ws.rs.core.Response.Status) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) JAXBElement(javax.xml.bind.JAXBElement) PrismObject(com.evolveum.midpoint.prism.PrismObject) javax.ws.rs.core(javax.ws.rs.core) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) QueryBuilder(com.evolveum.midpoint.prism.query.builder.QueryBuilder) QueryJaxbConvertor(com.evolveum.midpoint.prism.query.QueryJaxbConvertor) ScriptingExpressionType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ScriptingExpressionType) Protector(com.evolveum.midpoint.prism.crypto.Protector) SecurityUtil(com.evolveum.midpoint.security.api.SecurityUtil) MidPointConstants(com.evolveum.midpoint.schema.constants.MidPointConstants) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ValidationResult(com.evolveum.midpoint.model.api.validator.ValidationResult) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SecurityHelper(com.evolveum.midpoint.model.impl.security.SecurityHelper) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 17 with MessageContext

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());
    }
}
Also used : OAuthProblemException(net.oauth.OAuthProblemException) Message(org.apache.cxf.message.Message) MessageContext(org.apache.cxf.jaxrs.ext.MessageContext) OAuthProblemException(net.oauth.OAuthProblemException) MessageContextImpl(org.apache.cxf.jaxrs.ext.MessageContextImpl)

Example 18 with MessageContext

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;
}
Also used : MessageContext(org.apache.cxf.jaxrs.ext.MessageContext) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 19 with MessageContext

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);
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) MessageContext(org.apache.cxf.jaxrs.ext.MessageContext)

Example 20 with MessageContext

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;
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) MessageContext(org.apache.cxf.jaxrs.ext.MessageContext) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Aggregations

MessageContext (org.apache.cxf.jaxrs.ext.MessageContext)31 List (java.util.List)11 Map (java.util.Map)11 ArrayList (java.util.ArrayList)7 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)7 Response (javax.ws.rs.core.Response)7 MessageContextImpl (org.apache.cxf.jaxrs.ext.MessageContextImpl)7 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)7 RestApiUtil (org.wso2.carbon.apimgt.rest.api.util.utils.RestApiUtil)7 HashMap (java.util.HashMap)6 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)5 StringUtils (org.apache.commons.lang3.StringUtils)5 Message (org.apache.cxf.message.Message)5 ExceptionCodes (org.wso2.carbon.apimgt.api.ExceptionCodes)5 RestApiConstants (org.wso2.carbon.apimgt.rest.api.common.RestApiConstants)5 InputStream (java.io.InputStream)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 URI (java.net.URI)3 MediaType (javax.ws.rs.core.MediaType)3 Log (org.apache.commons.logging.Log)3