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);
}
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations