您可以使用過濾器新澤西州。
public class HTTPFilter implements ContainerRequestFilter {
private static final Logger logger = LoggerFactory.getLogger(HTTPFilter.class);
@Override
public void filter(ContainerRequestContext containerRequestContext) throws IOException {
logger.info(containerRequestContext.getUriInfo().getPath() + " endpoint called...");
//logger.info(containerRequestContext.getUriInfo().getAbsolutePath() + " endpoint called...");
}
}
之後,你必須在http配置文件中註冊它,或者只是擴展ResourceConfig類。這是你可以如何註冊它在http配置類
public class HTTPServer {
public static final Logger logger = LoggerFactory.getLogger(HTTPServer.class);
public static void init() {
URI baseUri = UriBuilder.fromUri("http://localhost/").port(9191).build();
ResourceConfig config = new ResourceConfig(Endpoints.class, HTTPFilter.class);
HttpServer server = JdkHttpServerFactory.createHttpServer(baseUri, config);
logger.info("HTTP Server started");
}
}
意味着你想在這裏創建一個URL?並從你想要得到param1和param2值? – Shamse