Service activation in OSGI results in Time out - osgi

Using a blueprint.xml, I am trying to create a jndi service for datasource and having a reference in the same bundle.The datasource service is not activated and the reference fails after certain time and results in time out.
Also, when the reference of service is commented in the blueprint, the service gets activated.
Is there a way I can handle the activation of the service with its reference also present in the same bundle.
<service id="zDS" interface="javax.sql.DataSource" ref="zOltpDataSource">
<service-properties>
<entry key="osgi.jndi.service.name" value="jdbc/zDS"/>
</service-properties>
</service>
<bean id="zDao"
class="com.h.h.common.dao.ZDaoImpl">
<property name="dataSource" ref="dataSource" />
</bean>
<reference id="dataSource" interface="javax.sql.DataSource"
filter="(osgi.jndi.service.name=jdbc/zDS)">
</reference>
<bean id="zOltpDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${z.driverClassName}"/>
<property name="url" value="${z.url}"/>
<property name="username" value="${z.username}"/>
<property name="password" value="${z.password}"/>
<property name="initialSize" value="${z.initialSize}"/>
<property name="maxIdle" value="${z.maxIdle}"/>
<property name="maxActive" value="${z.maxActive}"/>
<property name="validationQuery" value="${z.validationQuery}"/>
<property name="testOnBorrow" value="${z.testOnBorrow}"/>
</bean>

A Blueprint container will not initialise until all of its mandatory dependencies are satisfied: see Initialization of a Blueprint Container from the Blueprint Specification.
Therefore you cannot use a <reference> to a service that is only published from the same container, because there is effectively a circular dependency. Of course your container will start if there is a matching DataSource service from another bundle.
You shouldn't need to refer to the service, however. Just inject the zOltpDataSource bean directly into the zDao bean as follows:
<bean id="zDao"
class="com.h.h.common.dao.ZDaoImpl">
<property name="dataSource" ref="zOltpDataSource" />
</bean>

Related

Store variables out of the bundle in osgi

I have one question about blueprint in OSGI Bundles. I bundle activiti in one, but there are some configurations that have to be made in the blueprint to get it work. i don't want to compile the bundle new for every time I change those settings. is it possible to store them out out the blueprint to change it needing only to restart the bundle?
<bean id="configuration" class="org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration"
ext:field-injection="true">
<property name="databaseType" value="h2"/>
<property name="dataSource" ref="dataSource"/>
<property name="transactionManager" ref="transactionManager"/>
<property name="databaseSchemaUpdate" value="true"/>
<property name="transactionsExternallyManaged" value="true"/>
<property name="defaultCamelContext" value="defaultContext"/>
<property name="mailServerHost" value="smtp.googlemail.com"/>
<property name="mailServerUsername" value="xxxx"/>
<property name="mailServerPassword" value="xxxx"/>
<property name="mailServerPort" value="465"/>
<property name="useSSL" value="true" />
<property name="useTLS" value="true" />
<property name="mailServerDefaultFrom" value="senderadress"/>
</bean>
thank you so much!
In OSGi you use the configuration admin spec for your configs. In Apache Karaf it allows to store configs in files in the etc directory.
To inject them into blueprint you use the blueprint-cm namespace.
See this tutorial how to use it.

JBPM 5.4 LocalTaskService scope in Spring

I am using JBPM 5.4.0.Final with Spring 3.0.6
I am using local task service.
What should be the scope of org.jbpm.task.service.local.LocalTaskService if it is declared as a spring bean ? Can it be a singleton ?
tasks-context.xml:
<bean id="internalTaskService" class="org.jbpm.task.service.TaskService">
<property name="systemEventListener" ref="systemEventListener" />
</bean>
<bean id="htTxManager" class="org.drools.container.spring.beans.persistence.HumanTaskSpringTransactionManager">
<constructor-arg ref="transactionManager" />
</bean>
<bean id="springTaskSessionFactory" class="org.jbpm.task.service.persistence.TaskSessionSpringFactoryImpl" init-method="initialize"
depends-on="internalTaskService">
<property name="entityManagerFactory" ref="jbpmEMF" />
<property name="transactionManager" ref="htTxManager" />
<property name="useJTA" value="true" />
<property name="taskService" ref="internalTaskService" />
</bean>
<bean id="taskService" class="org.jbpm.task.service.local.LocalTaskService" depends-on="springTaskSessionFactory">
<constructor-arg ref="internalTaskService"></constructor-arg>
</bean>
The question is, how many instances do you need. If you have just one client of that application you can just create it singleton, it shouldn't affect the behavior. Let us know if you have any troubles with it.
Cheers

How can i get a Spring managed SessionCustomizer into the EclipseLink Config

I'm working with eclipselink in a spring project. one necessary part of my configuration is a SessionCustomizer that configures my id-generator (Snowflake by twitter).
Is it possible to handle the creation of this customizer with spring so i can use dependency injection and use property-placeholders?
The only examples i found for Customizers always configure the class in the persistence xml.
Here is my config so far:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="platform.auth-service" />
<property name="jpaDialect" ref="jpaDialect" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="jpaPropertyMap" ref="jPAPropertyProviderMap" />
</bean>
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="generateDdl" value="${database.generateTables}" />
<property name="databasePlatform" value="${database.platform}" />
</bean>
<bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
While the #Configurable Annotation from spring-aop (AspectJ integration) would have been a solution i decided to solve my problem with a static SequenceHolder class where i store the sequences with a SequenceInstaller bean.
Finally the SessionCustomizer installs the stored sequences in the persistencecontextfactory.
I had to configure a dependency between the factory and the installer because spring might have handled the factory before the installer otherwise.

