Search in sources :

Example 6 with HttpMethod

use of javax.ws.rs.HttpMethod in project feign by OpenFeign.

the class JAXRSContract method processAnnotationOnMethod.

@Override
protected void processAnnotationOnMethod(MethodMetadata data, Annotation methodAnnotation, Method method) {
    Class<? extends Annotation> annotationType = methodAnnotation.annotationType();
    HttpMethod http = annotationType.getAnnotation(HttpMethod.class);
    if (http != null) {
        checkState(data.template().method() == null, "Method %s contains multiple HTTP methods. Found: %s and %s", method.getName(), data.template().method(), http.value());
        data.template().method(http.value());
    } else if (annotationType == Path.class) {
        String pathValue = emptyToNull(Path.class.cast(methodAnnotation).value());
        checkState(pathValue != null, "Path.value() was empty on method %s", method.getName());
        String methodAnnotationValue = Path.class.cast(methodAnnotation).value();
        if (!methodAnnotationValue.startsWith("/") && !data.template().url().endsWith("/")) {
            methodAnnotationValue = "/" + methodAnnotationValue;
        }
        // jax-rs allows whitespace around the param name, as well as an optional regex. The contract should
        // strip these out appropriately.
        methodAnnotationValue = methodAnnotationValue.replaceAll("\\{\\s*(.+?)\\s*(:.+?)?\\}", "\\{$1\\}");
        data.template().append(methodAnnotationValue);
    } else if (annotationType == Produces.class) {
        handleProducesAnnotation(data, (Produces) methodAnnotation, "method " + method.getName());
    } else if (annotationType == Consumes.class) {
        handleConsumesAnnotation(data, (Consumes) methodAnnotation, "method " + method.getName());
    }
}
Also used : Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) HttpMethod(javax.ws.rs.HttpMethod)

Example 7 with HttpMethod

use of javax.ws.rs.HttpMethod in project java-chassis by ServiceComb.

the class HttpMethodAnnotationProcessor method process.

@Override
public void process(Object annotation, OperationGenerator operationGenerator) {
    Annotation httpMethodAnnotation = (Annotation) annotation;
    HttpMethod httpMethod = httpMethodAnnotation.annotationType().getAnnotation(HttpMethod.class);
    operationGenerator.setHttpMethod(httpMethod.value());
}
Also used : Annotation(java.lang.annotation.Annotation) HttpMethod(javax.ws.rs.HttpMethod)

Example 8 with HttpMethod

use of javax.ws.rs.HttpMethod in project incubator-servicecomb-java-chassis by apache.

the class HttpMethodAnnotationProcessor method process.

@Override
public void process(Object annotation, OperationGenerator operationGenerator) {
    Annotation httpMethodAnnotation = (Annotation) annotation;
    HttpMethod httpMethod = httpMethodAnnotation.annotationType().getAnnotation(HttpMethod.class);
    operationGenerator.setHttpMethod(httpMethod.value());
}
Also used : Annotation(java.lang.annotation.Annotation) HttpMethod(javax.ws.rs.HttpMethod)

Example 9 with HttpMethod

use of javax.ws.rs.HttpMethod in project jocean-http by isdom.

the class WSRSHttpMethodTestCase method testHttpMethodValue.

@Test
public final void testHttpMethodValue() {
    final HttpMethod method = POST.class.getAnnotation(HttpMethod.class);
    assertEquals("POST", method.value());
}
Also used : HttpMethod(javax.ws.rs.HttpMethod) Test(org.junit.Test)

Example 10 with HttpMethod

use of javax.ws.rs.HttpMethod in project opencast by opencast.

the class Activator method writeServiceDocumentation.

private void writeServiceDocumentation(final String docPath, HttpServletRequest req, HttpServletResponse resp) throws IOException {
    ServiceReference reference = null;
    for (ServiceReference ref : getRestEndpointServices()) {
        String alias = (String) ref.getProperty(SERVICE_PATH_PROPERTY);
        if (docPath.equalsIgnoreCase(alias)) {
            reference = ref;
            break;
        }
    }
    final StringBuilder docs = new StringBuilder();
    if (reference == null) {
        docs.append("REST docs unavailable for ");
        docs.append(docPath);
    } else {
        final Object restService = bundleContext.getService(reference);
        findRestAnnotation(restService.getClass()).fold(new Option.Match<RestService, Void>() {

            @Override
            public Void some(RestService annotation) {
                globalMacro.put("SERVICE_CLASS_SIMPLE_NAME", restService.getClass().getSimpleName());
                RestDocData data = new RestDocData(annotation.name(), annotation.title(), docPath, annotation.notes(), restService, globalMacro);
                data.setAbstract(annotation.abstractText());
                for (Method m : restService.getClass().getMethods()) {
                    RestQuery rq = (RestQuery) m.getAnnotation(RestQuery.class);
                    String httpMethodString = null;
                    for (Annotation a : m.getAnnotations()) {
                        HttpMethod httpMethod = (HttpMethod) a.annotationType().getAnnotation(HttpMethod.class);
                        if (httpMethod != null) {
                            httpMethodString = httpMethod.value();
                        }
                    }
                    Produces produces = (Produces) m.getAnnotation(Produces.class);
                    Path path = (Path) m.getAnnotation(Path.class);
                    Class<?> returnType = m.getReturnType();
                    if ((rq != null) && (httpMethodString != null) && (path != null)) {
                        data.addEndpoint(rq, returnType, produces, httpMethodString, path);
                    }
                }
                String template = DocUtil.loadTemplate("/ui/restdocs/template.xhtml");
                docs.append(DocUtil.generate(data, template));
                return null;
            }

            @Override
            public Void none() {
                docs.append("No documentation has been found for ").append(restService.getClass().getSimpleName());
                return null;
            }
        });
    }
    resp.setContentType("text/html");
    resp.getWriter().write(docs.toString());
}
Also used : Path(javax.ws.rs.Path) RestDocData(org.opencastproject.runtimeinfo.rest.RestDocData) HttpMethod(javax.ws.rs.HttpMethod) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) ServiceReference(org.osgi.framework.ServiceReference) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery) Option(org.opencastproject.util.data.Option) RestService(org.opencastproject.util.doc.rest.RestService) HttpMethod(javax.ws.rs.HttpMethod)

Aggregations

HttpMethod (javax.ws.rs.HttpMethod)14 Annotation (java.lang.annotation.Annotation)8 Method (java.lang.reflect.Method)7 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)5 Consumes (javax.ws.rs.Consumes)4 Test (org.junit.Test)3 RestQuery (org.opencastproject.util.doc.rest.RestQuery)3 Parameter (java.lang.reflect.Parameter)2 HashMap (java.util.HashMap)2 PathParam (javax.ws.rs.PathParam)2 QueryParam (javax.ws.rs.QueryParam)2 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AnnotatedMethod (com.fasterxml.jackson.databind.introspect.AnnotatedMethod)1 AnnotatedParameter (com.fasterxml.jackson.databind.introspect.AnnotatedParameter)1 Api (io.swagger.annotations.Api)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponse (io.swagger.annotations.ApiResponse)1