Search in sources :

Example 26 with Context

use of javax.ws.rs.core.Context in project tomee by apache.

the class ResourceUtils method createConstructorArguments.

public static Object[] createConstructorArguments(Constructor<?> c, Message m, boolean perRequest, Map<Class<?>, Object> contextValues, Class<?>[] params, Annotation[][] anns, Type[] genericTypes) {
    if (m == null) {
        m = new MessageImpl();
    }
    @SuppressWarnings("unchecked") MultivaluedMap<String, String> templateValues = (MultivaluedMap<String, String>) m.get(URITemplate.TEMPLATE_PARAMETERS);
    Object[] values = new Object[params.length];
    for (int i = 0; i < params.length; i++) {
        if (AnnotationUtils.getAnnotation(anns[i], Context.class) != null) {
            Object contextValue = contextValues != null ? contextValues.get(params[i]) : null;
            if (contextValue == null) {
                if (perRequest || InjectionUtils.VALUE_CONTEXTS.contains(params[i].getName())) {
                    values[i] = JAXRSUtils.createContextValue(m, genericTypes[i], params[i]);
                } else {
                    values[i] = InjectionUtils.createThreadLocalProxy(params[i]);
                }
            } else {
                values[i] = contextValue;
            }
        } else {
            // this branch won't execute for singletons given that the found constructor
            // is guaranteed to have only Context parameters, if any, for singletons
            Parameter p = ResourceUtils.getParameter(i, anns[i], params[i]);
            values[i] = JAXRSUtils.createHttpParameterValue(p, params[i], genericTypes[i], anns[i], m, templateValues, null);
        }
    }
    return values;
}
Also used : Context(javax.ws.rs.core.Context) Parameter(org.apache.cxf.jaxrs.model.Parameter) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) MessageImpl(org.apache.cxf.message.MessageImpl)

Example 27 with Context

use of javax.ws.rs.core.Context in project graphhopper by graphhopper.

the class IsochroneResource method doGet.

