I am deploying a web services on WSO2 Application Server 5.2.1 which loads a reportDesign from a database table and renders a PDF stream, which is then stored as a file in an outgoing ftp server directory. All works well when running from the command line, but I am having a hard time configuring the EngineConfig's EngineHome property in when deploying on WSO2 AS 5.2.1.
My pom.xml file (for Maven) embeds Birt 4.4.1 runtime in my aar file, which is then deployed as part of a larger car file. Birt jar files are correctly picked up by my web service.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
....
<artifactItem>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.eclipse.birt.runtime</artifactId>
<version>4.4.1</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/aar/lib</outputDirectory>
</artifactItem>
...
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
<dependencies>
...
<dependency>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.eclipse.birt.runtime</artifactId>
<version>4.4.1</version>
</dependency>
...
</dependencies>
A snippet of my Java code is as follows, which has been stripped down for simplicity:
InputStream theReportDesign = getReportDesignStream();
// The engine will eventually be called just once...
EngineConfig config = new EngineConfig();
config.setEngineHome("");
// Create the report engine itself. This engine can be used to run
// multiple reports.
ReportEngine engine = new ReportEngine(config);
// Create a task to run the report and convert the output to PDF.
IReportRunnable report = engine.openReportDesign(theReportName, theReportDesign);
IRunAndRenderTask task = engine.createRunAndRenderTask(report);
outputStream = new ByteArrayOutputStream();
// Define the report generation options
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_PDF);
options.setOutputStream(outputStream);
task.setRenderOption(options);
task.setErrorHandlingOption(IEngineTask.CONTINUE_ON_ERROR);
// set the parameters to appear in the report
task.setParameterValues(values);
// Generate the report.
task.run();
// Write the report to disk, so ftp clients can pick it up
outputStream.close();
writePdfReportToFile(outputStream);
The error I get when running this from within WSO2 Application Server is as follows:
Can not load the report engine
java.lang.NullPointerException
at org.eclipse.birt.report.engine.api.ReportEngine.openReportDesign(ReportEngine.java:182)
I have seen many proposed solutions on the web, but most within the Tomcat/Axis2 environment (which is what WSO2 uses) require knowledge of the ServletContext. My attempts to get the ServletContext off of the MessageContext have not been successful.
I am hoping to not have to deploy Birt into WSO2, but to instead keep the Birt Runtime contained within my aar file which I deploy to WSO2. But I'll resort to deploying Birt directly to the WSO2 server, as well (just need instructions to do that and still make the above code work).
Thanks in advance for any help.
This line should not be necessary because the BIRT runtime is embedded in your bundle, try to comment it:
config.setEngineHome("");
Furthermore usually we need to start the BIRT platform before creating an engine, check this link. I know you said the java snippet has been stripped, but we don't have any clue to guess if you forgot this or not:
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
However it is strange you don't get any exception when the engine is created, may be it is actually wrapped in a try..catch?
Ok, figured it out.
First of all, it is acceptable for EngineHome and BirtHome to be null if the runtime engine is already in your path.
As such, my issue is that when building with maven, it is not sufficient just define the the birt runtime in your pom.xml. There are a number of jar files which are not automatically included in the build and are otherwise not found in the WSO2 environment.
To this end, I've thus far added tidy to my pom.xml file, and added the following jar files to my WSO2_HOME/repository/components/dropins folder:
com.lowagie.text_2.1.7.v201004222200.jar
icu4j-54_1_1.jar
mysql_connector_java_5.1.26_bin_1.0.0.jar
org.apache.batik.bridge_1.6.0.v201011041432.jar
org.apache.batik.css_1.6.0.v201011041432.jar
org.apache.batik.dom.svg_1.6.0.v201011041432.jar
org.apache.batik.dom_1.6.0.v201011041432.jar
org.apache.batik.ext.awt_1.6.0.v201011041432.jar
org.apache.batik.parser_1.6.0.v201011041432.jar
org.apache.batik.pdf_1.6.0.v201105071520.jar
org.apache.batik.svggen_1.6.0.v201011041432.jar
org.apache.batik.transcoder_1.6.0.v201011041432.jar
org.apache.batik.util.gui_1.6.0.v201011041432.jar
org.apache.batik.util_1.6.0.v201011041432.jar
org.apache.batik.xml_1.6.0.v201011041432.jar
org.eclipse.datatools.connectivity.oda_3.4.3.v201405301249.jar
org.w3c.css.sac_1.3.0.v200805290154.jar
org.w3c.dom.smil_1.0.0.v200806040011.jar
org.w3c.dom.svg_1.1.0.v201011041433.jar
org.wso2.carbon.logging.propfile_1.0.0.jar
I've also found it necessary to put the following line of code prior to the Platform.startup(config) statement:
// The following line is required in wso2:
// http://stackoverflow.com/questions/13241045/why-doesnt-websphere-like-birt
RegistryProviderFactory.releaseDefault();
Platform.startup(config);
I am now successfully generating reports in the WSO2 environment. With that said, I am sure of the following:
Additional missing jar files will likely be found as I build out more reports
Some of the jar files I manually added to the wso2 dropins folder may be replaced with additional pom.xml dependencies
So more trial and error to come. But for now, am successfully generating reports in WSO2.
Related
Modular components for Liferay portal provided as OSGi modules use non standard Maven layout. All JSP pages are located in /src/main/resources/META-INF/resources instead of typical /src/main/webapps. Moreover, jar packaging is used instead of typical war. When such a project is opened in NetBeans, no errors or warnings are shown in JSP file even it is broken deliberately.
Example project can be found here https://github.com/liferay/liferay-blade-samples/tree/7.1/maven/apps/jsp-portlet
Can I somehow configure NetBeans to process my JSP files as usual?
NetBeans source code revealed there is some support for non-standard locations via the configuration of maven-war-plugin. So this plugin has to be present even not needed for the build:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<warSourceDirectory>/src/main/resources/META-INF/resources</warSourceDirectory>
</configuration>
</plugin>
My apps on Heroku use a DATABASE_URL. This is simple to parse with Java into a JDBC URL with a user name and password. There's no issue there. However, I have a JOOQ generator and Flyway migrator that have maven plugins and I can't figure out how to get the JDBC URL, User Name, and Password that these plugins require into maven. So currently I do it on app startup which is not ideal. When my app starts I get the DATABASE_URL, parse it, then do the flyway migration and jOOQ code generation. But I would like this to happen during the actual build process, not during application startup.
Basically I need the Heroku Environment variable formatted like (postgres://user:pass#ec2-host:1234/path-to-db) to be accessible in maven as a property like this (jdbc:postgresql://ec2-host:1234?user=user&password=pass).
I think the solution may lie with the maven build helper plugin but I can't get the regex properties specification quite right.
Thanks
I have solved this thanks to heroku support. Lukas and Axel you may want to document this for any of your users that are using heroku, want to run your tools in their build (vs code startup), and do not want to hand maintain different environment variables.
We will be using the GMavin Plus Plugin to run some code to parse the DATABASE_URL environment variable into properties prior to running the flyway migration or jOOQ code generation.
First off you need to add Groovy as a dependency:
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.3.9</version>
<scope>compile</scope>
</dependency>
Then the GMaven plus plugin:
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
</execution>
</executions>
<configuration>
<scripts>
<script><![CDATA[
URI dbUri = new URI(System.getenv("DATABASE_URL"));
String username = dbUri.getUserInfo().split(":")[0];
String password = dbUri.getUserInfo().split(":")[1];
int port = dbUri.getPort();
String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ":" + port + dbUri.getPath();
project.properties['database.jdbcUrl']=dbUrl
project.properties['database.username']=username
project.properties['database.password']=password
]]></script>
</scripts>
</configuration>
</plugin>
Now you can use ${database.jdbcUrl}, ${database.username}, and ${database.password} in your flyway, jOOQ, or whatever else configurations.
There are probably myriad ways to solve this with Maven, but one option is to keep a single properties file in your /src/main/resources path, load it using the properties-maven-plugin (an example can be seen in the jOOQ-Spring example), and then compose URLs using the individual parts, e.g. jOOQ and Flyway:
<url>jdbc:postgresql://${db.host}:${db.port}/${db.database}</url>
<user>${db.username}</user>
<password>${db.password}</password>
Heroku:
<database_url>postgres://${db.username}:${db.password}#${db.host}:${db.port}/${db.database}</database_url>
I have an application that needs to integrate with one of SharePoint's web services. This web service cannot be accessed freely and needs authentication.
As such, the standard wsdl2java Maven plugin in my application gives an HTTP 401 error when the generate-sources phase is executed.
Is there a way to setup Maven/POM so that I can provide a user/password that will generate the stubs?
I have come across some answers saying this is not possible but all answers are older than 1 year. I haven't found if Maven have issued an update on this. One option is to save a local copy of the WSDL (as suggested here) but I would like to avoid having local copies.
Because you mentioned CXF then I suppose you meant cxf-codegen-plugin. It's a bit of a hack but it works.
HTTP authentication credentials can be provided using java.net.Authenticator. One need to just define his own Authenticator class which overrides getPasswordAuthentication(..) method. Then it has to be set as default Authenticator. As far as I know it can't be done declaratively (for instance using environment properties) only programatically using Authenticator.setDefault(..).
In order to call Authenticator.setDefault(..) I would use CXF extension mechanism. Create separate maven project with similar class:
public class AuthenticatorReplacer {
public AuthenticatorReplacer(Bus bus) {
java.net.Authenticator.setDefault(new java.net.Authenticator() {
#Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("test", "test123"
.toCharArray());
}
});
}
}
and file src\main\resources\META-INF\cxf\bus-extensions.txt with contents:
org.example.AuthenticatorReplacer::false
Then add newly created project as a dependency to cxf-codegen-plugin:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${project.version}</version>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>cxf-authenticator-replacer</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
...
</plugin>
This way AuthenticatorReplacer is initialized by CXF extension mechanism and replaces default Authenticator with ours.
An clean alternative to #Dawid Pytel's solution would be to run this class during lifecycle of wsdl class auto generation:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>path.to.AuthenticatorReplacer</mainClass>
</configuration>
</plugin>
Important: your AuthenticatorReplacer has to be a main(String[] args) class and running the code inside.
I verified that Dawid's solution works. Alternatively, you can use SoapUI to pull down and cache the wsdl and then use SoapUi code generation support to use cxf to generate the code.
http://java.dzone.com/tips/generating-client-java-code
Dawid's solution works for me too. It is a little tricky though. In Eclipse, the pom.xml keeps complaining that "wsdl2java failed: Could not load extension class AuthenticatorReplacer". You have to ignore this error message and use the command line:
mvn generate-sources
The Java classes will then be generated successfully.
I thought this was simple, but having problems:
Project1 is of type war. It creates an entire webapp .war file, including some Apache modules (solr/lucene), and some of our custom code.
Project2 is an existing application. It needs to launch embedded Jetty to do queries against Project1's war file. (see code below)
Main Problem:
When Project2 instantiates Jetty, it needs to pass in the full path to the WAR file, but this changes each time. Maven adds version number stuff to Project1's war file.
Assemblies to the Rescue?
I'm able to get a custom assembly to work, but can't get rid of the versioning stamp from Project1.
But I always wind up with Project1-1.4.1-20120530.233546-2.war. It's in a more convenient place, but the name is still weird.
Jetty code in Project2:
// Context
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
String jettyHome = System.getProperty( "jetty.home", ".." );
String fullWarName = ...; // Project1's WAR file. This path always changes
webapp.setWar( fullWarName );
// Server
Server server = new Server( kPort ); // TODO: get from config
server.setHandler(webapp);
server.start();
server.join();
Other considerations:
I realize there is a maven-jetty plugin, but I don't believe that's appropriate here. It seems to be targeted at Unit tests, and also our application stack doesn't use maven at runtime to launch services.
I'm also aware that Solr has a fully embedded version that doesn't require a web container, but that's been deprecated for a while and not a good idea to use.
Is there a better way to refactor this project? Maybe this isn't "the maven way" ?
It turns out I didn't need an assembly (advice I had got internally), instead there's something easier in the main pom. Also, having the war unpacked here turned out to be a nice idea.
At the top of Project1's pom.xml I have:
<groupId>com.my.group</groupId>
<artifactId>project-one</artifactId>
<version>1.2.3-SNAPSHOT</version>
<packaging>war</packaging>
This goes near the bottom of Project2's pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-webapp</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.my.group</groupId>
<artifactId>project-one</artifactId>
<version>1.2.3-SNAPSHOT</version>
<type>war</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/webapps/project-one</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
Then when launching Jetty I have:
webapp.setWar( "target/webapps/project-one" );
I still think there might be issues with some Jetty settings, but I think this is the right direction.
Applications built on top of the NetBeans platform have a <myappdir>/etc/<myapp>.conf file determining, among other things, application JVM parameters. Historically, this file was a part of the NetBeans IDE installation (as far as I could tell), but starting with NB 6.9, custom files are now supported.
I am having trouble packaging a custom configuration file using Maven to build the application.
I imagine the app.conf property should have been set in the project's pom under project/build/pluginManagement/plugins like so:
<plugin>
...
<configuration>
<brandingToken>${brandingToken}</brandingToken>
<cluster>${brandingToken}</cluster>
<appConf>myapp.conf</appConf>
</configuration>
The maven module representing my application contained no prior source, so I created the src/main/nbm folder and placed myapp.conf in src/main/nbm. This isn't picked up by nbm-maven-plugin. and putting the conf file into src/main/resources doesn't make a difference.
So, can anyone explain how a NetBeans Platform application with a custom configuration file can be built using maven?
UPDATE:
With Tim's prod in the right direction, I found the answer documented on Geertjan's blog. The solution is to configure the nbm-maven-plugin like so in the application module pom:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>nbm-maven-plugin</artifactId>
<configuration>
<etcConfFile>src/main/resources/my.conf</etcConfFile>
</configuration>
</plugin>
</plugins>
</build>
BTW, if you need a second name with Geertjan, you're not really a NetBeans platform developer. ;)
Have a look at the documentation of the nbm:cluster-app plugin, specifically the part on the conf file.
As per my understanding that should allow you to replace the default one with a custom one that you create.