Tag: apache wink

restful call MediaType的MediaType格式错误:“*; Q = 0.2”

尝试使用POST方法执行restful Web服务。 这是我的界面的相关部分: @Path(“/customers”) public interface CustomerResource { @POST @Consumes(MediaType.APPLICATION_XML) public Response createCustomer(InputStream is); ….. } 实施: // Create customer public Response createCustomer(InputStream is) { logger.debug(“In createCustomer”); Customer customer = readCustomer(is); customer.setId(idCounter.incrementAndGet()); customerDB.put(customer.getId(), customer); logger.debug(“Created customer ” + customer.getId()); logger.debug(“Out createCustomer”); return Response.created(URI.create(“/customers/” + customer.getId())).build(); } 客户打电话(相关部分) URL postUrl = new URL(“http://localhost:8080/ShoppingApplication/rest/customers”); HttpURLConnection connection = […]

在JAX-RS请求之间共享变量

我认为这是一个关于JAX-RS的一个非常基本的问题,但我不知何故不能轻易找到答案。 我正在尝试重构REST服务,该服务使用“标准”Javax servlet – 手动将请求路由到方法 – 进入“更干净”的JAX-RS实现。 当前应用程序在servlet init()期间设置一些变量。 它将它们分配为HttpServlet类的属性,以便它们在每个doGet()期间可用,并且可以作为参数传递给请求处理方法。 为清楚起见,其中一个是ConcurentHashMap,它充当缓存。 现在,使用JAX-RS,我可以扩展Application来设置我的资源类。 我还可以在每个资源实现中使用@Context注释在处理请求时注入ServletContext之类的东西。 但我不知道如何在应用程序初始化期间类似地注入变量集。 我正在使用JAX-RS的Apache Wink 1.3.0实现。