RS request with JAX

I try to validate a JAX-RS request with a JAX-B object as parameter. Code: JAX-B model class: @XmlRootElement(namespace = "http://www.test.com/test") @XmlAccessorType(value = XmlAccessType.FIELD) public class TestModel { @XmlElement(required = true) private String id; @XmlElement private String name; } JAX-RS resource class: @Path("test") public class TestResource {

RS请求与JAX

我尝试使用JAX-B对象作为参数来验证JAX-RS请求。 码: JAX-B模型类: @XmlRootElement(namespace = "http://www.test.com/test") @XmlAccessorType(value = XmlAccessType.FIELD) public class TestModel { @XmlElement(required = true) private String id; @XmlElement private String name; } JAX-RS资源类: @Path("test") public class TestResource { @POST @Consumes({ MediaType.APPLI

8 encoded String in REST WebService with Apache CXF

I am setting a REST Web Service on a 2.5 Web App on Tomcat 6 using CXF 3.0.2. The webservice receives a POST request with no parameters and returns a JSON String with internationals characters (like é, è, à, ...). The problem is that the calling application seems to receive the String not encoded in UTF-8. I tried with SoapUI but similar problem with the "RAW View" (the "JSON v

REST WebService中的8编码字符串与Apache CXF

我正在使用CXF 3.0.2在Tomcat 6上的2.5 Web应用程序上设置REST Web服务。 webservice收到一个不带参数的POST请求,并返回一个带有国际字符的JSON字符串(如é,è,à,...)。 问题在于调用应用程序似乎收到了未使用UTF-8编码的字符串。 我尝试过使用SoapUI,但与“RAW视图”(“JSON视图”似乎可以)类似的问题。 我真的不知道可能是什么问题。 实际上,我不知道调用的应用程序是不是以UTF-8读取,或者CXF发送的是非UTF-8编码

Handling custom error response in JAX

I am starting to use the new client API library in JAX-RS and really loving it so far. I have found one thing I cannot figure out however. The API I am using has a custom error message format that looks like this for example: { "code": 400, "message": "This is a message which describes why there was a code 400." } It returns 400 as the status code but also includes a descriptive erro

处理JAX中的自定义错误响应

我开始在JAX-RS中使用新的客户端API库,并且非常喜欢它。 但是我发现了一件我无法弄清楚的事情。 我使用的API有一个自定义的错误消息格式,例如: { "code": 400, "message": "This is a message which describes why there was a code 400." } 它返回400作为状态码,但还包含一个描述性错误消息,告诉你你做错了什么。 然而,JAX-RS 2.0客户端将400状态重新映射成通用的,我失去了良好的错误信息。 它正确地将

Mapping of custom exception in JAX

I am developing a Client-Server app with JAX-RS / Apache CXF , JSON I would like Apache CXF to handle my exception transparently on both ends : Which means transforming the exception into a bean, serializing it with my Jackson Serializer (JSON) and then doing the over way around on client side. I have seen several confusing posts/answers on this subject and came up with using the @WebFault an

在JAX中映射自定义异常

我正在开发一个带有JAX-RS / Apache CXF , JSON的Client-Server应用程序 我希望Apache CXF能够在两端透明地处理异常:这意味着将异常转换为bean,使用Jackson序列化程序(JSON)对其进行序列化,然后在客户端进行过滤。 我在这个问题上看到了几个令人困惑的帖子/答案,并提出使用@WebFault注释: @WebFault(name=CODE, faultBean="foo.bar.FaultBean") public class DuplicateRuleNameFault extends Exception { static

how to remove or hide the Http response error using java

I have a REST web service class which i call HttpRequest using curl.I wrote the web service using jersey framework and java in Netbean IDE.If the HttpRequest syntax is correct, the response shows Ok. But When I request the wrong syntax , the response show like this : < HTTP/1.1 400 Bad Request < X-Powered-By: Servlet/3.0 < Server: GlassFish Server Open Source Edition 3.0.1 <

如何使用java删除或隐藏Http响应错误

我有一个REST Web服务类,我使用curl调用HttpRequest。我在Netbean IDE中使用泽西框架和Java编写了Web服务。如果HttpRequest语法正确,响应显示Ok。 但是当我请求错误的语法时,响应显示如下: <HTTP / 1.1 400错误请求 <X-Powered-By:Servlet / 3.0 <服务器:GlassFish Server开源版3.0.1 <Content-Type:text / html <内容长度:1049 <日期:2011年5月16日星期一01:13:31 GMT <连接:关

Trying to pass the value from first java class to second java class

This question already has an answer here: Get value from one class to use it in another class (java) 3 answers return new Status("success", cursor.toString()); You are returning cursor.toString() which is cursor's string representation, which doesn't read content of cursor rather use cursor.next() as you have used in loop. Create list of status and add status into this l

尝试将第一个Java类的值传递给第二个Java类

这个问题在这里已经有了答案: 从一个类中获取值以在另一个类中使用它(java)3个答案 返回新状态(“成功”,cursor.toString()); 您正在返回cursor.toString(),它是游标的字符串表示形式,它不会读取游标的内容,而是像您在循环中使用cursor.next()一样。 创建状态列表并将状态逐一添加到此列表中并返回列表,请参阅以下代码: try { //Build the query BasicDBObject query = new BasicDBO

How to make response 404 without any HTML body for RESTful?

I just use following code to response a 404:Not found. return Response.status(Status.NOT_FOUND).build(); While the response always with following body. How can i remove them? Holp anyone can help me? Thank you so much!

如何在没有任何HTML主体的情况下为RESTful做响应404?

我只是使用以下代码来回应404:未找到。 return Response.status(Status.NOT_FOUND).build(); 而响应总是随着身体。 我如何删除它们? Holp任何人都可以帮助我? 非常感谢!

jetty websocket server: Send customer status code based on application logic

I am writing a Websocket server using Jetty. My handler code: public class WebSocketServerHandler { @OnWebSocketClose public void onClose(int statusCode, String reason) { System.out.println("Close: statusCode=" + statusCode + ", reason=" + reason); } @OnWebSocketError public void onError(Throwable t) { } @OnWebSocketConnect public void onConnect(Sess

jetty websocket服务器:根据应用程序逻辑发送客户状态码

我正在写一个使用Jetty的Websocket服务器。 我的处理代码: public class WebSocketServerHandler { @OnWebSocketClose public void onClose(int statusCode, String reason) { System.out.println("Close: statusCode=" + statusCode + ", reason=" + reason); } @OnWebSocketError public void onError(Throwable t) { } @OnWebSocketConnect public void onConnect(Session se

How to get a status code?

I'm a bit new to JAX-RS. I have the following code: Client client = ClientBuilder.newClient(); WebTarget resource = client.target("/foo/bar/" + id); final String xml = resource.request(MediaType.APPLICATION_XML).get(String.class); This is a stupid question, but how exactly could I get the response and it's status code from here? The output is a String ... Invocation.Builder builde

如何获得状态码?

我对JAX-RS有点新鲜。 我有以下代码: Client client = ClientBuilder.newClient(); WebTarget resource = client.target("/foo/bar/" + id); final String xml = resource.request(MediaType.APPLICATION_XML).get(String.class); 这是一个愚蠢的问题,但我究竟能从这里得到响应和状态码? 输出是一个String ... Invocation.Builder builder = resource.request(MediaType.APPLICATION_XML); Response resp = builder.ge

page> defined in web.xml always comes back with HTTP status 200

I have an EE6 JAX-RS application that runs on Jboss 7 (EAP 6.4) and handles most of its exceptions and errors internally through an implementation of ExceptionMapper . There are circumstances, though, (most notably when HTTP Basic Auth fails) when this is not invoked because the error occurs before the application is invoked, and thus the client gets the server's default error page (JBWEB b

在web.xml中定义的页面总是返回HTTP状态200

我有一个运行在Jboss 7(EAP 6.4)上的EE6 JAX-RS应用程序,并通过ExceptionMapper的实现在内部处理其大部分异常和错误。 但是,有些情况下(最明显的是当HTTP Basic Auth失败时),因为错误发生在应用程序被调用之前,因此客户端获取服务器的默认错误页面(JBWEB bla bla,带有丑陋紫色的HTML )。 现在为了捕获这些“外部”错误,我在web.xml添加了<error-page>定义,如下所示: <error-page> <location&