@Produces({"application/xml"}) @GET @Path("{path}") public synchronized Response geExternalGrammar( @Context UriInfo uriInfo, @PathParam("path") String path) { try { // Fail if wadl generation is disabled if (!wadlContext.isWadlGenerationEnabled()) { return Response.status(Response.Status.NOT_FOUND).build(); } ApplicationDescription applicationDescription = wadlContext.getApplication(uriInfo, WadlUtils.isDetailedWadlRequested(uriInfo)); // Fail is we don't have any metadata for this path ApplicationDescription.ExternalGrammar externalMetadata = applicationDescription.getExternalGrammar(path); if (externalMetadata == null) { return Response.status(Response.Status.NOT_FOUND).build(); } // Return the data return Response.ok() .type(externalMetadata.getType()) .entity(externalMetadata.getContent()) .build(); } catch (Exception e) { throw new ProcessingException(LocalizationMessages.ERROR_WADL_RESOURCE_EXTERNAL_GRAMMAR(), e); } }
@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); } }
@Path("switch") @POST public void switchMethod(@Context final WadlApplicationContext wadlApplicationContext) { wadlApplicationContext.setWadlGenerationEnabled( !wadlApplicationContext.isWadlGenerationEnabled()); }