@GET
@Produces(MediaType.APPLICATION_JSON)
public Response doGet(@Context UriInfo uriInfo, @QueryParam("profile") String profileName, @QueryParam("buckets") @Range(min = 1, max = 20) @DefaultValue("1") IntParam nBuckets, @QueryParam("reverse_flow") @DefaultValue("false") boolean reverseFlow, @QueryParam("point") @NotNull GHPointParam point, @QueryParam("time_limit") @DefaultValue("600") LongParam timeLimitInSeconds, @QueryParam("distance_limit") @DefaultValue("-1") LongParam distanceLimitInMeter, @QueryParam("weight_limit") @DefaultValue("-1") LongParam weightLimit, @QueryParam("type") @DefaultValue("json") ResponseType respType, @QueryParam("tolerance") @DefaultValue("0") double toleranceInMeter, @QueryParam("full_geometry") @DefaultValue("false") boolean fullGeometry) {
    StopWatch sw = new StopWatch().start();
    PMap hintsMap = new PMap();
    RouteResource.initHints(hintsMap, uriInfo.getQueryParameters());
    hintsMap.putObject(Parameters.CH.DISABLE, true);
    hintsMap.putObject(Parameters.Landmark.DISABLE, true);
    if (Helper.isEmpty(profileName)) {
        profileName = profileResolver.resolveProfile(hintsMap).getName();
        removeLegacyParameters(hintsMap);
    }
    errorIfLegacyParameters(hintsMap);
    Profile profile = graphHopper.getProfile(profileName);
    if (profile == null)
        throw new IllegalArgumentException("The requested profile '" + profileName + "' does not exist");
    LocationIndex locationIndex = graphHopper.getLocationIndex();
    Graph graph = graphHopper.getGraphHopperStorage();
    Weighting weighting = graphHopper.createWeighting(profile, hintsMap);
    BooleanEncodedValue inSubnetworkEnc = graphHopper.getEncodingManager().getBooleanEncodedValue(Subnetwork.key(profileName));
    if (hintsMap.has(Parameters.Routing.BLOCK_AREA)) {
        GraphEdgeIdFinder.BlockArea blockArea = GraphEdgeIdFinder.createBlockArea(graph, locationIndex, Collections.singletonList(point.get()), hintsMap, new FiniteWeightFilter(weighting));
        weighting = new BlockAreaWeighting(weighting, blockArea);
    }
    Snap snap = locationIndex.findClosest(point.get().lat, point.get().lon, new DefaultSnapFilter(weighting, inSubnetworkEnc));
    if (!snap.isValid())
        throw new IllegalArgumentException("Point not found:" + point);
    QueryGraph queryGraph = QueryGraph.create(graph, snap);
    TraversalMode traversalMode = profile.isTurnCosts() ? EDGE_BASED : NODE_BASED;
    ShortestPathTree shortestPathTree = new ShortestPathTree(queryGraph, queryGraph.wrapWeighting(weighting), reverseFlow, traversalMode);
    double limit;
    if (weightLimit.get() > 0) {
        limit = weightLimit.get();
        shortestPathTree.setWeightLimit(limit + Math.max(limit * 0.14, 2_000));
    } else if (distanceLimitInMeter.get() > 0) {
        limit = distanceLimitInMeter.get();
        shortestPathTree.setDistanceLimit(limit + Math.max(limit * 0.14, 2_000));
    } else {
        limit = timeLimitInSeconds.get() * 1000;
        shortestPathTree.setTimeLimit(limit + Math.max(limit * 0.14, 200_000));
    }
    ArrayList<Double> zs = new ArrayList<>();
    double delta = limit / nBuckets.get();
    for (int i = 0; i < nBuckets.get(); i++) {
        zs.add((i + 1) * delta);
    }
    ToDoubleFunction<ShortestPathTree.IsoLabel> fz;
    if (weightLimit.get() > 0) {
        fz = l -> l.weight;
    } else if (distanceLimitInMeter.get() > 0) {
        fz = l -> l.distance;
    } else {
        fz = l -> l.time;
    }
    Triangulator.Result result = triangulator.triangulate(snap, queryGraph, shortestPathTree, fz, degreesFromMeters(toleranceInMeter));
    ContourBuilder contourBuilder = new ContourBuilder(result.triangulation);
    ArrayList<Geometry> isochrones = new ArrayList<>();
    for (Double z : zs) {
        logger.info("Building contour z={}", z);
        MultiPolygon isochrone = contourBuilder.computeIsoline(z, result.seedEdges);
        if (fullGeometry) {
            isochrones.add(isochrone);
        } else {
            Polygon maxPolygon = heuristicallyFindMainConnectedComponent(isochrone, isochrone.getFactory().createPoint(new Coordinate(point.get().lon, point.get().lat)));
            isochrones.add(isochrone.getFactory().createPolygon(((LinearRing) maxPolygon.getExteriorRing())));
        }
    }
    ArrayList<JsonFeature> features = new ArrayList<>();
    for (Geometry isochrone : isochrones) {
        JsonFeature feature = new JsonFeature();
        HashMap<String, Object> properties = new HashMap<>();
        properties.put("bucket", features.size());
        if (respType == geojson) {
            properties.put("copyrights", ResponsePathSerializer.COPYRIGHTS);
        }
        feature.setProperties(properties);
        feature.setGeometry(isochrone);
        features.add(feature);
    }
    ObjectNode json = JsonNodeFactory.instance.objectNode();
    sw.stop();
    ObjectNode finalJson = null;
    if (respType == geojson) {
        json.put("type", "FeatureCollection");
        json.putPOJO("features", features);
        finalJson = json;
    } else {
        json.putPOJO("polygons", features);
        final ObjectNode info = json.putObject("info");
        info.putPOJO("copyrights", ResponsePathSerializer.COPYRIGHTS);
        info.put("took", Math.round((float) sw.getMillis()));
        finalJson = json;
    }
    logger.info("took: " + sw.getSeconds() + ", visited nodes:" + shortestPathTree.getVisitedNodes());
    return Response.ok(finalJson).header("X-GH-Took", "" + sw.getSeconds() * 1000).build();
}
Also used : ProfileResolver(com.graphhopper.routing.ProfileResolver) LoggerFactory(org.slf4j.LoggerFactory) Subnetwork(com.graphhopper.routing.ev.Subnetwork) HashMap(java.util.HashMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) Range(org.hibernate.validator.constraints.Range) Inject(javax.inject.Inject) MediaType(javax.ws.rs.core.MediaType) ShortestPathTree(com.graphhopper.isochrone.algorithm.ShortestPathTree) BlockAreaWeighting(com.graphhopper.routing.weighting.BlockAreaWeighting) IntParam(io.dropwizard.jersey.params.IntParam) Profile(com.graphhopper.config.Profile) TraversalMode(com.graphhopper.routing.util.TraversalMode) Graph(com.graphhopper.storage.Graph) NODE_BASED(com.graphhopper.routing.util.TraversalMode.NODE_BASED) GraphHopper(com.graphhopper.GraphHopper) org.locationtech.jts.geom(org.locationtech.jts.geom) com.graphhopper.util(com.graphhopper.util) Logger(org.slf4j.Logger) Context(javax.ws.rs.core.Context) ResponsePathSerializer(com.graphhopper.jackson.ResponsePathSerializer) LocationIndex(com.graphhopper.storage.index.LocationIndex) RouteResource.errorIfLegacyParameters(com.graphhopper.resources.RouteResource.errorIfLegacyParameters) LongParam(io.dropwizard.jersey.params.LongParam) BooleanEncodedValue(com.graphhopper.routing.ev.BooleanEncodedValue) NotNull(javax.validation.constraints.NotNull) ResponseType.geojson(com.graphhopper.resources.IsochroneResource.ResponseType.geojson) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph) GHPointParam(com.graphhopper.http.GHPointParam) GraphEdgeIdFinder(com.graphhopper.storage.GraphEdgeIdFinder) Triangulator(com.graphhopper.isochrone.algorithm.Triangulator) ContourBuilder(com.graphhopper.isochrone.algorithm.ContourBuilder) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Weighting(com.graphhopper.routing.weighting.Weighting) ToDoubleFunction(java.util.function.ToDoubleFunction) FiniteWeightFilter(com.graphhopper.routing.util.FiniteWeightFilter) DefaultSnapFilter(com.graphhopper.routing.util.DefaultSnapFilter) Snap(com.graphhopper.storage.index.Snap) UriInfo(javax.ws.rs.core.UriInfo) EDGE_BASED(com.graphhopper.routing.util.TraversalMode.EDGE_BASED) Collections(java.util.Collections) RouteResource.removeLegacyParameters(com.graphhopper.resources.RouteResource.removeLegacyParameters) GraphEdgeIdFinder(com.graphhopper.storage.GraphEdgeIdFinder) Triangulator(com.graphhopper.isochrone.algorithm.Triangulator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BlockAreaWeighting(com.graphhopper.routing.weighting.BlockAreaWeighting) TraversalMode(com.graphhopper.routing.util.TraversalMode) Snap(com.graphhopper.storage.index.Snap) Profile(com.graphhopper.config.Profile) FiniteWeightFilter(com.graphhopper.routing.util.FiniteWeightFilter) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultSnapFilter(com.graphhopper.routing.util.DefaultSnapFilter) LocationIndex(com.graphhopper.storage.index.LocationIndex) Graph(com.graphhopper.storage.Graph) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph) BlockAreaWeighting(com.graphhopper.routing.weighting.BlockAreaWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) BooleanEncodedValue(com.graphhopper.routing.ev.BooleanEncodedValue) ContourBuilder(com.graphhopper.isochrone.algorithm.ContourBuilder) ShortestPathTree(com.graphhopper.isochrone.algorithm.ShortestPathTree) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph)

Example 28 with Context

use of javax.ws.rs.core.Context in project graylog2-server by Graylog2.

the class StreamResource method create.

@POST
@Timed
@ApiOperation(value = "Create a stream")
@RequiresPermissions(RestPermissions.STREAMS_CREATE)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.STREAM_CREATE)
public Response create(@ApiParam(name = "JSON body", required = true) final CreateStreamRequest cr, @Context UserContext userContext) throws ValidationException {
    // Create stream.
    final Stream stream = streamService.create(cr, getCurrentUser().getName());
    stream.setDisabled(true);
    final IndexSet indexSet = stream.getIndexSet();
    if (!indexSet.getConfig().isWritable()) {
        throw new BadRequestException("Assigned index set must be writable!");
    } else if (!indexSet.getConfig().isRegularIndex()) {
        throw new BadRequestException("Assigned index set is not usable");
    }
    final Set<StreamRule> streamRules = cr.rules().stream().map(streamRule -> streamRuleService.create(null, streamRule)).collect(Collectors.toSet());
    final String id = streamService.saveWithRulesAndOwnership(stream, streamRules, userContext.getUser());
    final Map<String, String> result = ImmutableMap.of("stream_id", id);
    final URI streamUri = getUriBuilderToSelf().path(StreamResource.class).path("{streamId}").build(id);
    return Response.created(streamUri).entity(result).build();
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) Arrays(java.util.Arrays) Produces(javax.ws.rs.Produces) Tools(org.graylog2.plugin.Tools) UserContext(org.graylog.security.UserContext) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) AlertService(org.graylog2.alerts.AlertService) StreamRule(org.graylog2.plugin.streams.StreamRule) NotEmpty(javax.validation.constraints.NotEmpty) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) PaginatedList(org.graylog2.database.PaginatedList) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) SearchQueryField(org.graylog2.search.SearchQueryField) AlertConditionSummary(org.graylog2.rest.models.streams.alerts.AlertConditionSummary) StreamImpl(org.graylog2.streams.StreamImpl) StreamRuleService(org.graylog2.streams.StreamRuleService) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) BadRequestException(javax.ws.rs.BadRequestException) IndexSet(org.graylog2.indexer.IndexSet) URI(java.net.URI) DELETE(javax.ws.rs.DELETE) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) StreamRouterEngine(org.graylog2.streams.StreamRouterEngine) ISODateTimeFormat(org.joda.time.format.ISODateTimeFormat) ImmutableSet(com.google.common.collect.ImmutableSet) Context(javax.ws.rs.core.Context) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Timed(com.codahale.metrics.annotation.Timed) CreateStreamRequest(org.graylog2.rest.resources.streams.requests.CreateStreamRequest) CreateAlarmCallbackRequest(org.graylog2.rest.models.alarmcallbacks.requests.CreateAlarmCallbackRequest) List(java.util.List) Response(javax.ws.rs.core.Response) Stream(org.graylog2.plugin.streams.Stream) AuditEventTypes(org.graylog2.audit.AuditEventTypes) StreamService(org.graylog2.streams.StreamService) AlertCondition(org.graylog2.plugin.alarms.AlertCondition) AlertReceivers(org.graylog2.rest.models.alarmcallbacks.requests.AlertReceivers) StreamDTO(org.graylog2.streams.StreamDTO) CreateConditionRequest(org.graylog2.rest.models.streams.alerts.requests.CreateConditionRequest) Optional(java.util.Optional) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) PathParam(javax.ws.rs.PathParam) PaginatedStreamService(org.graylog2.streams.PaginatedStreamService) CloneStreamRequest(org.graylog2.rest.resources.streams.requests.CloneStreamRequest) SearchQueryParser(org.graylog2.search.SearchQueryParser) GET(javax.ws.rs.GET) TestMatchResponse(org.graylog2.rest.resources.streams.responses.TestMatchResponse) StreamPageListResponse(org.graylog2.rest.resources.streams.responses.StreamPageListResponse) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) StreamListResponse(org.graylog2.rest.resources.streams.responses.StreamListResponse) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) UpdateStreamRequest(org.graylog2.rest.models.streams.requests.UpdateStreamRequest) Lists(com.google.common.collect.Lists) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) AuditEvent(org.graylog2.audit.jersey.AuditEvent) Api(io.swagger.annotations.Api) SearchQuery(org.graylog2.search.SearchQuery) NotFoundException(org.graylog2.database.NotFoundException) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) DateTime(org.joda.time.DateTime) RestResource(org.graylog2.shared.rest.resources.RestResource) OutputSummary(org.graylog2.rest.models.system.outputs.responses.OutputSummary) Maps(com.google.common.collect.Maps) AlarmCallbackConfigurationService(org.graylog2.alarmcallbacks.AlarmCallbackConfigurationService) Output(org.graylog2.plugin.streams.Output) ApiResponse(io.swagger.annotations.ApiResponse) ValidationException(org.graylog2.plugin.database.ValidationException) RestPermissions(org.graylog2.shared.security.RestPermissions) StreamResponse(org.graylog2.rest.resources.streams.responses.StreamResponse) ObjectId(org.bson.types.ObjectId) PUT(javax.ws.rs.PUT) StreamRuleImpl(org.graylog2.streams.StreamRuleImpl) Message(org.graylog2.plugin.Message) Collections(java.util.Collections) StreamRule(org.graylog2.plugin.streams.StreamRule) BadRequestException(javax.ws.rs.BadRequestException) Stream(org.graylog2.plugin.streams.Stream) URI(java.net.URI) IndexSet(org.graylog2.indexer.IndexSet) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 29 with Context

