use of org.glassfish.jersey.server.wadl.WadlGenerator in project jersey by jersey.
the class WadlGeneratorLoaderTest method testLoadStream.
@Test
public void testLoadStream() throws Exception {
final InjectionManager injectionManager = InjectionManagerFactory.createInjectionManager();
final Properties props = new Properties();
final String path = getClass().getPackage().getName().replaceAll("\\.", "/") + "/testfile.xml";
props.put("testStream", path);
final WadlGeneratorDescription description = new WadlGeneratorDescription(MyWadlGenerator2.class, props);
final WadlGenerator wadlGenerator = WadlGeneratorLoader.loadWadlGeneratorDescriptions(injectionManager, description);
Assert.assertEquals(MyWadlGenerator2.class, wadlGenerator.getClass());
final URL resource = getClass().getResource("testfile.xml");
Assert.assertEquals(new File(resource.toURI()).length(), ((MyWadlGenerator2) wadlGenerator).getTestStreamContent().length());
}
use of org.glassfish.jersey.server.wadl.WadlGenerator in project jersey by jersey.
the class WadlGeneratorResourceDocSupportTest method wadlIsGeneratedWithUnknownCustomParameterAnnotation.
@Test
public void wadlIsGeneratedWithUnknownCustomParameterAnnotation() throws JAXBException {
/* Set up a ClassDocType that has something for a custom-annotated parameter */
ClassDocType cdt = new ClassDocType();
cdt.setClassName(TestResource.class.getName());
MethodDocType mdt = new MethodDocType();
mdt.setMethodName("method");
cdt.getMethodDocs().add(mdt);
ParamDocType pdt = new ParamDocType("x", "comment about x");
mdt.getParamDocs().add(pdt);
AnnotationDocType adt = new AnnotationDocType();
adt.setAnnotationTypeName(CustomParam.class.getName());
adt.getAttributeDocs().add(new NamedValueType("value", "x"));
pdt.getAnnotationDocs().add(adt);
ResourceDocType rdt = new ResourceDocType();
rdt.getDocs().add(cdt);
/* Generate WADL for that class */
WadlGenerator wg = new WadlGeneratorResourceDocSupport(new WadlGeneratorImpl(), rdt);
WadlBuilder wb = new WadlBuilder(wg, false, null);
Resource resource = Resource.from(TestResource.class);
ApplicationDescription app = wb.generate(Collections.singletonList(resource));
/* Confirm that it can be marshalled without error */
StringWriter sw = new StringWriter();
JAXBContext context = JAXBContext.newInstance(Application.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.marshal(app.getApplication(), sw);
}
use of org.glassfish.jersey.server.wadl.WadlGenerator in project jersey by jersey.
the class WadlGeneratorConfig method createWadlGenerator.
/**
* Create a new instance of {@link org.glassfish.jersey.server.wadl.WadlGenerator}, based on the {@link WadlGeneratorDescription}s
* provided by {@link #configure()}.
*
* @return the initialized {@link org.glassfish.jersey.server.wadl.WadlGenerator}
*/
public WadlGenerator createWadlGenerator(InjectionManager injectionManager) {
final WadlGenerator wadlGenerator;
final List<WadlGeneratorDescription> wadlGeneratorDescriptions;
try {
wadlGeneratorDescriptions = configure();
} catch (final Exception e) {
throw new ProcessingException(LocalizationMessages.ERROR_WADL_GENERATOR_CONFIGURE(), e);
}
for (final WadlGeneratorDescription desc : wadlGeneratorDescriptions) {
desc.setConfiguratorClass(this.getClass());
}
try {
wadlGenerator = WadlGeneratorLoader.loadWadlGeneratorDescriptions(injectionManager, wadlGeneratorDescriptions);
} catch (final Exception e) {
throw new ProcessingException(LocalizationMessages.ERROR_WADL_GENERATOR_LOAD(), e);
}
return wadlGenerator;
}
use of org.glassfish.jersey.server.wadl.WadlGenerator in project jersey by jersey.
the class WadlGeneratorLoader method loadWadlGenerators.
static WadlGenerator loadWadlGenerators(List<WadlGenerator> wadlGenerators) throws Exception {
WadlGenerator wadlGenerator = new WadlGeneratorJAXBGrammarGenerator();
if (wadlGenerators != null && !wadlGenerators.isEmpty()) {
for (WadlGenerator generator : wadlGenerators) {
generator.setWadlGeneratorDelegate(wadlGenerator);
wadlGenerator = generator;
}
}
wadlGenerator.init();
return wadlGenerator;
}
use of org.glassfish.jersey.server.wadl.WadlGenerator 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;
}
Aggregations