jersey

Very peculiar :HTTP Status 405 - Method Not Allowed

夙愿已清 提交于 2020-03-17 10:16:29
问题 [using Apache Tomcat/7.0.27] It seems I only get this error ( HTTP Status 405 - Method Not Allowed ) when I try to make a REST request directly from the browser. E.g by pasting this in the address bar : http://localhost:8080/restExample/rest/catalog/video/14951/hello When I run my test client Main.java everything works fine. Any ideas as to why it wont let me execute a REST through the browser? Client Side: public class Main{ public static void main(String [] args){ ClientConfig config = new

Meaning of each field in default Format of HTTP Request Log in DropWizard

我怕爱的太早我们不能终老 提交于 2020-03-17 08:58:44
问题 The access log that get generated in Dropwizard are something of following format:- 10.10.10.10 - - [16/Mar/2015:23:59:59 +0530] "GET /yyyy/vx.x/uri HTTP/1.1" 200 - "-" "-" 1 Field 1 :- 10.10.10.10 (Ip Address from which request came) Field 2 :- [16/Mar/2015:23:59:59 +0530] (Time and Date when request came) Field 3 :- "GET /yyyy/vx.x/uri HTTP/1.1" (HTTP Rest API method) Field 4 :- 200 (HTTP Response code) Field 5 :- "-" (????) Field 6 :- "-" (????) Field 7 :- 1 (????) Can someone explain the

Webservice Jersey Test Framework

青春壹個敷衍的年華 提交于 2020-03-13 00:34:27
前言:您的应用程序是否拥有RESTful Web服务?你想确保这些服务是正常工作在一个广泛的容器——无论是重量轻和重的? 你有没有觉得需要一个基础设施的设置,您可以使用它来测试你的服务对所有这些容器,而不必担心诸如部署描述符,等等. I 怎样使用Jersey Test Framework? 要简单的使用框架您也许需要以下几个步骤: 1、添加项目依赖的pom.xml内容 <dependency> <groupId>com.sun.jersey.test.framework</groupId> <artifactId>jersey-test-framework</artifactId> <version>1.0.3</version> <scope>test</scope> </dependency> 2、新建一个Java类并继承 com.sun.jersey.test.framework.JerseyTest 3、通过super调用父类方法为 JerseyTest设置下面标出的一个或多个参数 super(String rootResourcePackage),super(String contextPath, String servletPath, String resourcePackageName),super(). 4、添加测试类的 org.junit.Test

Jersey

泄露秘密 提交于 2020-03-12 22:44:01
Developing RESTful Web services that seamlessly support exposing your data in a variety of representation media types and abstract away the low-level details of the client-server communication is not an easy task without a good toolkit. In order to simplify development of RESTful Web services and their clients in Java, a standard and portable JAX-RS API has been designed. Jersey RESTful Web Services framework is open source, production quality, framework for developing RESTful Web Services in Java that provides support for JAX-RS APIs and serves as a JAX-RS (JSR 311 & JSR 339) Reference

Configure Response object for Rest Services inside a Jersey-Grizzly server, in OSGi container (CORS error prevention with Jersey 1x)

不问归期 提交于 2020-03-05 11:49:16
问题 The last couple of days, I have been struggling with an issue. I've created a rest service hosted by a Grizzly server inside an OSGi container. Everything is working perfectly at this point. Now, I want to add a header in every response.Not so complex or illogical right? Yet, I can't find a way to do it. I have tried to: 1) Get the response object inside the rest functions as this question suggests (pretty textbook when you are not under OSGi). 2) Add a handler using the code above (in this

Configure Response object for Rest Services inside a Jersey-Grizzly server, in OSGi container (CORS error prevention with Jersey 1x)

假如想象 提交于 2020-03-05 11:48:50
问题 The last couple of days, I have been struggling with an issue. I've created a rest service hosted by a Grizzly server inside an OSGi container. Everything is working perfectly at this point. Now, I want to add a header in every response.Not so complex or illogical right? Yet, I can't find a way to do it. I have tried to: 1) Get the response object inside the rest functions as this question suggests (pretty textbook when you are not under OSGi). 2) Add a handler using the code above (in this

Apache Jersey POST not working when posting JSON

丶灬走出姿态 提交于 2020-03-05 11:46:39
问题 I am using Apache Jersey and trying to POST valid JSON data to the service and it was giving me HTTP 415 error. So with the help of following links I was able to fix this error. Stack Overflow issue for the same error Basically I added some dependencies in pom.xml and some init-params in web.xml explained here This is in answer for above question My method signature @POST @Produces(MediaType.APPLICATION_JSON) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response

0226 rest接口设计

℡╲_俬逩灬. 提交于 2020-02-28 01:56:42
背景 为了更方便的书写和阐述问题,文章中按照第一人称的角度书写。作为一个以java为主要开发语言的工程师,我所描述的都是java相关的编码和设计。 工程师的静态输出就是代码和文档,动态的就是各种应用程序(app,h5站点,微信公众号,小程序)。动态的先不讨论,主要讨论静态的。 随意查看一个代码库,可以看到代码的编写过程,某些代码可能在现在看来实现很低效和可笑,但是在当时的技术和时间场景下,肯定是最优的输出。 也可以在gitlab上看看每次的pull request ,看看当时对这些代码的codeReview ; 反馈出的问题就是程序的设计非常重要。而接口是功能的抽象,相对比较稳定,对团队来说影响比较大。 ** API设计原则 先给接口来个简单的定义:即协议,约定了请求和响应的参数和格式。 接口设计要求是:<br />1.简洁;<br />2.考虑到向后兼容; 业界有一些基本的原则: 1 restfull restfull是一种设计风格,一切接口皆是资源。<br /> <br />目前是设计的主流,思想也非常先进。<br /> 2 参数结构化 请求和响应中的参数要结构化,好处是易读易用。 3 安全 <br />这个怎么重要都不为过,接口设计必须考虑认证和授权,保证特定的人只能访问特定的资源。<br /> <br />同时需要注意在日志中不能含有用户和系统的敏感信息。<br /> 4

jersey and jax-rs RI2 - missing HttpServerFactory

眉间皱痕 提交于 2020-02-26 08:11:10
问题 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) 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

Spring application without web.xml log4j configuration

谁都会走 提交于 2020-02-22 07:51:06
问题 I have a Spring + Jersey web application that I'm migrating from a web.xml to annotation base configuration. I'm implementing WebApplicationInitializer and everything works except log4j, because I have a custom file name. In the web.xml I had <context-param> <param-name>log4jConfiguration</param-name> <param-value>/WEB-INF/custom-name-log4j.xml</param-value> </context-param> This worked. Now, I tried to do the same in Java: container.setInitParameter("log4jConfiguration", "/WEB-INF/custom