Search in sources :

Example 1 with Application

use of com.sun.research.ws.wadl.Application in project jersey by jersey.

the class WadlBuilder method generate.

/**
     * Generate WADL for a resource.
     *
     * @param resource    the resource
     * @param description the overall application description so we can
     * @return the JAXB WADL application bean
     */
public Application generate(ApplicationDescription description, org.glassfish.jersey.server.model.Resource resource) {
    try {
        Application wadlApplication = _wadlGenerator.createApplication();
        Resources wadlResources = _wadlGenerator.createResources();
        Resource wadlResource = generateResource(resource, null);
        if (wadlResource == null) {
            return null;
        }
        wadlResources.getResource().add(wadlResource);
        wadlApplication.getResources().add(wadlResources);
        addVersion(wadlApplication);
        // Attach the data to the parts of the model
        _wadlGenerator.attachTypes(description);
        return wadlApplication;
    } catch (Exception e) {
        throw new ProcessingException(LocalizationMessages.ERROR_WADL_BUILDER_GENERATION_RESOURCE(resource), e);
    }
}
Also used : Resource(com.sun.research.ws.wadl.Resource) Resources(com.sun.research.ws.wadl.Resources) Application(com.sun.research.ws.wadl.Application) ProcessingException(javax.ws.rs.ProcessingException) ProcessingException(javax.ws.rs.ProcessingException)

Example 2 with Application

use of com.sun.research.ws.wadl.Application in project jersey by jersey.

the class WadlBuilder method generate.

/**
     * Generate WADL for a set of resources.
     *
     * @param resources the set of resources.
     * @return the JAXB WADL application bean.
     */
public ApplicationDescription generate(List<org.glassfish.jersey.server.model.Resource> resources) {
    Application wadlApplication = _wadlGenerator.createApplication();
    Resources wadlResources = _wadlGenerator.createResources();
    // for each resource
    for (org.glassfish.jersey.server.model.Resource r : resources) {
        Resource wadlResource = generateResource(r, r.getPath());
        if (wadlResource == null) {
            continue;
        }
        wadlResources.getResource().add(wadlResource);
    }
    wadlApplication.getResources().add(wadlResources);
    addVersion(wadlApplication);
    addHint(wadlApplication);
    // Build any external grammars
    WadlGenerator.ExternalGrammarDefinition external = _wadlGenerator.createExternalGrammar();
    //
    ApplicationDescription description = new ApplicationDescription(wadlApplication, external);
    // Attach the data to the parts of the model
    _wadlGenerator.attachTypes(description);
    return description;
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) Resource(com.sun.research.ws.wadl.Resource) Resources(com.sun.research.ws.wadl.Resources) Application(com.sun.research.ws.wadl.Application)

Example 3 with Application

use of com.sun.research.ws.wadl.Application 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);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleDateFormat(java.text.SimpleDateFormat) Application(com.sun.research.ws.wadl.Application) Date(java.util.Date) ProcessingException(javax.ws.rs.ProcessingException) ProcessingException(javax.ws.rs.ProcessingException) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with Application

use of com.sun.research.ws.wadl.Application in project jersey by jersey.

the class WadlApplicationContextImpl method getApplication.

@Override
public Application getApplication(final UriInfo info, final org.glassfish.jersey.server.model.Resource resource, final boolean detailedWadl) {
    // Get the root application description
    //
    final ApplicationDescription description = getApplication(info, detailedWadl);
    final WadlGenerator wadlGenerator = wadlGeneratorConfig.createWadlGenerator(injectionManager);
    final Application application = new WadlBuilder(wadlGenerator, detailedWadl, info).generate(description, resource);
    if (application == null) {
        return null;
    }
    for (final Resources resources : application.getResources()) {
        resources.setBase(info.getBaseUri().toString());
    }
    // Attach any grammar we may have
    attachExternalGrammar(application, description, info.getRequestUri());
    for (final Resources resources : application.getResources()) {
        final Resource r = resources.getResource().get(0);
        r.setPath(info.getBaseUri().relativize(info.getAbsolutePath()).toString());
        // remove path params since path is fixed at this point
        r.getParam().clear();
    }
    return application;
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) Resource(com.sun.research.ws.wadl.Resource) Resources(com.sun.research.ws.wadl.Resources) Application(com.sun.research.ws.wadl.Application)

Example 5 with Application

use of com.sun.research.ws.wadl.Application in project jersey by jersey.

the class WadlApplicationContextImpl method getApplication.

@Override
public ApplicationDescription getApplication(final UriInfo uriInfo, final boolean detailedWadl) {
    final ApplicationDescription applicationDescription = getWadlBuilder(detailedWadl, uriInfo).generate(resourceContext.getResourceModel().getRootResources());
    final Application application = applicationDescription.getApplication();
    for (final Resources resources : application.getResources()) {
        if (resources.getBase() == null) {
            resources.setBase(uriInfo.getBaseUri().toString());
        }
    }
    attachExternalGrammar(application, applicationDescription, uriInfo.getRequestUri());
    return applicationDescription;
}
Also used : Resources(com.sun.research.ws.wadl.Resources) Application(com.sun.research.ws.wadl.Application)

Aggregations

Application (com.sun.research.ws.wadl.Application)5 Resources (com.sun.research.ws.wadl.Resources)4 Resource (com.sun.research.ws.wadl.Resource)3 ProcessingException (javax.ws.rs.ProcessingException)2 WadlGenerator (org.glassfish.jersey.server.wadl.WadlGenerator)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 Marshaller (javax.xml.bind.Marshaller)1