Java Code Examples for javax.ws.rs.Path#value()

The following examples show how to use javax.ws.rs.Path#value() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestRsRouteInitializer.java    From vxms with Apache License 2.0 6 votes vote down vote up
private static void initHttpDelete(
        VxmsShared vxmsShared,
        Router router,
        Object service,
        Method restMethod,
        Path path,
        Stream<Method> errorMethodStream,
        Optional<Consumes> consumes) {
    final Route route = router.delete(URIUtil.cleanPath(path.value()));
    final Context context = getContext(vxmsShared);
    final String methodId =
            path.value()
                    + DELETE.class.getName()
                    + ConfigurationUtil.getCircuitBreakerIDPostfix(context.config());
    initHttpOperation(
            methodId,
            vxmsShared,
            service,
            restMethod,
            route,
            errorMethodStream,
            consumes,
            DELETE.class);
}
 
Example 2
Source File: RestRsRouteInitializer.java    From vxms with Apache License 2.0 6 votes vote down vote up
protected static void initHttpGet(
        VxmsShared vxmsShared,
        Router router,
        Object service,
        Method restMethod,
        Path path,
        Stream<Method> errorMethodStream,
        Optional<Consumes> consumes) {
    final Route route = router.get(URIUtil.cleanPath(path.value()));
    final Context context = getContext(vxmsShared);
    final String methodId =
            path.value()
                    + GET.class.getName()
                    + ConfigurationUtil.getCircuitBreakerIDPostfix(context.config());
    initHttpOperation(
            methodId, vxmsShared, service, restMethod, route, errorMethodStream, consumes, GET.class);
}
 
Example 3
Source File: RestRsRouteInitializer.java    From vxms with Apache License 2.0 6 votes vote down vote up
private static void initHttpPut(
        VxmsShared vxmsShared,
        Router router,
        Object service,
        Method restMethod,
        Path path,
        Stream<Method> errorMethodStream,
        Optional<Consumes> consumes) {
    final Route route = router.put(URIUtil.cleanPath(path.value()));
    final Context context = getContext(vxmsShared);
    final String methodId =
            path.value()
                    + PUT.class.getName()
                    + ConfigurationUtil.getCircuitBreakerIDPostfix(context.config());
    initHttpOperation(
            methodId, vxmsShared, service, restMethod, route, errorMethodStream, consumes, PUT.class);
}
 
Example 4
Source File: MdwScanner.java    From mdw with Apache License 2.0 6 votes vote down vote up
private boolean isMatch(Class<? extends TextService> serviceClass, String servicePath) {
    if ("/".equals(servicePath)) {
        return true;
    }
    else {
        String path = serviceClass.getName().replace('.', '/');
        Path pathAnnotation = serviceClass.getAnnotation(Path.class);
        if (pathAnnotation != null) {
            path = serviceClass.getPackage().getName().replace('.', '/');
            if (!pathAnnotation.value().startsWith("/"))
                path += "/";
            if (!pathAnnotation.value().equals("/"))
                path += pathAnnotation.value();
        }
        if (path.equals(servicePath) || ("/" + path).equals(servicePath)) {
            return true;
        }
        else if (servicePath.contains("/{") && servicePath.endsWith("}")) {
            // parameterized -- matches if all remaining path segments are parameterized
            String nonparam = servicePath.substring(0, servicePath.indexOf("/{"));
            if (path.equals(nonparam) || ("/" + path).equals(nonparam))
                return true;
        }
    }
    return false;
}
 
