(Geoevent) How can I put a depedency in a custom processor?

4938
4
01-08-2015 04:30 AM
RafaelDetoni
New Contributor

Hello everyone,

 

       I would like to know how can I make to put the ojdbc6.jar(oracle) in a custom maven project of a processor in geoevent?

 

       The oracle drive in maven have license and is impossible to get the jar in a open maven repository, just local! Because of that I followed this post bellow and worked, but when I exported the maven project to a jar and put it in Geoevent the dependency not work properly!

 

Post link

http://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/

 

I tried to collocate the jar in this directory bellow to see if works, but was in vain

C:\Program Files\ArcGIS\Server\GeoEvent\system\com\oracle\ojdbc6

C:\Program Files\ArcGIS\Server\GeoEvent\sdk\repository\com\oracle\ojdbc6

 

I really appreciate any help!

 

In attached is the repository placed in ojdbc directory and pom.xml

0 Kudos
4 Replies
BrunoMendes
Occasional Contributor

I'm facing the exact same problem.

Please update the discussion if you have found an answer.

0 Kudos
VladislavPlechnoy
New Contributor III

There are two things here that I believe we need to take care of:

At processor build time dependency on ojdbc6 needs to be added to the project maven pom file.

Here is how this might work:

First, issue maven command to install your jar

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file \

-Dfile=<path-to-file> -DgroupId=com.oracle \

                         -DartifactId=ojdbc6 -Dversion=11.2.0

Next, declare it like any other dependency in your processor pom file:

<dependency>

<groupId>com.oracle</groupId>

<artifactId>ojdbc6</artifactId>

<version>11.2.0</version>

</dependency>

At processor deploy time this dependency needs to be added to karaf container that GeoEvent runs inside. The easiest way to achieve this is to build a so-called uberjar that wraps 3rd party dependency inside.

Here is how we usually achieve that:

<?xml version="1.0"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

   <modelVersion>4.0.0</modelVersion>

   <groupId>group-id</groupId>

   <artifactId>artifact-id</artifactId>

   <version>version</version>

   <packaging>pom</packaging>

   <name>Your-component-name</name>

   <url></url>

   <properties>

      <contact.address>you@company.com</contact.address>

      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

      <maven.bundle.plugin.version>2.3.6</maven.bundle.plugin.version>

   </properties>

   <dependencies>

      <dependency>

         <groupId>com.esri.geoevent.sdk</groupId>

         <artifactId>geoevent-sdk</artifactId>

         <version>10.3.0</version>

      </dependency>

      <dependency>

         <groupId>com.oracle</groupId>

         <artifactId>ojdbc6</artifactId>

         <version>11.2.0</version>

      </dependency>

   </dependencies>

   <build>

      <pluginManagement>

         <plugins>

            <plugin>

               <groupId>org.apache.felix</groupId>

               <artifactId>maven-bundle-plugin</artifactId>

               <extensions>true</extensions>

               <version>${maven.bundle.plugin.version}</version>

               <configuration>

                  <instructions>

                     <Embed-Dependency>ojdbc6;scope=compile|runtime;inline=true</Embed-Dependency>

                  </instructions>

               </configuration>

            </plugin>

            <plugin>

               <groupId>org.apache.maven.plugins</groupId>

               <artifactId>maven-compiler-plugin</artifactId>

               <version>2.5.1</version>

               <configuration>

                  <source>1.7</source>

                  <target>1.7</target>

               </configuration>

            </plugin>

         </plugins>

      </pluginManagement>

   </build>

</project>

In addition:

Once you get your uberjar built, you may also need to modify your code somewhat from traditional JDBC code.  Due to way Class Loaders work within GeoEvent's container (OSGi based Karaf), you cannot use the traditional method to acquire a Connection (DriverManager.getConnection). Instead, you'll need to instantiate the Driver class with code like the following:

Driver oDriver = new OracleDriver();

String url = ...

Properties props = new Properties();

//set properties

Connection conn = oDriver.getConnection(url, props);

This is all I have to share for now.

Please try these steps and let us know if they help.

Thanks!

0 Kudos
BrunoMendes
Occasional Contributor

Thanks Vladislav for sharing your solution but it didn't work for me.

When I tried to deploy my custom Transport to GeoEvent/deploy folder, the module raised the following exception: missing requirement [477.0] package; (package=com.sun.security.auth.module)

I've noticed that this and other dependencies from ojdbc6.jar we're added to IMPORT-PACKAGE entry in META-INF/MANIFEST.MF file. And to solve it I would have to add every dependency to my uberjar. Plus, I think it would violate Oracle Licence Agreement if I did explode ojdbc jar contents in my uberjar.

What worked for me was:

1. install ojdbc jar in Karaf;

mvn install:install-file -Dfile=[driver path]/ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

2. create a DataSource and deploy it to Karaf;

<?xml version="1.0" encoding="UTF-8"?>

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

  <bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">

      <property name="URL" value="[connection string]"/>

      <property name="user" value="[user]"/>

      <property name="password" value="[pass]"/>

  </bean> 

  

<service interface="javax.sql.DataSource" ref="dataSource">

  <service-properties>

   <entry key="osgi.jndi.service.name" value="jdbc/oracleds"/>

   <entry key="datasource.name" value="OracleDS"/>

  </service-properties>

</service>

</blueprint>

3. reference the DataSource in OSGi blueprint config.xml:

<reference id="dataSource" interface="javax.sql.DataSource" filter="(osgi.jndi.service.name=jdbc/oracleds)" />

My reference was this link: Oracle Datasource in Fuse ESB / Apache Karaf | Sachin Handiekar

0 Kudos
BrunoMendes
Occasional Contributor

Ok, now the project is built and deployed successfully. But there is one last problem to solve.

Whenever the code that gets a connection is called I get this error: "INVALID CONNECTION :Invalid Oracle URL specified".

Even using the complete form jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=[hostname])(PORT=[port])))(CONNECT_DATA=(SERVICE_NAME=[service]))) the same error occurs.

I've tested the URL in a simple java project and it connects successfully, so I'm sure it is a valid URL.

No clue on how to solve this.

I've found this documentation about datasources in Apache Karaf: Apache Karaf 3.0.3-SNAPSHOT Guides

The problem is that even after running features:install jdbc in GeoEvent console, the commands jdbc:* are not recognized. Because running jdbc:list I would be able to check if the parameters of the deployed datasource are the same GeoEvent is trying to use.

0 Kudos