球衣和jax-rs RI2-缺少HttpServerFactory [英] jersey and jax-rs RI2 - missing HttpServerFactory
问题描述
我有一个简单的项目来测试JAX-RS服务.昨天我下载了jersey-1.7.1,并使用com.sun.jersey.api.container.httpserver.HttpServerFactory和com.sun.net.httpserver.HttpServer创建了一个http服务器来从eclipse内部测试我的服务(不使用oa重量容器)
I have a simple project to test JAX-RS services. Yesterday I downloaded jersey-1.7.1 and used com.sun.jersey.api.container.httpserver.HttpServerFactory and com.sun.net.httpserver.HttpServer to create a http server to test my services from inside eclipse (w/o a heavy weight container)
今天,我下载了最新的球衣罐(jaxrs-ri),并且缺少HttpServerFactory.看起来他们删除了1.7.1 => 2.0之间的类,但是我在不赞成的部分中找不到它.我在API部分中看到了grizzly2类(也许那是我现在应该使用的类),但是jaxrs-ri捆绑包中的jar都没有提供这些类.我下载了jersey-grizzly 1.12 jar,但它只有com/sun/jersey/server/impl/container/grizzly2/GrizzlyContainer类,没有实现.
Today, I downloaded the latest jersey jars (jaxrs-ri) and the HttpServerFactory is missing. Looks like they removed the class between 1.7.1 => 2.0 but I cannot find it in deprecated section. I see grizzly2 classes in API section (maybe that is what I am supposed to use now) but none of the jars in jaxrs-ri bundle provide those classes. I downloaded the jersey-grizzly 1.12 jar but it only has com/sun/jersey/server/impl/container/grizzly2/GrizzlyContainer classes and no implementation.
对灵魂友善的问题
1-使用jersey下载页面上的最新jaxrs-ri jars,建议一种创建简单http服务器以从命令行进行测试(如果1.7.1方法已被弃用)的方法. 要下载/包含哪些罐子,也许还有一个简短的代码示例?
1 - with the latest jaxrs-ri jars from jersey download page, what is the recommended way to create a simple http server to test from command line if the 1.7.1 way has been deprecated. what jars to download/include and perhaps a short code sample?
2-有关使用java创建简单REST服务的整个文档非常混乱.那么,您如何找到正确的信息呢?
2 - The whole documentation around creating a simple REST service using java is a big mess. So how do you find the right information?
(真的,这不是在开玩笑.也许这需要一个单独的博客文章-仅查看混乱情况,更改的API,没有有关过时功能的信息,实现差异,例如CXF与jersey,API 1.x与API 2.0,Glassfish容器v xy与Tomcat,y的x版本与y的x2版本,servlet 3.0都有此文件,无论您是否扩展应用程序!)
(Really, this is not a joke. maybe this would require a separate blog post - just look at the mess, changed API, no information on deprecated features, implementation diffs, e.g. CXF vs. jersey, API 1.x vs API 2.0, Glassfish container v x.y vs. Tomcat, version x of y vs. version x2 of y, servlet 3.0 would have this file, are you extending Application or not!)
更新
使用JDKHttp服务器的工作示例
working example with JDKHttp server
package test.jersey;
import java.net.URI;
import com.sun.net.httpserver.HttpServer;
import org.glassfish.jersey.jdkhttp.JdkHttpServerFactory ;
import org.glassfish.jersey.server.ResourceConfig;
public class ConsoleServerV2 {
static final String BASE_URI = "http://localhost:9099/";
public static void main(String[] args) throws Exception {
HttpServer server = null ;
ResourceConfig rc = new ResourceConfig(rest.Service.class);
URI endpoint = new URI(BASE_URI);
server = JdkHttpServerFactory.createHttpServer(endpoint,rc);
System.out.println("console v2.0 : Press Enter to stop the server. ");
System.in.read();
server.stop(0);
}
}
推荐答案
您可以使用JdkHttpServerFactory,该软件可在jersey-container-jdk-http-2.0.jar :
You could use the JdkHttpServerFactory, which is available in the jersey-container-jdk-http-2.0.jar:
ResourceConfig rc = new ResourceConfig(HelloWorldResource.class);
HttpServer server = JdkHttpServerFactory.createHttpServer(baseUri, rc);
无需调用server.start()!
No need to call server.start()!
这篇关于球衣和jax-rs RI2-缺少HttpServerFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!