jax-rs

Jersey Method not allowed 405

冷暖自知 提交于 2019-12-23 20:01:06
问题 I am new to the rest services. I am trying to create a service that accepts json string from a client. I am getting 405 error when I am calling this service using JQuery. Below is the Java code for ws: @POST @Path("logevent") @Consumes(MediaType.APPLICATION_JSON) public boolean logEvent(String obj) { System.out.println(obj); return true; } and @Path("getdata") @GET public String getData() { return "Hello"; } and jQuery code for posting the JSON is: var json ="{\"userName\":\"testtest\"}"; var

Unmarshal a single element list fails

柔情痞子 提交于 2019-12-23 18:09:51
问题 I'm running a sample (which i can't find anymore) from Blaise Doughans blog on Glassfish 3 using EclipseLink 2.5 MOXy for JAXB service. @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class Company { @XmlElementWrapper(name="employees") @XmlElement(name = "employee", type=Employee.class) private List<Employee> employees; } @XmlAccessorType(XmlAccessType.FIELD) public class Employee { private String id; private String name; } I added some annotations to the classes, to produce the

How can I serve static content from CXF / JAX-RS with my rest API mapped to root context?

半世苍凉 提交于 2019-12-23 18:05:41
问题 I have a rest API using CXF to implement JAX-RS where the REST endpoints are directly on the root context. For example if my root context is localhost:8080/myservice And my endpoints are: localhost:8080/myservice/resource1 localhost:8080/myservice/resource2 But I want to serve static content like this: localhost:8080/myservice/docs/swagger.json In my web.xml I'd like to do something like this: <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet

Feign源码学习

独自空忆成欢 提交于 2019-12-23 17:53:36
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> feign介绍 Feign是一款java的Restful客户端组件,Feign使得 Java HTTP 客户端编写更方便。Feign 灵感来源于Retrofit, JAXRS-2.0和WebSocket。feign在github上有近3K个star,是一款相当优秀的开源组件,虽然相比Retrofit的近30K个star,逊色了太多,但是spring cloud集成了feign,使得feign在java生态中比Retrofit使用的更加广泛。 feign的基本原理是在接口方法上加注解,定义rest请求,构造出接口的动态代理对象,然后通过调用接口方法就可以发送http请求,并且自动解析http响应为方法返回值,极大的简化了客户端调用rest api的代码。官网的示例如下: interface GitHub { @RequestLine("GET /repos/{owner}/{repo}/contributors") List<Contributor> contributors(@Param("owner") String owner, @Param("repo") String repo); } static class Contributor { String login; int contributions;

How can I provide configuration to JAX-RS @Provider annotated ContainerRequestFilter?

假如想象 提交于 2019-12-23 17:42:33
问题 I'm using ContainerRequestFilter filter like this: @NameBinding @Target({TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface SomeFilterAnn {} @SomeFilterAnn @Provider public class SomeFilter implements ContainerRequestFilter { private static final Logger LOG = LoggerFactory.getLogger(SomeFilter.class); @Override public void filter(ContainerRequestContext requestContext) throws IOException { // ... } } It makes possible to bind the filter to rest resources by @SomeFilterAnn

Restful service with CXF and Kerberos authentication

早过忘川 提交于 2019-12-23 17:19:03
问题 Having a hard time trying to protect an existing CXF JAX-RS service with Kerberos authentication. I went through what seems to be the reference documentation : http://cxf.apache.org/docs/jaxrs-kerberos.html but it did not help much. I'm actually trying to configure Tomcat+CXF to reproduce this kind of Apache configuration (which works) : <Directory /var/www/> AuthType Kerberos KrbServiceName HTTP/fqdn@realm Krb5Keytab /path/to/file.keytab Require valid-user </Directory> jaas.conf and krb5

jax-rs ContextResolver<T> undestanding

泪湿孤枕 提交于 2019-12-23 17:17:48
问题 But I was trying to understand the usage of Providers in jax-rs. But was not able to understand how ContextResolver can be used. Can someone explain this with some basic example? 回答1: You will see it being used a lot in resolving a serialization context object. For example an ObjectMapper for JSON serialization. For example @Provider @Produces(MediaType.APPLICATION_JSON) public static JacksonContextResolver implements ContextResolver<ObjectMapper> { private final ObjectMapper mapper; public

JAX RS Jersey Schema Validation

走远了吗. 提交于 2019-12-23 15:46:14
问题 How to configure schema validation for JAX-RS RESTFul services? We are using XSD to define the models, and JAXB to generate the java models. 回答1: This is how it's done automatically in ReXSL: XslResolver#addXsdValidatorToMarshaller() (pay attention to the highlighted method). In a nutshell, you need to use setSchema() of your JAXB Marshaller . 来源: https://stackoverflow.com/questions/3886653/jax-rs-jersey-schema-validation

How to set CORS headers into internal server error responses?

邮差的信 提交于 2019-12-23 14:42:08
问题 I have a java application server with a REST interface provided by resteasy and I have the CORS filter bellow @Provider public class CORSFilter implements ContainerResponseFilter { public void filter(ContainerRequestContext cReq, ContainerResponseContext cResp) { cResp.getHeaders().add("Access-Control-Allow-Origin", "*"); cResp.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization, auth-token"); cResp.getHeaders().add("Access-Control-Allow-Credentials",

How to set CORS headers into internal server error responses?

纵然是瞬间 提交于 2019-12-23 14:41:48
问题 I have a java application server with a REST interface provided by resteasy and I have the CORS filter bellow @Provider public class CORSFilter implements ContainerResponseFilter { public void filter(ContainerRequestContext cReq, ContainerResponseContext cResp) { cResp.getHeaders().add("Access-Control-Allow-Origin", "*"); cResp.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization, auth-token"); cResp.getHeaders().add("Access-Control-Allow-Credentials",