@Test public void testEntityBody() throws IOException { EntityDefinition def = mock(EntityDefinition.class); when(entityDefinitionStore.lookupByEntityType(anyString())).thenReturn(def); ByteArrayOutputStream out = new ByteArrayOutputStream(); EntityBody body = new EntityBody(); body.put("id", "1234"); body.put("name", "test name"); EntityResponse response = new EntityResponse("TestEntity", body); writer.writeTo(response, null, null, null, null, null, out); assertNotNull("Should not be null", out); String value = new String(out.toByteArray()); assertTrue("Should match", value.indexOf("<TestEntity") > 0); assertTrue("Should match", value.indexOf("<id>") > 0); assertTrue("Should match", value.indexOf("<name>") > 0); }
@Override public void writeTo(EntityResponse entityResponse, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { try { writeEntity(entityResponse, entityStream); } catch (XMLStreamException e) { LOG.error("Could not write out to XML {}", e); throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); } }
EntityXMLWriter implements MessageBodyWriter<EntityResponse> { @Override public void writeTo(EntityResponse entityResponse, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { try { writeEntity(entityResponse, entityStream); } catch (XMLStreamException e) { LOG.error("Could not write out to XML {}", e); throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); } } }
EntityXMLWriter implements MessageBodyWriter<EntityResponse> { @Override public void writeTo(EntityResponse entityResponse, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { try { writeEntity(entityResponse, entityStream); } catch (XMLStreamException e) { LOG.error("Could not write out to XML {}", e); throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); } }  }
EntityXMLWriter implements MessageBodyWriter<EntityResponse> { @Override public void writeTo(EntityResponse entityResponse, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { try { writeEntity(entityResponse, entityStream); } catch (XMLStreamException e) { LOG.error("Could not write out to XML {}", e); throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); } }  @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(EntityResponse entityResponse, Class<?> type, Type genericType,
                        Annotation[] annotations, MediaType mediaType); @Override void writeTo(EntityResponse entityResponse, Class<?> type, Type genericType, Annotation[] annotations,
                        MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream); }
EntityXMLWriter implements MessageBodyWriter<EntityResponse> { @Override public void writeTo(EntityResponse entityResponse, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { try { writeEntity(entityResponse, entityStream); } catch (XMLStreamException e) { LOG.error("Could not write out to XML {}", e); throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); } }  @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(EntityResponse entityResponse, Class<?> type, Type genericType,
                        Annotation[] annotations, MediaType mediaType); @Override void writeTo(EntityResponse entityResponse, Class<?> type, Type genericType, Annotation[] annotations,
                        MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream);  }