Example 5
Source File: OpenTracingHTTPPathNameTests.java    From microprofile-opentracing with Apache License 2.0 6 votes vote down vote up
@Override
protected String getOperationName(String spanKind, String httpMethod, Class<?> clazz, Method method) {
    if (spanKind.equals(Tags.SPAN_KIND_SERVER)) {
        StringBuilder operationName = new StringBuilder(httpMethod.toUpperCase() + ":");
        Path classPath = clazz.getAnnotation(Path.class);
        if (classPath == null) {
            throw new IllegalArgumentException("Supplied clazz is not JAX-RS resource");
        }
        if (!classPath.value().startsWith("/")) {
            operationName.append("/");
        }
        operationName.append(classPath.value());
        if (!classPath.value().endsWith("/")) {
            operationName.append("/");
        }
        Path methodPath = method.getAnnotation(Path.class);
        String methodPathStr = methodPath.value();
        if (methodPathStr.startsWith("/")) {
            methodPathStr = methodPathStr.replaceFirst("/", "");
        }
        operationName.append(methodPathStr);
        return operationName.toString();
    }
    return super.getOperationName(spanKind, httpMethod, clazz, method);
}
 
Example 6
Source File: WebSocketServlet.java    From icure-backend with GNU General Public License v2.0 5 votes vote down vote up
private void scanBeanMethods(Object bean, Map<String, WebSocketInvocation> methods) {
	Class clazz = bean.getClass();
	Path annotation = (Path) clazz.getAnnotation(Path.class);

	if (annotation!=null) {
		String basePath = annotation.value();
		Arrays.stream(clazz.getMethods()).filter(m -> m.getAnnotation(WebSocketOperation.class) != null).forEach(m ->
				methods.put((basePath + "/" + m.getAnnotation(Path.class).value()).replaceAll("//", "/"), new WebSocketInvocation(m.getAnnotation(WebSocketOperation.class).adapterClass(), bean, m))
		);
	}
}
 
Example 7
Source File: RestRsRouteInitializer.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static void initHttpAll(
        VxmsShared vxmsShared,
        Router router,
        Object service,
        Method restMethod,
        Path path,
        Stream<Method> errorMethodStream,
        Optional<Consumes> consumes) {
    final Optional<Method> errorMethod = errorMethodStream.findFirst();
    final Route route = router.route(URIUtil.cleanPath(path.value()));
    final Context context = getContext(vxmsShared);
    final String methodId =
            path.value() + HTTP_ALL + ConfigurationUtil.getCircuitBreakerIDPostfix(context.config());
    initHttpRoute(methodId, vxmsShared, service, restMethod, consumes, errorMethod, route);
}
 
Example 8
Source File: ServletService.java    From Web-API with MIT License 5 votes vote down vote up
/**
 * Register a servlet with the WebAPI, which will give it a separate base address
 * @param servlet The class of servlet to register. The WebAPI will create an instance when starting. Make
 *                sure to provide an empty constructor.
 */
public void registerServlet(Class<? extends BaseServlet> servlet) {
    Logger logger = WebAPI.getLogger();

    if (!servlet.isAnnotationPresent(Path.class)) {
        logger.error("Servlet " + servlet.getName() + " is missing @Path annotation");
        return;
    }

    Path info = servlet.getAnnotation(Path.class);
    String basePath = info.value();
    if (basePath.endsWith("/"))
        basePath = basePath.substring(0, basePath.length() - 1);
    if (!basePath.startsWith("/"))
        basePath = "/" + basePath;

    try {
        Method m = servlet.getMethod("onRegister");
        m.invoke(null);
    } catch (NoSuchMethodException ignored) {
    } catch (IllegalAccessException | InvocationTargetException e) {
        e.printStackTrace();
        WebAPI.sentryCapture(e);
    }

    servletClasses.put(basePath, servlet);
}
 
Example 9
Source File: OperationNameProvider.java    From java-jaxrs with Apache License 2.0 5 votes vote down vote up
private static String extractPath(AnnotatedElement element) {
  Path path = element.getAnnotation(Path.class);
  if (path != null) {
    return path.value();
  }
  return null;
}
 
Example 10
Source File: ResourceMethodParser.java    From jweb-cms with GNU Affero General Public License v3.0 5 votes vote down vote up
public ResourceMethodParser(Class<?> controllerClass, AbstractModule module) {
    this.module = module;
    this.controllerClass = controllerClass;

    Path path = controllerClass.getDeclaredAnnotation(Path.class);
    if (path == null) {
        throw new ApplicationException("missing @Path, type={}", controllerClass);
    }
    rootPath = path.value();
}
 
