SQLException: Illegal connection port value ${env.OPENSHIFT_MYSQL_DB_PORT} - database

I am trying to deploy a fairly basic Spring+Hibernate web app to my newly created app. (I am new to openshift).
I have followed this example from the knowledge base.
But after deploying the application i am getting
..
java.sql.SQLException: Illegal connection port value '${env.OPENSHIFT_MYSQL_DB_PORT}'
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2018)
..
I have defined the datasource in my applicationcontext.xml
This is the section in my applicationContext.xml that I define the deta shource (eli is the database name)
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="jdbc:mysql://${env.OPENSHIFT_MYSQL_DB_HOST}:${env.OPENSHIFT_MYSQL_DB_PORT}/eli" p:username="${jdbc.username}"
p:password="${jdbc.password}"/>
Any idea what I am doing wrong?
Thanks

The error you're receiving seems to indicate that the property replacement strings in your Spring XML configuration aren't actually being processed by Spring. You can add a PropertyPlaceholderConfigurer to your configuration to enable processing from the system environment:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="searchSystemEnvironment" value="true" />
...
</bean>

Related

Config file Ignite discovery in zeppelin, config xml not working even after IgniteConfiguration bean is present

I am using zookeeper based discovery for ignite cluster and ignite nodes are getting properly connected.
When i am setting same config.xml file in zeppelin ignite interpreter in , I am not able to run the ignite. it fails with below exception.
It gives me below error on zepplin:
Failed to find configuration in: file:////tmp/shared.xml
Failed to find configuration in: file:////tmp/shared.xml
Exception details: please click this link
ignite_client.xml i am using:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="clientMode" value="true"/>
<property name="peerClassLoadingEnabled" value="false"/>
<property name="discoverySpi">
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="ipFinder">
<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.zk.TcpDiscoveryZookeeperIpFinder">
<property name="zkConnectionString" value="zookeeper:2181"/>
</bean>
</property>
</bean>
</property>
<property name="cacheConfiguration">
<list>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="testcache"/>
<property name="startSize" value="10"/>
</bean>
</list>
</property>
</bean>
I saw the Ignite code and found that its failing because spring bean is not found of type IgniteConfiguration, but in xml it is actually present as can be seen in shared xml above.
Analysis so far
Debugged zeppelin and Ignite code and verified correct xml file is passed to ignite.start
Verified even content of file tobe double sure by reading inputStream and file content is correct , inputStream is from org.springframework.beans.factory.xml.XmlBeanDefinitionReader#loadBeanDefinitions(org.springframework.core.io.support.EncodedResource)
On further debug verified that beanDefinitionMap in ApplicationContext contains IgniteConfiguration, attaching snapshot
Tried getting bean by name , it works ... instead of cfgMap = springCtx.getBeansOfType(cls); in org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl#loadConfigurations(java.net.URL, java.lang.Class, java.lang.String...)
For sake of trial I used sprintContext.getBean(), assuming it would run, but its getting weired , I got below class cast exception
After analysis so far, only thing I can understand is some how IgniteConfiguration loaded by diff classloader is causing issue, but dont know why its happening
Debugged further and confirmed, it is because IgniteConfiguration loaded by different class loader, one loaded already was from sun.misc.Launcher.AppClassLoader#AppClassLoader and in sprinContext IgnitConfiguration bean present is loded by scala.reflect.internal.util.ScalaClassLoader and that is why the error "Failed to find configuration in: file:////tmp/shared.xml"
Logically I can think it as spark program is scala code and spring bean loaded at runtime that is why this mismatch
Is this normal ?
I tried your configuration and it works for me. Did you have another version of the file before? If so, I think it was not updated properly, because the only way to get this exception is having valid Spring XML file, but without IgniteConfiguration bean.
Are you sure you actually use the correct file? Can this be caused by the fact that you have it in /tmp folder?

Jboss RestEasy web service connection pooling

