Friday 15 August 2014

java - JAX-RS get entity as JAXB object and as String -


I have a JX-RS web service (using jersey) which requests a JAXB object as the request institution Does. When we get an error, we want to log the original XML string that was sent to us. Currently, I'm just martializing the JACAB object, but since we have many Java anomes in those classes, the value values ​​that are not spelled correctly in the original XML string are lost, which are for our purposes. Not acceptable.

Does anyone know any way to get the request unit as both string and JABX object? I do not like to write a custom message debitter and I probably do not like to try and get messesby reader for JACB. You are free to use Jersey-specific classes too, we are using version 1.0.x.

gets out, it is not hard to do this JX-RS API here I have done :

  @ path ("/ transaction") public class testResource & lt; X & gt; {Private Sector & lt; X & gt; JaxbClass; @POST @ Path ( "/ {transactions id}") @ Kansom ( "application / xml") public reaction post (@ Kntekt provider, @ Conteks HTTP headers http Hdiyron, @ Pathprm ( "transaction-id") final Long transaction ID, last string xmlString) throws WebApplicationException, IOException {MessageBodyReader & lt; X & gt; Reader = providers .getMessageBodyReader (jaxbClass, blank, blank, MediaType.APPLICATION_XML_TYPE); InputStream entityStream = new bytereinputstream (xmlString.getBytes ()); Last X xmlObject = reader.readFrom (jaxbClass, null, null, MediaType.APPLICATION_XML_TYPE, httpHeaders.getRequestHeaders (), antistream); // Insert logic here Returns Response.ok (). Build (); }}  

This will give you XML as a string and in some lines of code as a JAXB object.


No comments:

Post a Comment