Example 11
Source File: EndpointMetricsFilter.java    From syndesis with Apache License 2.0 4 votes vote down vote up
private String getResourceMethodPath() {
    Path methodPath = resourceInfo.getResourceMethod().getAnnotation(Path.class);
    return methodPath != null ? methodPath.value() : "";
}
 
Example 12
Source File: PayloadBuilder.java    From emodb with Apache License 2.0 4 votes vote down vote up
private String getPath(Class<?> resourceType) {
    Path path = resourceType.getAnnotation(Path.class);
    checkNotNull(path, "The resource %s is not annotated with @Path", resourceType.getName());
    return path.value();
}
 
Example 13
Source File: EndpointMetricsFilter.java    From syndesis with Apache License 2.0 4 votes vote down vote up
private String getResourceClassPath() {
    Path classPath = resourceInfo.getResourceClass().getAnnotation(Path.class);
    return classPath != null ? classPath.value() : "";
}
 
Example 14
Source File: EndpointMetricsFilter.java    From syndesis with Apache License 2.0 4 votes vote down vote up
private String getResourceMethodPath() {
    Path methodPath = resourceInfo.getResourceMethod().getAnnotation(Path.class);
    return methodPath != null ? methodPath.value() : "";
}
 
Example 15
Source File: ResourceReaderExtension.java    From mdw with Apache License 2.0 4 votes vote down vote up
@Override
public String getPath(ReaderContext context, Method method) {
    String p = null;
    Api apiAnnotation = context.getCls().getAnnotation(Api.class);
    ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class);
    String operationPath = apiOperation == null ? null : apiOperation.nickname();
    if (operationPath != null && !operationPath.isEmpty()) {
        // same logic as ServletReaderExtension
        p = PathUtils.collectPath(context.getParentPath(),
                apiAnnotation == null ? null : apiAnnotation.value(), operationPath);
    }
    else {
        // try JAX-RS annotations
        Path parentPath = ReflectionUtils.getAnnotation(method.getDeclaringClass(), Path.class);
        if (parentPath != null && parentPath.value() != null && !parentPath.value().isEmpty()) {
            p = parentPath.value();
        }
        Path path = ReflectionUtils.getAnnotation(method, Path.class);
        if (path != null && path.value() != null && !path.value().isEmpty()) {
            if (p == null)
                p = path.value();
            else {
                if (path.value().startsWith("/"))
                    p += path.value();
                else
                    p = p + "/" + path.value();
            }
        }
        // check dynamic java, which has package-based pathing
        java.lang.Package pkg = method.getDeclaringClass().getPackage();
        if (p != null && "MDW".equals(pkg.getImplementationTitle())) {
            if (p.startsWith("/"))
                p = "/" + pkg.getName().replace('.', '/') + p;
            else
                p = "/" + pkg.getName().replace('.', '/') + "/" + p;
        }

        if (apiOperation != null) {
            ApiImplicitParams implicitParams = ReflectionUtils.getAnnotation(method, ApiImplicitParams.class);
            if (implicitParams != null && implicitParams.value() != null && implicitParams.value().length == 1) {
                ApiImplicitParam implicitParam = implicitParams.value()[0];
                if (implicitParam.name() != null && !"body".equals(implicitParam.paramType()) && !"query".equals(implicitParam.paramType()) && !"header".equals(implicitParam.paramType()) && !"form".equals(implicitParam.paramType()))
                    p += "/{" + implicitParam.name() + "}";
            }
        }
    }

    return p;
}
 
Example 16
Source File: EndpointMetricsFilter.java    From syndesis with Apache License 2.0 4 votes vote down vote up
private String getResourceClassPath() {
    Path classPath = resourceInfo.getResourceClass().getAnnotation(Path.class);
    return classPath != null ? classPath.value() : "";
}
 