Getting error
NoSuchMethodError: org.apache.http.impl.conn.DefaultClientConnectionOperator.(Lorg/apache/http/conn/scheme/SchemeRegistry;Lorg/apache/http/conn/DnsResolver;)
Using httpclient-4.2-alpha1.jar
Configuration :
<!-- Rest easy connection pooling -->
<bean id="poolingClientConnectionManager" class="com.auction.acp.rest.impl.ConnectionManager" >
</bean>
<bean id="httpClient" class="org.apache.http.impl.client.DefaultHttpClient" >
<constructor-arg name="conman" ref="poolingClientConnectionManager"> </constructor-arg>
</bean>
When I explore jar this constructor is already there.
First thing which is coming in my mind is some other library [I'm using JBoss] is in use.
Tried with exclusions in jboss-deployment-structure.xml but no luck.
<exclusions>
<module name="org.apache.httpcomponents" />
<module name="org.apache.http.impl.conn" />
</exclusions>
If the constructor exists in the JAR you're "exploring" but JBoss can't find it, it means JBoss is not using the JAR you want it to. I suggest using Logback for logging, as it'll add the name of the JAR to the stacktrace in your logs so you know which JAR JBoss is using.

Why does Persistence.createEntityManagerFactory("transactions-optional") errors when appengine is deployed

I have created an appengine which runs fine and returns records from my Google cloud SQL db in debug mode. When I deploy the appegine and run the endpoint it errors. And the error I get in the appengine log is:
Caused by: org.datanucleus.exceptions.NucleusUserException: There is no available StoreManager of type "jdbc". Make sure that you have put the relevant DataNucleus store plugin in your CLASSPATH and if defining a connection via JNDI or DataSource you also need to provide persistence property "datanucleus.storeManagerType".
Here is a list or the jars in war\WEB-INF\lib directory:
appengine-api-1.0-sdk-1.7.6
appengine-api-labs
appengine-endpoints
appengine-jsr107cache-1.7.6
asm-4.0
com.sun.tools.xjc_2.2.0
com.sun.xml.bind_2.2.0.v201004141950
datanucleus-api-jdo-3.1.3
datanucleus-api-jpa-3.1.3
datanucleus-appengine-2.1.2
datanucleus-core-3.1.3
eclipselink
eclipselink-jpa-modelgen_2.4.1.v20121003-ad44345
gcm-server
geronimo-jpa_2.0_spec-1.0
javax.activation_1.1.0.v201108011116
javax.mail_1.4.0.v201005080615
javax.persistence_2.0.4.v201112161009
javax.xml.bind_2.2.0.v201105210648
javax.xml.stream_1.0.1.v201004272200
jdo-api-3.0.1
json_simple-1.1
jsr107cache-1.1
jta-1.1
org.eclipse.persistence.jpars_2.4.1.v20121003-ad44345
Here is my persistence.xml:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">
<persistence-unit name="transactions-optional" transaction-type="RESOURCE_LOCAL">
<provider></provider>
<class>com.example.myapp.Class1</class>
<class>com.example.myapp.Class2</class>
<properties>
<property name="datanucleus.NontransactionalRead" value="true"/>
<property name="datanucleus.NontransactionalWrite" value="true"/>
<property name="javax.persistence.jdbc.driver" value="com.google.appengine.api.rdbms.AppEngineDriver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:google:rdbms://something.com:someproj:someapp/somedb"/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.password" value=""/>
</properties>
</persistence-unit>
</persistence>
Using:
cloud sql
JPA
Datanucleous v2
SDK 1.7.6
Jre7
As it works fine in debug mode I dont understand what the problem might be as I am new to appengine. Please let me know if you need more information.
Thanks guys.
Make your mind up which JPA provider you're using ... for Cloud SQL (not AppEngine, so you don't need "datanucleus-appengine", nor do you need "datanucleus-api-jdo" either FWIW). You have DataNucleus JPA (version 3 actually, but omitting datanucleus-rdbms jar for some reason, yet CloudSQL needs it), and you have EclipseLink also. You then don't set the persistence provider in persistence.xml so leave it all to chance which one it tries to give you ... and it tries DataNucleus JPA but you haven't included the datanucleus-rdbms jar so you can't persist to an RDBMS without that.

Cloud Foundry + JPA + Spring + EntityManager

I want to deploy a Web based WAR into CloudFoundry using a cloud datasource.
I have defined a bean like this:
<cloud:data-source id="dataSource"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="myPersistenceUnit" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="generateDdl" value="true"/>
</bean>
</property>
</bean>
</beans>
....but when i try to deploy I obtain a Java Agent exception :
Cannot apply class transformer without LoadTimeWeaver specified
But i can't specfy a Java Agent whithout uploading a jar instrument agent.....
Any solution??
I'm not that familiar with EclipseLink, so I'm not even sure that the weaver requirement comes from EclipseLink, BUT
One way of doing this would be to deploy your app as a standalone app (i.e. deploy your own tomcat around it), that way you can put the extra weaver jar in lib/.
Have a look at http://blog.cloudfoundry.org/2012/06/18/deploying-tomcat-7-using-the-standalone-framework/ and https://github.com/ericbottard/cloudfoundry-tomcat-7
Also, if you only have one DataSource, you can avoid using the cloudfoundry-specific <cloud:datasource /> namespace by just uploading your regular app and have Cloud Foundry auto reconfigure your app (info here: http://blog.springsource.org/2011/11/04/using-cloud-foundry-services-with-spring-part-2-auto-reconfiguration/) As a matter of fact, this may be the way to have EclipseLink work seamlessly on Cloud Foundry (my guess here)
And of course, there's also the option of switching to another provider that doesn't require class instrumentation, but that's a bit extreme.
Again, I'm not an Eclipse Link guru, so I may be missing something here...

JPA entity manager factory creation failing; JBoss, Hibernate and SQL Server

Running JBoss 5.1, with Hibernate as the JPA provider. Backed with SQL Server 2008.
I'm receiving an error at server startup, which is java.lang.ClassCastException: org.hibernate.dialect.SQLServerDialect cannot be cast to org.hibernate.dialect.Dialect. Pretty clear message, but I'm baffled as to the underlying cause. I have hibernate-core-3.5.1-Final.jar on the classpath, and the necessary class files are present.
This dialect setting was giving no error in the project when it was being used as a property being passed to a Spring AnnotationSessionFactoryBean, but I'm trying to refactor a piece to straight EJB/JPA. For what it's worth, here's my persistence config:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">
<persistence-unit name="[my name here]">
<jta-data-source>java:jdbc/[my name here]</jta-data-source>
<properties>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" />
</properties>
</persistence-unit>
I hate these kind of "here's my config and my stacktrace" questions, but I've been poking around on this for an hour and a half and am failing to come up with any new ideas.
The ClassCastException is caused by having two copies of the javax.persistence APIs in your system. When running on JBoss, you are just not supposed to package persistence jar in your application. Remove all the persistence related jar's from your application and the exception should go away.

Resources