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;
}
use of org.glassfish.jersey.server.wadl.WadlGenerator in project jersey by jersey.
the class WadlGeneratorConfigTest method testBuildWadlGeneratorFromDescriptions.
@Test
public void testBuildWadlGeneratorFromDescriptions() {
final InjectionManager locator = InjectionManagerFactory.createInjectionManager();
final String propValue = "bar";
WadlGeneratorConfig config = WadlGeneratorConfig.generator(MyWadlGenerator.class).prop("foo", propValue).build();
WadlGenerator wadlGenerator = config.createWadlGenerator(locator);
Assert.assertEquals(MyWadlGenerator.class, wadlGenerator.getClass());
Assert.assertEquals(((MyWadlGenerator) wadlGenerator).getFoo(), propValue);
final String propValue2 = "baz";
config = WadlGeneratorConfig.generator(MyWadlGenerator.class).prop("foo", propValue).generator(MyWadlGenerator2.class).prop("bar", propValue2).build();
wadlGenerator = config.createWadlGenerator(locator);
Assert.assertEquals(MyWadlGenerator2.class, wadlGenerator.getClass());
final MyWadlGenerator2 wadlGenerator2 = (MyWadlGenerator2) wadlGenerator;
Assert.assertEquals(wadlGenerator2.getBar(), propValue2);
Assert.assertEquals(MyWadlGenerator.class, wadlGenerator2.getDelegate().getClass());
Assert.assertEquals(((MyWadlGenerator) wadlGenerator2.getDelegate()).getFoo(), propValue);
}
use of org.glassfish.jersey.server.wadl.WadlGenerator in project jersey by jersey.
the class WadlGeneratorConfigurationLoaderTest method testLoadConfigClass.
@Test
public void testLoadConfigClass() throws URISyntaxException {
final ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.property(ServerProperties.WADL_GENERATOR_CONFIG, MyWadlGeneratorConfig.class.getName());
final InjectionManager locator = InjectionManagerFactory.createInjectionManager(resourceConfig.getProperties());
final WadlGenerator wadlGenerator = WadlGeneratorConfigLoader.loadWadlGeneratorsFromConfig(resourceConfig.getProperties()).createWadlGenerator(locator);
Assert.assertEquals(MyWadlGenerator.class, wadlGenerator.getClass());
}
Aggregations