Hibernate (JPA,JSF 2.0, Spring) switch from HyperSQL to Oracle - Configuration is being ignored

i'm currently in the process of working on a midsized Webproject, using JSF 2.0 with Spring.As IDE i use Eclipse with JBoss Tools. The Webapp is deployed to a Tomcat v7.0 Server.
I use Hibernate/JPA/C3P0/ to connect to the Database (previously HyperSQL) I now tried to switch to an Oracle DB, which i did a number of times before and it never was a problem, however now it seems, that the changed configuartion is just being ignored. When i fire up the Server, it still uses the HyperSQl Driver and the old DB, although i cleaned the workdirectory of Tomcat, removed and redeployed the Webapp (which i built from scratch of course).
The project is split in two, one webapp and one service part. The project are dependent in Eclipse. However, although all of the businesslogic is implemented in the service layer, i can just remove it and the webapp doesn't throw an error and i can start it as if nothing has changed. This tells me that it must be cached somewhere and it is not refreshed on the server...I also deleted the server, added a freshly downloaded instance - still the same thing...Does anyone have an Idea what this could be about?
Here is my service.spring.xml:
<!-- Enable processing of #PersistenceContext and #PersistenceUnit -->
<context:annotation-config/>
<!-- Enable transaction configuration with #Transactional -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- Configure a c3p0 pooled data source -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="user"/>
<property name="password" value="password"/>
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/>
<property name="jdbcUrl" value="jdbc:oracle:thin:#dburl"/>
<property name="initialPoolSize" value="1"/>
<property name="minPoolSize" value="1"/>
<property name="maxPoolSize" value="10"/>
</bean>
<!-- Configure the JPA entity manager factory with Hibernate -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="false"/>
<property name="database" value="ORACLE"/>
<property name="generateDdl" value="true"/>
</bean>
</property>
<property name="persistenceUnitName" value="mygourmet"/>
</bean>
<!-- Configure transaction manager for JPA -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
And my persistence.xml:
<persistence-unit name="mygourmet" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
<property name="hibernate.use_sql_comments" value="false" />
<property name="hibernate.connection.autocommit" value="false" />
<property name="hibernate.cache.use_query_cache" value="false" />
<property name="hibernate.cache.use_second_level_cache" value="false" />
<property name="hibernate.hbm2ddl.auto" value="create" />
</properties>
I used the exact same configuration on another project and it works like a charm...Any hints are highly appreciated, thank you guys in advance!
Problem solved - i did a mvn clean install, generated new eclipse projects and imported them back into eclipse. It seems the changes in my service module were not recognized by eclipse.

Error upon integrating JNDI with Spring

This was my first attempt at Spring with JNDI but getting the below mentioned exception when trying to create the ApplicationContext like:
ApplicationContext context = new ClassPathXmlApplicationContext("master-job.xml");
The Spring configuration file is as follows:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="/jdbc/Eqpstatus"/>
<property name="resourceRef" value="true" />
</bean>
<bean id="masterDao" class="com.dao.MasterDao">
<property name="dataSource" ref="dataSource"/>
</bean>
On Server i have the required resource entry for the JNDI name.
<Resource auth="Container" driverClassName="oracle.jdbc.OracleDriver"
maxActive="10" maxIdle="2" maxWait="10000" name="jdbc/Eqpstatus"
password="xxxx" type="javax.sql.DataSource"
url="jdbc:oracle:thin:#(DESCRIPTION=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=xxxx) (PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=xxxx) (PORT=1521))(CONNECT_DATA=(SERVICE_NAME=xyz)))"
username="xxx"/>
The error i see is:
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
Would highly appreciate any inputs on this as am new to Spring-JNDI integration.
First, I think you should use the dedicated tag instead of declaring a "JndiObjectFactoryBean" bean :
<!-- JNDI DataSource for J2EE environments -->
<jee:jndi-lookup id="dataSource" jndi-name="java:jdbc/rppsDS-PUB-PROTO" default-ref="localDataSource" />
<!-- local dataSource for JUnit integration tests -->
<bean id="localDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="maxActive" value="100"/>
<property name="maxWait" value="1000"/>
<property name="poolPreparedStatements" value="true"/>
<property name="defaultAutoCommit" value="true"/>
</bean>
Then, you need a jndi.properties file (which could be directly in application server dir such as JBoss) with a content similar to :
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:1099
If you are using Tomcat and everything is fine with your Tomcat configuration; this should be enough:
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/dataSource" />
Where jdbc/dataSource is the name defined in your Tomcat config.
EDIT:
My bad, forgot about the jndi.properties; there are two possibilities:
either provide a jndi.properties on your classpath or
set the values in a in the <jee:jndi-environment/> element of <jee:jndi-lookup /> (see reference)
The java.naming.factory.initial property needs to be set for sure, to something like org.apache.naming.java.javaURLContextFactory, possibly some other values as well, like:
java.naming.factory.url.pkgs=org.apache.naming
java.naming.factory.url.pkgs.prefixes=org.apache.naming
java.naming.provider.url=org.apache.naming
Also see reference.

Resources