Skip to content

Instantly share code, notes, and snippets.

@jeanouii
Created February 25, 2014 14:38
Show Gist options
  • Select an option

  • Save jeanouii/9209995 to your computer and use it in GitHub Desktop.

Select an option

Save jeanouii/9209995 to your computer and use it in GitHub Desktop.
public class WadlInstaller {
private static final Logger LOGGER = Logger.getInstance(LogCategory.OPENEJB_SERVER, WadlInstaller.class);
private static final String WADLX_GENERATOR_ID = "wadlxGenerator";
public void beforeInfoTreeBuilder(@Observes final BeforeAppInfoBuilderEvent event) {
final Service wadlxGenerator = new Service(WADLX_GENERATOR_ID, null);
wadlxGenerator.setClassName(WadlGenerator.class.getName());
// for now, we just deal with one WebModule (Collapsed EAR) and of course one EjbModule
final Iterator<WebModule> iterator = event.getAppModule().getWebModules().iterator();
for (EjbModule ejbModule : event.getAppModule().getEjbModules()) {
ejbModule.getAppModule().getServices().add(wadlxGenerator);
// get the openejb-jar or create if none
OpenejbJar openejbJar = ejbModule.getOpenejbJar();
if (openejbJar == null) {
openejbJar = new OpenejbJar();
ejbModule.setOpenejbJar(openejbJar);
}
// get the PojoDeployment for the REST application or create if none
boolean found = false;
for (PojoDeployment pojo : openejbJar.getPojoDeployment()) {
while (iterator.hasNext()) {
WebModule webModule = iterator.next();
if (webModule.getRestApplications().contains(pojo.getClassName())) {
LOGGER.debug("Found application for class " + pojo.getClassName());
addProviderProperty(pojo, WADLX_GENERATOR_ID);
found = true;
continue;
}
}
}
if (!found) {
LOGGER.debug("No application found. Creating one configuration for the default jaxrs-application.");
final PojoDeployment pojo = new PojoDeployment();
pojo.setClassName("jaxrs-application"); // default application
addProviderProperty(pojo, WADLX_GENERATOR_ID);
openejbJar.getPojoDeployment().add(pojo);
}
}
}
private void addProviderProperty(final PojoDeployment pojo, final String id) {
String current = pojo.getProperties().getProperty("cxf.jaxrs.providers");
if (current != null && current.trim().length() > 0) {
// there is already a jaxrs set of providers configured, just add our
current += "," + id;
} else {
current = id;
}
pojo.getProperties().setProperty("cxf.jaxrs.providers", current);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment