org.jboss.resteasy.wadl.ResteasyWadlDefaultResource Maven / Gradle / Ivy
The newest version!
package org.jboss.resteasy.wadl;
import java.util.HashMap;
import java.util.Map;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.xml.bind.JAXBException;
import org.jboss.resteasy.spi.ResteasyDeployment;
import org.jboss.resteasy.wadl.i18n.LogMessages;
import org.jboss.resteasy.wadl.i18n.Messages;
/**
* @author Weinan Li
*/
public abstract class ResteasyWadlDefaultResource {
private Map services = new HashMap<>();
private void loadServices(ResteasyDeployment deployment) {
services.put("/", ResteasyWadlGenerator.generateServiceRegistry(deployment));
}
public Map getServices() {
return services;
}
ResteasyWadlWriter wadlWriter = new ResteasyWadlWriter(); // create a default servlet writer.
public ResteasyWadlWriter getWadlWriter() {
return wadlWriter;
}
@GET
@Path("/application.xml")
@Produces("application/xml")
public String output(@Context ResteasyDeployment deployment) {
loadServices(deployment);
try {
return wadlWriter.getStringWriter("", services).toString();
} catch (JAXBException e) {
LogMessages.LOGGER.error(Messages.MESSAGES.cantProcessWadl(), e);
}
return null;
}
@GET
@Path("/wadl-extended/{path}")
@Produces("application/xml")
public Response grammars(@PathParam("path") String path, @Context ResteasyDeployment deployment) {
loadServices(deployment);
wadlWriter.createApplication("", services);
return Response
.ok()
.type(MediaType.APPLICATION_XML_TYPE)
.entity(wadlWriter.getWadlGrammar().getSchemaOfUrl(path))
.build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy