PostgreSQL as datasource for WSO2 EI and APIM+IS - postgresql

I faced with problem when I've set up PostegreSQL as master datasource for clusterization.
Sometimes I see hanged sessions from WSO2 components which lock objects in database. Because of this arise inactive scheduled tasks, problems with auth, etc.
Could you help me please with configuration of PostgreSQL? I guess I have to specify some session timeout property or something other parameter.
Below part of configuration for connection to PostgreSQL:
<configuration>
<url>jdbc:postgresql://xxx.xxx.xxx.xxx:xxxx/yyyy_db</url>
<username>username</username>
<password>password</password>
<driverClassName>org.postgresql.Driver</driverClassName>
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<testOnBorrow>true</testOnBorrow>
<validationInterval>30000</validationInterval>
<defaultAutoCommit>true</defaultAutoCommit>
</configuration>
Kind Regards,
Kirill Levitskiy

I found the solution.
There should be changed 'testOnBorrow' to false. It is nessesary, because I've removed ValidationQuery and InitValidation options before, but forgot about testOnBorrow.
Database configuration should look like this:
<configuration>
<url>jdbc:postgresql://xxx.xxx.xxx.xxx:xxxx/yyyy_db</url>
<username>username</username>
<password>password</password>
<driverClassName>org.postgresql.Driver</driverClassName>
<maxWait>60000</maxWait>
<testOnBorrow>false</testOnBorrow>
<validationInterval>30000</validationInterval>
<defaultAutoCommit>true</defaultAutoCommit>
</configuration>

Related

How to enable failover for a postgresql jdbc data source

I have a data source defined in a Liberty application server for postgresql
<dataSource jdbcDriverRef="PostgreSQLDriver" ...>
<properties password="..." user="admin" serverName="server" portNumber="2020" databaseName="dbname" ssl="false"
</dataSource>
I see that I can enable failover on a jdbc connection by specifying a url like:
jdbc:postgresql://host1:port,host2:port,host3:port/dbname
Is there any way that this failover url can be provided to a application server datasource?
Yes, you can specify any key/value pair on the <properties> element and Liberty will supply it to the vendor data source class. In this case, the property would be URL="jdbc:postgresql://host1:port,host2:port,host3:port/dbname"
Also, note that in more recent versions of Liberty, there is a properties.postgresql which is specific to Postgres and better documents the available settings for it.
Here is an example,
<dataSource jdbcDriverRef="PostgreSQLDriver" ...>
<properties.postgresql password="..." user="admin" URL="jdbc:postgresql://host1:port,host2:port,host3:port/dbname" ssl="false"
</dataSource>

getting setting from web.config in sitecore

i want to get global setting from web.config file in sitecore solution,
i write setting in config file and able to see it's entry in showconfig. when i try to get it's value, it is not giving appropriate value. my code is like this:
var newsBodyTemplateID = Sitecore.Configuration.Settings.GetSetting("NewsBody");
when i evaluate this, it giving this message:
what i'm missing here can some figure out it.
First of all I don't recomment to add in web.config your settings. If you want to upgrade your Sitecore than you have to merge manually your web.config.
If you still want to add setttings in web.config you need to have something like :
<configuration>
.....
<appSettings>
<add key="YourSeetings" value="your value" />
...
</appSettings>
.....
</configuration>
From C# code you need to use
ConfigurationManager.AppSettings["YourSeetings"]
If you have your settings on section /configuration/sitecore/settings
you need to use from C# code :
Sitecore.Configuration.Settings.GetSetting("yoursettingsname");
Your config file will looks like :
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore>
<!-- General settings -->
<settings>
<setting name="YourSettingsFieldName" value="{1EPR25B2-98C6-45BF-B9E4-824ECAAEF499}" />
</settings>
</sitecore>
</configuration>
That method will return settings from the Sitecore\Settings node. there is another method to get AppSettings.
Sitecore.Configuration.Settings.GetAppSetting()

JBoss EAP 6 configure single server for remote debugging in domain mode

I have Domain controller, one Host controller and one server running in the same machine.
I'm using IDEA to connect to the remote server for debugging but it's not stopping on break points even though it's running the code (i've verified with system outs).
I've enabled HOST_CONTROLLER_JAVA_OPTS and PROCESS_CONTROLLER_JAVA_OPTS for remote debugging in $JBOSS_HOME/bin/domain.conf:
# Sample JPDA settings for remote socket debuging.
PROCESS_CONTROLLER_JAVA_OPTS="$PROCESS_CONTROLLER_JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8788,server=y,suspend=n"
HOST_CONTROLLER_JAVA_OPTS="$HOST_CONTROLLER_JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
When i start JBoss server i can see from netstat that it's properly listening to ports 8787 and 8788. If i list the processes running in the system i can see one for Domain controller, one for Host controller and one for the server (server1). Domain and Host controllers have the debug options specified in their launch properties but they're missing for server1.
I've been looking at the various XML, .conf and .sh files for a while now but i can't figure out how i could specify server1 to use the remote debugging options. Is there a way to remotely debug a single server in domain mode?
JHollanti maybe you are missing some compiler flags (like "lines,vars,source") to allow remote debugging.
For example, is you are using Ant you need to add this lines to your javac:
<!-- Javac lines, vars, source compiler flags -->
<javac srcdir="..." destdir="..." classpathref="..." debug="true" debuglevel="lines,vars,source" />
Then in your execution script you jave to add:
<!-- debug configurations: modify the port you want-->
<jvmarg value="-Xdebug"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=4060"/>
On the other hand, if you are using Maven same flags can be added in the , like this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<!-- Necessary in order for the debug levels to be considered-->
<debug>true</debug>
<debugLevel>lines,vars,source</debugLevel>
</configuration>
</plugin>
</plugins>
</build>
In case of using Jetty, same as before... you need to have the following variable:
export MAVEN_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n"
On the other hand, what you can check is setting the suspend flag in yes, it is "suspend=y". This won't start your app unless you connect a debugger.
Here you can check specific info about jboss:
http://webdev.apl.jhu.edu/~jcs/ejava-javaee/coursedocs/605-784-site/docs/content/html/devenv-jboss-setup.html#enable-jboss-debug
Hope to help
Hey I don't have a solution to this however I was able to set the port for server one along with host and process controllers as well.
How I did it : I added the "-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n" to the JVM arguments on the jboss admin console.
Steps:
1) Login to admin console of jboss => localhost:9990/console
2) go to servers => select server 1 in the table.
3) Then add the debug string into JVM arguments text box.
Once you restart your server you'll see now the server one is listening on this port.
However problem came when I tried to run my eclipse in debug mode. Though on the sever I could see the connection was established through netstat however eclipse is not able to communicate to server 1 and it times out.
Important thing to be noticed is I'm able to run eclipse in debug mode if I do what you did in domain.conf file and use those ports; however then the control never comes to my breakpoint in eclipse.
You can enable remote debugging by adding jvm-options in $JBOSS_HOME$\domain\configuration\hosts.xml
Add the following configuration under <servers> -> <server> -> <jvm>
<jvm-options>
<option value="-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"/>
</jvm-options>
your server configuration in hosts.xml should look something similar to this
<servers>
<server name="Server1" group="Group1" auto-start="true">
<jvm name="Server1_JVM" debug-enabled="false">
<heap size="2048m" max-size="4096m"/>
<jvm-options>
<option value="-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"/>
</jvm-options>
</jvm>
<socket-bindings socket-binding-group="full-ha-sockets" port-offset="100"/>
</server>
</servers>
Hope this helps!

How to integrate the WSO2 Data Services 3.0 with Oracle 10g

We use Windows Server 8 with Oracle 10g (R 10.2.0.2).
We believe that the Oracle JDBC Jar is correct, we tested some possibilities.
The problem now when we tested the connection is: "provided data source type not supported".
Anybody have any suggestion?
Thanks so much!
I believe there must be an issue with your datasource configuration defined in master-datasources.xml or any other *-datasources.xml you are using in your environment. Please double check whether the following line is defined properly in your datasource configuration. All the RDBMS databases should be configured having the definition type as "RDBMS".
<definition type="RDBMS">
A complete sample datasource configuration for your requirement is depicted below.
<datasource>
<name>testds</name>
<description>The datasource used for registry and user manager</description>
<jndiConfig>
<name>jdbc/testds</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:oracle:thin:#localhost:1521:XE</url>
<username>test</username>
<password>test</password>
<driverClassName>oracle.jdbc.OracleDriver</driverClassName>
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT 1 FROM DUAL</validationQuery>
<validationInterval>30000</validationInterval>
</configuration>
</definition>
</datasource>
Hope this helps.
Regards,
Prabath

Aspectj compile time weaving based transactions not working (JPA from a WebService call)

I'm trying to use aspectj with compile time weaving to support annotations like Spring's #Transactional and #Configurable. I'm using the org.springframework.orm.jpa.JpaTransactionManager transaction manager and what I see in the logs when I try to call entityManager.persist(entity) in my GenericDAO is something like this:
insurance-module-0.1-SNAPSHOT 19:57:55.199 [http-bio-8084-exec-49] TRACE org.hibernate.loader.Loader - Bound [6] parameters total
insurance-module-0.1-SNAPSHOT 19:57:55.199 [http-bio-8084-exec-49] TRACE org.hibernate.loader.Loader - processing result set
insurance-module-0.1-SNAPSHOT 19:57:55.199 [http-bio-8084-exec-49] DEBUG org.hibernate.loader.Loader - result set row: 0
insurance-module-0.1-SNAPSHOT 19:57:55.199 [http-bio-8084-exec-49] TRACE o.h.t.descriptor.sql.BasicExtractor - found [1] as column [id3_]
insurance-module-0.1-SNAPSHOT 19:57:55.199 [http-bio-8084-exec-49] DEBUG org.hibernate.loader.Loader - result row: EntityKey[com.vendio.insurance.domain.db.InsuranceRate#1]
insurance-module-0.1-SNAPSHOT 19:57:55.199 [http-bio-8084-exec-49] TRACE org.hibernate.loader.Loader - done processing result set (1 rows)
insurance-module-0.1-SNAPSHOT 19:57:55.200 [http-bio-8084-exec-49] TRACE org.hibernate.loader.Loader - total objects hydrated: 0
insurance-module-0.1-SNAPSHOT 19:57:55.200 [http-bio-8084-exec-49] DEBUG o.h.e.StatefulPersistenceContext - initializing non-lazy collections
insurance-module-0.1-SNAPSHOT 19:57:55.200 [http-bio-8084-exec-49] TRACE org.hibernate.impl.SessionImpl - after transaction completion
insurance-module-0.1-SNAPSHOT 19:57:55.201 [http-bio-8084-exec-49] TRACE o.s.t.s.TransactionSynchronizationManager - Retrieved value [org.springframework.orm.jpa.EntityManagerHolder#5ec859c1] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#337cbe84] bound to thread [http-bio-8084-exec-49]
insurance-module-0.1-SNAPSHOT 19:57:55.209 [http-bio-8084-exec-49] DEBUG org.hibernate.SQL - select sequence_next_hi_value from hibernate_sequences where sequence_name = 'registered_policy' for update
insurance-module-0.1-SNAPSHOT 19:57:55.210 [http-bio-8084-exec-49] DEBUG org.hibernate.SQL - update hibernate_sequences set sequence_next_hi_value = ? where sequence_next_hi_value = ? and sequence_name = 'registered_policy'
insurance-module-0.1-SNAPSHOT 19:57:55.218 [http-bio-8084-exec-49] TRACE o.s.t.s.TransactionSynchronizationManager - Retrieved value [org.springframework.orm.jpa.EntityManagerHolder#5ec859c1] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#337cbe84] bound to thread [http-bio-8084-exec-49]
so the per-table hibernate sequence gets updated but my entity is not inserted into the database.
If I add entityManager.flush() an exception appears stating "no transaction is in progress".
What is going on here?!
My GenericDAO class looks like this:
public class GenericDAO<T extends Persistable> {
#PersistenceContext
protected EntityManager entityManager;
#PersistenceUnit
protected EntityManagerFactory entityManagerFactory;
#Transactional
public void saveOrUpdate(T entity) {
entityManager.persist(entity);
}
}
I call the saveOrUpdate method from a web-service exported with the WSSpringServlet.
P.S.: Also my Maven config looks like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<complianceLevel>1.6</complianceLevel>
<showWeaveInfo>true</showWeaveInfo>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
When compiling I get something which looks decent enough (my aspect gets applied):
Join point 'method-call(void javax.persistence.EntityManager.persist(java.lang.Object))'
in Type 'com.vendio.insurance.dao.GenericDAO' (GenericDAO.java:28)
advised by afterThrowing advice from 'org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect'
(spring-aspects-3.1.0.RELEASE.jar!JpaExceptionTranslatorAspect.class:14(from JpaExceptionTranslatorAspect.aj))
And my relevant Spring config is:
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<context:component-scan base-package="com.vendio.insurance" />
<context:spring-configured/>
<!-- <bean class="org.springframework.transaction.aspectj.AnnotationTransactionAspect" factory-method="aspectOf">
<property name="transactionManager" ref="transactionManager"/>
</bean>-->
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" />
So everything looks decent, but I can't find an answer of why this doesn't work...
I've found my answer following this link: http://forum.springsource.org/showthread.php?18953-DispatcherServlet-and-ContextLoaderListener.
The problem was caused by the fact that I was also using Spring MVC and I was creating without knowing two almost identical Spring contexts. Thus the transaction was managed by the transaction manager in the first context (the one receiving the JAX-WS call) but the entity manager I was calling was managed by the second context (with a different transaction manager).
The solution was to isolate the small reduced context definition for the DispatcherServlet and leave the rest of the beans to be managed by ContextLoaderListener:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/application-context.xml</param-value>
</context-param>
<servlet>
<servlet-name>spring-mvc-dispatcher-servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>2</load-on-startup>
<init-param>
<param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/servlet-context.xml</param-value>
</init-param>
</servlet>
Since I used annotation based MVC (with #Controller annotation) I also had to reduce the scope of the context:component-scan's base-package in the "servlet" context.
Below is the quote from the link that saved my day:
DispatcherServlet will always load its own configuration file using -servlet.xml. It is intended that this file will contain web components such as Controllers, ViewResolvers and LocaleResolvers - but no middle tier components.
The ContextLoaderListener is then used to load the files containing your middle tier and data tier components. Spring will merge all these components into an ApplicationContext making your middle tier components accessible from your web tier components. >Rob Harrop Lead Engineer, dm Server
If you use EntityManager you won't have to deal with any hibernate issues in your code.
That's exactly what jpa is for.
I had the same problem some time ago.
Your EntityManager has to be injected with #PersistenceContext. getEntityManager() won't do.
And your annotated functions have to be public.
so the per-table hibernate sequence gets updated but my entity is not inserted into the database.
I was experiencing the same symptom even though there was no problem of two identical Spring contexts. The forceAjcCompile option resolved the issue:
...
<java.version>1.6</java.version>
<aspectj.version>1.7.0</aspectj.version>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.6</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<outxml>true</outxml>
<showWeaveInfo>false</showWeaveInfo>
<verbose>false</verbose>
<complianceLevel>${java.version}</complianceLevel>
<forceAjcCompile>true</forceAjcCompile>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
<source>${java.version}</source>
<target>${java.version}</target>
<Xlint>ignore</Xlint>
</configuration>
</plugin>