use of javax.xml.bind.Marshaller in project feign by OpenFeign.
the class JAXBContextFactoryTest method buildsMarshallerWithSchemaLocationProperty.
@Test
public void buildsMarshallerWithSchemaLocationProperty() throws Exception {
JAXBContextFactory factory = new JAXBContextFactory.Builder().withMarshallerSchemaLocation("http://apihost http://apihost/schema.xsd").build();
Marshaller marshaller = factory.createMarshaller(Object.class);
assertEquals("http://apihost http://apihost/schema.xsd", marshaller.getProperty(Marshaller.JAXB_SCHEMA_LOCATION));
}
use of javax.xml.bind.Marshaller in project feign by OpenFeign.
the class JAXBContextFactoryTest method buildsMarshallerWithNoNamespaceSchemaLocationProperty.
@Test
public void buildsMarshallerWithNoNamespaceSchemaLocationProperty() throws Exception {
JAXBContextFactory factory = new JAXBContextFactory.Builder().withMarshallerNoNamespaceSchemaLocation("http://apihost/schema.xsd").build();
Marshaller marshaller = factory.createMarshaller(Object.class);
assertEquals("http://apihost/schema.xsd", marshaller.getProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION));
}
use of javax.xml.bind.Marshaller in project quickstarts by jboss-switchyard.
the class JAXBUtil method marshal.
/**
* Returns string representation of {@link GreetingRequest}.
*
* @param rq Request.
* @return XML representation.
* @throws JAXBException
*/
public static String marshal(GreetingRequest rq) throws JAXBException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Marshaller marshaller = CONTEXT.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(rq, bos);
return new String(bos.toByteArray());
}
use of javax.xml.bind.Marshaller in project jersey by jersey.
the class WadlResource method getWadl.
@Produces({ "application/vnd.sun.wadl+xml", "application/xml" })
@GET
public synchronized Response getWadl(@Context UriInfo uriInfo) {
try {
if (!wadlContext.isWadlGenerationEnabled()) {
return Response.status(Response.Status.NOT_FOUND).build();
}
final boolean detailedWadl = WadlUtils.isDetailedWadlRequested(uriInfo);
if ((wadlXmlRepresentation == null) || (!isCached(uriInfo, detailedWadl))) {
this.lastBaseUri = uriInfo.getBaseUri();
lastDetailedWadl = detailedWadl;
this.lastModified = new SimpleDateFormat(HTTPDATEFORMAT).format(new Date());
ApplicationDescription applicationDescription = wadlContext.getApplication(uriInfo, detailedWadl);
Application application = applicationDescription.getApplication();
try {
final Marshaller marshaller = wadlContext.getJAXBContext().createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
final ByteArrayOutputStream os = new ByteArrayOutputStream();
marshaller.marshal(application, os);
wadlXmlRepresentation = os.toByteArray();
os.close();
} catch (Exception e) {
throw new ProcessingException("Could not marshal the wadl Application.", e);
}
}
return Response.ok(new ByteArrayInputStream(wadlXmlRepresentation)).header("Last-modified", lastModified).build();
} catch (Exception e) {
throw new ProcessingException("Error generating /application.wadl.", e);
}
}
use of javax.xml.bind.Marshaller in project jersey by jersey.
the class AbstractCollectionJaxbProvider method writeTo.
@Override
public final void writeTo(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException {
try {
final Collection c = (type.isArray()) ? Arrays.asList((Object[]) t) : (Collection) t;
final Class elementType = getElementClass(type, genericType);
final Charset charset = getCharset(mediaType);
final String charsetName = charset.name();
final Marshaller m = getMarshaller(elementType, mediaType);
m.setProperty(Marshaller.JAXB_FRAGMENT, true);
if (charset != UTF8) {
m.setProperty(Marshaller.JAXB_ENCODING, charsetName);
}
setHeader(m, annotations);
writeCollection(elementType, c, mediaType, charset, m, entityStream);
} catch (JAXBException ex) {
throw new InternalServerErrorException(ex);
}
}
Aggregations