Jersey Post 400 Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and jersey client post bad request policies of this site About Us Learn more about Stack Overflow the
Jersey 400 Bad Request
company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users returned a response status of 400 bad request jersey Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes
Jersey Return Bad Request
a minute: Sign up Jersey: Returning 400 error instead of 500 when given invalid request body up vote 13 down vote favorite 2 I'm using Jersey's integrated Jackson processing to transform incoming JSON to a POJO, e.g.: @POST @Consumes(MediaType.APPLICATION_JSON) public Response newCustomer( CustomerRepresentation customer) { ... } If a client sends JSON with invalid fields Jersey currently returns a 500 Internal jersey bad request exception Server Error. Instead, I'd like to return a 400 Bad Request, preferably with some meaningful detail indicating which fields are in error. Any insight into how this could be accomplished? (At least returning a generic 400 instead of the completely inappropriate 500?) Update: Here's the exception being generated server-side, before my handler is invoked: javax.servlet.ServletException: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "this_isnt_a_known"_field" (Class com.redacted....), not marked as ignorable jersey jax-rs share|improve this question edited Mar 27 '12 at 17:12 asked Mar 23 '12 at 18:31 HolySamosa 2,95563172 400 actually means Bad request, i.e. the server thinks that client has send the wrong request. So semantically it does not fit what you want to achieve. –dma_k Mar 25 '12 at 15:28 Thanks for catching my slip. I intended to type "Bad Request". Question edited accordingly. –HolySamosa Mar 26 '12 at 13:05 Jersey usually returns 400 if the request body is invalid. Are you sure it doesn't fail in the body of your method with a NPE or something? Do you see any error and/or stack trace in your app serv
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring
Jersey Post 400 Bad Request
developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
Jersey 400 Response
x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; jersey exception mapper it only takes a minute: Sign up HTTP 400 error in REST web service during POST with FormParam containing own objects (e.g. enities) up vote 4 down vote favorite 1 For an ordering process in my REST service I have http://stackoverflow.com/questions/9844654/jersey-returning-400-error-instead-of-500-when-given-invalid-request-body to send a list of "articles" from client to server. These article objects are of a self-made entity type. I already found out that sending a list of STRING or INTEGER objects does work, sending it via @FormParam. But as soon as I try to send a list of my own objects (even only ONE object), I always get a HTTP 400 error "Bad Request". I tried excatly the same code like below (only the parameters of form.add() and http://stackoverflow.com/questions/18694297/http-400-error-in-rest-web-service-during-post-with-formparam-containing-own-obj the parameters of the server method were altered) and postet Strings, Integers and lists of Strings successfully. It only makes problems sending own object types. Logging told me that the server method isn't reached. The process is broken somewhere before. I also tried to get the request by using a proxy (Apache JMeter). Here it says that the parameter kunde contains the value entities.Kunde%40af8358. So I guess the object is not serialized thoroughly (or at all). But sending this kind of object from server to client in a response works fine - here the XML-serialization is no problem. What might be the reason? Is it maybe NOT possible to send own types through POST? (PS: The type Kundein my example is serializable and annotated with @XmlRootElement.) Thank you in advance for your help! Jana Note: I'm using the SAP Netweaver AS. But until now it behaved like every other Java AS, so I don't think this will be the reason. Every other REST operation does work, even POST without own entities. Addition: I'm using the JERSEY library. My Code on server side: @Path("/test") @POST @Produces(MediaType.TEXT_XML) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public String test( @FormParam("kunde") Kunde kunde) { return "The name of the customer is: " +kunde.getVorname()+" "+kunde.getNachname(); } My code on client side (the method is in a Session Bean): public String test() { Kunde kunde = new Kunde(); kunde.setNachname("Müller"); kunde.setVorname("Kurt"); Form form = new Form(); form.add("kunde", kunde); return service .
seo spring testing tips & tricks tomcat troubleshooting web design web development Tags About Home Error handling in REST API with Jersey June 06, 2014 Reading time ~6 minutes http://www.codingpedia.org/ama/error-handling-in-rest-api-with-jersey/ Home About Tags Categories C# Java EE Podcastpedia.org WordPress architecture code database dev tools development errors hibernate ide image intro java java ee javascript jekyll optimization qa resources sample security seo spring testing tips & tricks tomcat troubleshooting web design web development | Follow @codingpedia Error handling in REST API with Jersey Error handling is one of the most procrastinated and bad request least enjoyable parts when writing code… I mean, why should the application not always work as expected, when we've written it with so much passion and care, and, you know, the clients of the application always send the right requests, right?!? Unfortunately things do go wrong from time to time, and when it does we should be prepared to some extent at least… This is 400 bad request especially the case when writing REST APIs, because clients only get a black box with specification, having no clue what to do when the expected answer doesn't come back, unless we do something about it… Bottom line: error handling is essential when designing REST APIs. In this post I will present how I've designed and implemented the error handling of a REST API with the help Jersey framework. The code is based on the open source project presented in the Tutorial – REST API design and implementation in Java with Jersey and Spring" Contents 1. Design 2. Implementation 2.1. Checked(business) exceptions 2.2. Unchecked(technical) exceptions 3. Testing 4. Custom Reason Phrase in HTTP status error message response with JAX-RS (Jersey) 5. Summary 6. Resources 6.1. Source Code 6.2. Codingpedia 6.3. Web 1. Design There are usually two causes for error occurence: either something failed on the server or the client of the API sent an invalid request. In both cases I've decided to send back a response with some metadata that should be useful for client, and potentially the developers of the cl