use of javax.ws.rs.core.Context in project hippo by NHS-digital-website.

the class OrganisationDataResource method getOrg.

@GET
@Path("/")
public List<OdsOrganisation> getOrg(@Context HttpServletRequest request, @Context HttpServletResponse servletResponse, @QueryParam("orgName") String orgName) {
    if (odsResults == null) {
        try {
            log.debug("Loading ODS Data");
            HstRequestContext context = new DefaultRestContext(this, request).getRequestContext();
            QueryManager manager = context.getSession().getWorkspace().getQueryManager();
            Query jcrQuery = manager.createQuery("/jcr:root/content/assets//*[@jcr:primaryType='externalstorage:resource']", "xpath");
            QueryResult execute = jcrQuery.execute();
            NodeIterator iterator = execute.getNodes();
            while (iterator.hasNext()) {
                Node node = iterator.nextNode();
                if (node.getPath().contains("/content/assets/ODS_Data")) {
                    Value val = node.getProperty("jcr:data").getValue();
                    // convert JSON array to Java List
                    odsResults = new ObjectMapper().readValue(val.getString().replace("\n", ""), new TypeReference<List<OdsOrganisation>>() {
                    });
                    break;
                }
            }
        } catch (RepositoryException | JsonProcessingException e) {
            log.debug("Failed to load ODS Data ", e);
        }
    }
    List<OdsOrganisation> filterOrg = odsResults.stream().filter(b -> (b.getOrgName() + " " + b.getCode()).toUpperCase().contains(orgName.toUpperCase())).collect(Collectors.toList());
    return filterOrg;
}
Also used : DefaultRestContext(org.onehippo.cms7.essentials.components.rest.ctx.DefaultRestContext) NodeIterator(javax.jcr.NodeIterator) Query(javax.jcr.query.Query) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) Logger(org.slf4j.Logger) OdsOrganisation(uk.nhs.digital.model.OdsOrganisation) Context(javax.ws.rs.core.Context) QueryManager(javax.jcr.query.QueryManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) QueryResult(javax.jcr.query.QueryResult) Collectors(java.util.stream.Collectors) BaseRestResource(org.onehippo.cms7.essentials.components.rest.BaseRestResource) DefaultRestContext(org.onehippo.cms7.essentials.components.rest.ctx.DefaultRestContext) List(java.util.List) HttpServletRequest(javax.servlet.http.HttpServletRequest) MediaType(javax.ws.rs.core.MediaType) Value(javax.jcr.Value) RepositoryException(javax.jcr.RepositoryException) javax.ws.rs(javax.ws.rs) Node(javax.jcr.Node) TypeReference(com.fasterxml.jackson.core.type.TypeReference) NodeIterator(javax.jcr.NodeIterator) Query(javax.jcr.query.Query) Node(javax.jcr.Node) OdsOrganisation(uk.nhs.digital.model.OdsOrganisation) RepositoryException(javax.jcr.RepositoryException) QueryResult(javax.jcr.query.QueryResult) QueryManager(javax.jcr.query.QueryManager) Value(javax.jcr.Value) TypeReference(com.fasterxml.jackson.core.type.TypeReference) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 30 with Context

