Search in sources :

Example 1 with WadlGenerator

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;
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) ProcessingException(javax.ws.rs.ProcessingException) ProcessingException(javax.ws.rs.ProcessingException)

Example 2 with 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;
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) WadlGeneratorJAXBGrammarGenerator(org.glassfish.jersey.server.wadl.internal.generators.WadlGeneratorJAXBGrammarGenerator)

Example 3 with 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;
}
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 4 with WadlGenerator

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);
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 5 with WadlGenerator

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());
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Aggregations

WadlGenerator (org.glassfish.jersey.server.wadl.WadlGenerator)16 Test (org.junit.Test)11 InjectionManager (org.glassfish.jersey.internal.inject.InjectionManager)10 Properties (java.util.Properties)5 File (java.io.File)4 URL (java.net.URL)4 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)2 WadlGeneratorJAXBGrammarGenerator (org.glassfish.jersey.server.wadl.internal.generators.WadlGeneratorJAXBGrammarGenerator)2 Application (com.sun.research.ws.wadl.Application)1 Resource (com.sun.research.ws.wadl.Resource)1 Resources (com.sun.research.ws.wadl.Resources)1 StringWriter (java.io.StringWriter)1 ProcessingException (javax.ws.rs.ProcessingException)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 Resource (org.glassfish.jersey.server.model.Resource)1 ApplicationDescription (org.glassfish.jersey.server.wadl.internal.ApplicationDescription)1 WadlBuilder (org.glassfish.jersey.server.wadl.internal.WadlBuilder)1 WadlGeneratorImpl (org.glassfish.jersey.server.wadl.internal.WadlGeneratorImpl)1 WadlGeneratorResourceDocSupport (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.WadlGeneratorResourceDocSupport)1