}
// Select the right variant based on the request type
List<Variant> vl = Variant.mediaTypes(MediaTypes.WADL, MediaTypes.WADL_JSON, MediaType.APPLICATION_XML_TYPE)
.add().build();
Variant v = request.selectVariant(vl);
if (v==null) {
return Response.notAcceptable(vl).build();
}
// Update the last modified stamp
if (applicationDescription == null || ((lastBaseUri != null) && !lastBaseUri.equals(uriInfo.getBaseUri()) && !lastVariant.equals(v))) {
this.lastBaseUri = uriInfo.getBaseUri();
this.lastModified = new SimpleDateFormat(HTTPDATEFORMAT).format(new Date());
this.lastVariant = v;
applicationDescription = wadlContext.getApplication(uriInfo);
final Application application = applicationDescription.getApplication();
final ByteArrayOutputStream os = new ByteArrayOutputStream();
if(v.getMediaType().equals(MediaTypes.WADL)) {
try {
final Marshaller marshaller = wadlContext.getJAXBContext().createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(application, os);
cachedWadl = os.toByteArray();
os.close();
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Could not marshal wadl Application.", e);
return Response.serverError().build();
}
} else {
final MessageBodyWriter<Application> messageBodyWriter = providers.getMessageBodyWriter(Application.class, null, new Annotation[0], v.getMediaType());
if(messageBodyWriter == null) {
return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).build();
}
try {
messageBodyWriter.writeTo(application, Application.class, null, new Annotation[0], v.getMediaType(), null /* headers */, os);
cachedWadl = os.toByteArray();
os.close();
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Could not serialize wadl Application.", e);
return Response.serverError().build();