use of javax.ws.rs.core.Context in project Summer by yale8848.

the class MethodsProcessor method get.

public static ClassInfo get(List<ClassInfo> classInfos, Class clazz) {
    Path path = (Path) clazz.getAnnotation(Path.class);
    if (path == null || path.value() == null) {
        return null;
    }
    ClassInfo classInfo = new ClassInfo();
    classInfo.setClassPath(path.value());
    classInfo.setClazzObj(newClass(clazz));
    classInfo.setClazz(clazz);
    Interceptor[] interceptorsClazz = getBefores((Before) clazz.getAnnotation(Before.class));
    if (interceptorsClazz != null) {
        classInfo.setBefores(interceptorsClazz);
    }
    interceptorsClazz = getAfters((After) clazz.getAnnotation(After.class));
    if (interceptorsClazz != null) {
        classInfo.setAfters(interceptorsClazz);
    }
    for (Method method : clazz.getMethods()) {
        Class mt = method.getDeclaringClass();
        if (mt == Object.class) {
            continue;
        }
        MethodInfo methodInfo = new MethodInfo();
        Interceptor[] interceptorsMethod = getBefores((Before) method.getAnnotation(Before.class));
        if (interceptorsMethod != null) {
            methodInfo.setBefores(interceptorsMethod);
        }
        interceptorsMethod = getAfters((After) method.getAnnotation(After.class));
        if (interceptorsMethod != null) {
            methodInfo.setAfters(interceptorsMethod);
        }
        Blocking blocking = method.getAnnotation(Blocking.class);
        if (blocking != null) {
            methodInfo.setBlocking(true);
        }
        Path pathMthod = (Path) method.getAnnotation(Path.class);
        Produces produces = (Produces) method.getAnnotation(Produces.class);
        methodInfo.setMethodPath(getPathValue(pathMthod));
        methodInfo.setProducesType(getProducesValue(produces));
        methodInfo.setHttpMethod(getHttpMethod(method));
        methodInfo.setMethod(method);
        Parameter[] parameters = method.getParameters();
        Class<?>[] parameterTypes = method.getParameterTypes();
        Annotation[][] annotations = method.getParameterAnnotations();
        int i = 0;
        for (Annotation[] an : annotations) {
            ArgInfo argInfo = new ArgInfo();
            argInfo.setAnnotation(an);
            argInfo.setClazz(parameterTypes[i]);
            argInfo.setParameter(parameters[i]);
            for (Annotation ant : an) {
                if (ant instanceof Context) {
                    argInfo.setContext(true);
                } else if (ant instanceof DefaultValue) {
                    argInfo.setDefaultValue(((DefaultValue) ant).value());
                } else if (ant instanceof PathParam) {
                    argInfo.setPathParam(true);
                    argInfo.setPathParam(((PathParam) ant).value());
                } else if (ant instanceof QueryParam) {
                    argInfo.setQueryParam(true);
                    argInfo.setQueryParam(((QueryParam) ant).value());
                } else if (ant instanceof FormParam) {
                    argInfo.setFormParam(true);
                    argInfo.setFormParam(((FormParam) ant).value());
                }
            }
            i++;
            methodInfo.addArgInfo(argInfo);
        }
        classInfo.addMethodInfo(methodInfo);
    }
    classInfos.add(classInfo);
    return classInfo;
}
Also used : Context(javax.ws.rs.core.Context) Blocking(ren.yale.java.annotation.Blocking) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) ArgInfo(ren.yale.java.method.ArgInfo) After(ren.yale.java.aop.After) Parameter(java.lang.reflect.Parameter) MethodInfo(ren.yale.java.method.MethodInfo) Interceptor(ren.yale.java.interceptor.Interceptor) ClassInfo(ren.yale.java.method.ClassInfo)

Aggregations

Context (javax.ws.rs.core.Context)70 Response (javax.ws.rs.core.Response)51 Path (javax.ws.rs.Path)48 PathParam (javax.ws.rs.PathParam)41 GET (javax.ws.rs.GET)39 List (java.util.List)38 MediaType (javax.ws.rs.core.MediaType)36 POST (javax.ws.rs.POST)34 UriInfo (javax.ws.rs.core.UriInfo)32 Produces (javax.ws.rs.Produces)30 PUT (javax.ws.rs.PUT)29 Inject (javax.inject.Inject)27 HttpServletRequest (javax.servlet.http.HttpServletRequest)27 QueryParam (javax.ws.rs.QueryParam)27 Map (java.util.Map)25 IOException (java.io.IOException)24 Api (io.swagger.annotations.Api)23 ApiOperation (io.swagger.annotations.ApiOperation)23 ApiParam (io.swagger.annotations.ApiParam)23 URI (java.net.URI)23