Example 17
Source File: NotFoundExceptionMapper.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public static List<ResourceDescription> fromBoundResourceInvokers(
        Set<Map.Entry<String, List<ResourceInvoker>>> bound) {
    Map<String, ResourceDescription> descriptions = new HashMap<>();

    for (Map.Entry<String, List<ResourceInvoker>> entry : bound) {
        for (ResourceInvoker invoker : entry.getValue()) {
            // skip those for now
            if (!(invoker instanceof ResourceMethodInvoker)) {
                continue;
            }
            ResourceMethodInvoker method = (ResourceMethodInvoker) invoker;
            Class<?> resourceClass = method.getResourceClass();
            String resourceClassName = resourceClass.getName();
            String basePath = null;
            NonJaxRsClassMappings nonJaxRsClassMappings = null;
            Path path = resourceClass.getAnnotation(Path.class);
            if (path == null) {
                nonJaxRsClassMappings = nonJaxRsClassNameToMethodPaths.get(resourceClassName);
                if (nonJaxRsClassMappings != null) {
                    basePath = nonJaxRsClassMappings.getBasePath();
                }
            } else {
                basePath = path.value();
            }

            if (basePath == null) {
                continue;
            }

            if (!descriptions.containsKey(basePath)) {
                descriptions.put(basePath, new ResourceDescription(basePath));
            }

            String subPath = "";
            for (Annotation annotation : method.getMethodAnnotations()) {
                if (annotation.annotationType().equals(Path.class)) {
                    subPath = ((Path) annotation).value();
                    break;
                }
            }
            // attempt to find a mapping in the non JAX-RS paths
            if (subPath.isEmpty() && (nonJaxRsClassMappings != null)) {
                String methodName = method.getMethod().getName();
                String subPathFromMethodName = nonJaxRsClassMappings.getMethodNameToPath().get(methodName);
                if (subPathFromMethodName != null) {
                    subPath = subPathFromMethodName;
                }
            }

            descriptions.get(basePath).addMethod(basePath + subPath, method);
        }
    }

    return new LinkedList<>(descriptions.values());
}
 
Example 18
Source File: BaseRsService.java    From govpay with GNU General Public License v3.0 4 votes vote down vote up
private String getPathFromRestMethod(String methodName) {

        try {
        	Class<?> c = this.getClass();
        	// la versione V1 non implementa interfacce
//        	Class<?> [] interfaces = c.getInterfaces();
//        	if(interfaces==null || interfaces.length<=0) {
//        		return null;
//        	}
//        	Class<?> cInterface = null;
//        	for (int i = 0; i < interfaces.length; i++) {
//        		if (interfaces[i] != null && interfaces[i].isAnnotationPresent(Path.class)) {
//        			cInterface = interfaces[i];
//        			break;
//        		}
//			}
//        	if(cInterface==null) {
//        		return null;
//        	}
//        	Method [] methods = cInterface.getMethods();
        	
        	String rsBasePathValue = "";
        	Path rsBasePath = c.getAnnotation(Path.class);
        	if(rsBasePath !=null) {
        		rsBasePathValue = rsBasePath.value();
        	}
        	
        	Method [] methods = c.getMethods();
        	if(methods==null || methods.length<=0) {
        		return null;
        	}
        	Method method = null;
        	for (int i = 0; i < methods.length; i++) {
        		if (methods[i] != null && methods[i].getName().equals(methodName) && methods[i].isAnnotationPresent(Path.class)) {
        			method = methods[i];
        			break;
        		}
			}
        	if(method==null) {
        		return null;
        	}
        	Path path = method.getAnnotation(Path.class);
        	if(path==null) {
        		return null;
        	}
        	return rsBasePathValue + path.value();
        } catch (Exception e) {
            this.log.error(e.getMessage(),e);
        }

        return null;
    }
 
Example 19
Source File: DefaultResourceNameParser.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
@Override
public String parse(ContainerRequestContext containerRequestContext, ResourceInfo resourceInfo) {
    Path classPath = resourceInfo.getResourceClass().getAnnotation(Path.class);
    Path methodPath = resourceInfo.getResourceMethod().getAnnotation(Path.class);
    return containerRequestContext.getRequest().getMethod() + ":" + (classPath != null ? classPath.value() : "") + (methodPath != null ? methodPath.value() : "");
}
 
