Search in sources :

Example 6 with WadlGenerator

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());
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) Properties(java.util.Properties) File(java.io.File) URL(java.net.URL) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 7 with WadlGenerator

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);
}
Also used : WadlGeneratorImpl(org.glassfish.jersey.server.wadl.internal.WadlGeneratorImpl) Marshaller(javax.xml.bind.Marshaller) ClassDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ClassDocType) NamedValueType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.NamedValueType) Resource(org.glassfish.jersey.server.model.Resource) AnnotationDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.AnnotationDocType) WadlBuilder(org.glassfish.jersey.server.wadl.internal.WadlBuilder) JAXBContext(javax.xml.bind.JAXBContext) ApplicationDescription(org.glassfish.jersey.server.wadl.internal.ApplicationDescription) WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) StringWriter(java.io.StringWriter) MethodDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.MethodDocType) ResourceDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ResourceDocType) WadlGeneratorResourceDocSupport(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.WadlGeneratorResourceDocSupport) ParamDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ParamDocType) Test(org.junit.Test)

Example 8 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 9 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 10 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)

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