Example 20
Source File: ReactorGuiceServer.java    From reactor-guice with Apache License 2.0 4 votes vote down vote up
private Consumer<HttpServerRoutes> routesBuilder() {
    // routes
    return routes -> {
        for (String className : classNames) {
            if (injector == null) {
                continue;
            }
            Object handleObject;
            Class<?> handleClass;
            try {
                handleClass = Class.forName(className);
                if (handleClass.isInterface()) {
                    continue;
                }
            }
            catch(ClassNotFoundException e) {
                continue;
            }
            // 拿到根路径
            Path pathAnnotation = handleClass.getAnnotation(Path.class);
            String rootPath = (pathAnnotation == null) ? "" : pathAnnotation.value();
            // if websocket
            if (AbstractWebSocketServerHandle.class.isAssignableFrom(handleClass) && pathAnnotation != null) {
                handleObject = injector.getInstance(handleClass);
                System.out.println("    WS " + rootPath + " → " + className);
                routes.get(rootPath, (req, resp) -> httpPublisher(req, resp, null, o ->
                        websocketPublisher.sendMessage(req, resp, (WebSocketServerHandle) handleObject, o)
                ));
                continue;
            }
            // if is not controller
            if (!handleClass.isAnnotationPresent(Controller.class)) {
                continue;
            }
            handleObject = injector.getInstance(handleClass);
            // methods for handle
            Method[] handleMethods = handleClass.getMethods();
            // loop methods
            for (Method method : handleMethods) {
                // if have request path
                if (method.isAnnotationPresent(Path.class)) {
                    String requestPath = rootPath + method.getAnnotation(Path.class).value();
                    // GET
                    if (method.isAnnotationPresent(GET.class)) {
                        System.out.println("   GET " + requestPath + " → " + className + ":" + method.getName());
                        routes.get(requestPath, (req, resp) -> httpPublisher(req, resp, method, o ->
                            handlePublisher.sendResult(req, resp, method, handleObject, o)
                        ));
                    }
                    // POST
                    else if (method.isAnnotationPresent(POST.class)) {
                        System.out.println("  POST " + requestPath + " → " + className + ":" + method.getName());
                        routes.post(requestPath, (req, resp) -> httpPublisher(req, resp, method, o ->
                            handlePublisher.sendResult(req, resp, method, handleObject, o)
                        ));
                    }
                    // DELETE
                    else if (method.isAnnotationPresent(DELETE.class)) {
                        System.out.println("DELETE " + requestPath + " → " + className + ":" + method.getName());
                        routes.delete(requestPath, (req, resp) -> httpPublisher(req, resp, method, o ->
                            handlePublisher.sendResult(req, resp, method, handleObject, o)
                        ));
                    }
                    // UPDATE
                    else if (method.isAnnotationPresent(PUT.class)) {
                        System.out.println("   PUT " + requestPath + " → " + className + ":" + method.getName());
                        routes.put(requestPath, (req, resp) -> httpPublisher(req, resp, method, o ->
                            handlePublisher.sendResult(req, resp, method, handleObject, o)
                        ));
                    }
                    if (crossOrigin) {
                        // OPTION
                        routes.options(requestPath, (req, resp) -> httpPublisher(req, resp, method, o -> Mono.empty()));
                    }
                }
            }
        }

        // is is api gateway server
        if (this.apiGatewayDispatcher!=null) {
            ApiGatewayPublisher apiGatewayPublisher = new ApiGatewayPublisher(this.apiGatewayDispatcher);
            System.out.println("   Any /** →  /** <api gateway model>");
            routes.route(apiGatewayPublisher::checkRequest, (req, resp) -> httpPublisher(req, resp, null, o ->
                apiGatewayPublisher.sendResponse(req, resp, websocketPublisher, o)
            ));
        }
        // static server
        else {
            System.out.println("   GET /** →  /public/* <static files>");
            routes.route(req->true, (req, resp) -> httpPublisher(req, resp, null, o ->
                staticFilePublisher.sendFile(req, resp)
            ));
        }
    };
}