How to configure Oracle Data source JNDI in a Pivotal TC server? - jndi

I am working on an application that is configured on jdk 1.7
It uses JNDI to get connection with the Oracle DataSource.
I believe the JNDI name is not bound to server.
The line:
DataSource ds = (DataSource) ServiceLocator.getinstance().getDataSource(jndiName); // jndiName = "jdbc/myDB"
looks for the JNDI name in 'cache' and if not found looks it up in 'initialContext'. But it gets null from both Maps.
The error that I am facing is:
JNDI Name not found.
I have tried the following steps to solve this:
Added < resource-ref > in the application web.xml file as below -
< resource-ref >
< description > MySQL Datasource example< / description >
< res-ref-name > jdbc/myDB < /res-ref-name >
< res-type>javax.sql.DataSource< /res-type >
< res-auth>Container
< /resource-ref >
Added the < Resource > tag in server.xml file of the server as below -
< Context >
< Resource name="jdbc/myDB" auth="Container" type="javax.sql.DataSource" maxActive="50" maxIdle="30" maxWait="10000" username="mysqluser" password="mysqlpassword" driverClassName=" oracle.jdbc.xa.client.OracleXADataSource " url="jdbc:mysql://localhost/myDB"/ > < / Context >
Changed the first line mentioned above to:
DataSource ds = (DataSource) ServiceLocator.getinstance().getDataSource("java:comp/env/jdbc/myDB");
Added ojdbc14.jar to the server's lib folder
What should be the next approach to solve this?

For (3) Do not use ojdbc14.jar, it is very old. Use ojdbc7.jar from the latest 12.1.0.2 version. You can download it from here.

Related

Liquigraph schema files missing?

We have a service in our site that uses neo4j for the database. Today when I tried to load up the service for development the project bombs out. I'm getting errors like this:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquigraph' defined in class path resource [org/liquigraph/spring/starter/LiquigraphAutoConfiguration$LiquigraphConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException:
cvc-elt.1: Cannot find the declaration of element 'changelog'.
and this:
2021-08-02 14:43:41.516 WARN 9650 --- [ restartedMain] o.l.core.io.xml.ChangelogParser : XSD validation warning : schema_reference.4: Failed to read schema document 'http://www.liquigraph.org/schema/1.0/liquigraph.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
in my terminal.
I went to the site listed in the error and it doesn't work. There is also this one which is pretty similar but gives a 404.
our pom.xml file lists this for liquigraph:
<!-- https://mvnrepository.com/artifact/org.liquigraph/liquigraph-spring-boot-starter -->
<dependency>
<groupId>org.liquigraph</groupId>
<artifactId>liquigraph-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
In researching the project I saw something about running it "offline" or something. How can I get the project to load with the XSD files missing?
This should be fixed now.
I just deployed a new version of the website and misconfigured a couple of things (wrong CNAME file location, wrong schema files location).
https://www.liquigraph.org/schema/1.0/liquigraph.xsd and http://www.liquigraph.org/schema/1.0/liquigraph.xsd should work fine now.
More recent releases of Liquigraph also support schema location redirects such as the latest 3.x and 4.x. Make sure to upgrade!

quartz.properties not loaded in grails app's embedded jetty

I've enabled jdbcStore in QuartzConfig
quartz {
jdbcStore = true
autoStartup = true
}
and provided quartz.properties in grails-app/conf directory:
...
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
...
The problem is that when I run grails in local dev environment with grails rA those properties are ignored and I get an exception:
Caused by: org.quartz.JobPersistenceException: Couldn't store trigger 'RebillJobSimpleTrigger' for 'com.payment.rebill.RebillJob' job:Bad value for type long : \xaced00057.....
at org.quartz.impl.jdbcjobstore.JobStoreSupport.storeTrigger(JobStoreSupport.java:1241)
at org.quartz.impl.jdbcjobstore.JobStoreSupport$5.execute(JobStoreSupport.java:1147)
at org.quartz.impl.jdbcjobstore.JobStoreSupport$40.execute(JobStoreSupport.java:3670)
at org.quartz.impl.jdbcjobstore.JobStoreCMT.executeInLock(JobStoreCMT.java:242)
In live environment everything works ok, however I'm unable to run the project in embedded jetty.
Elaboration:
The exception is thrown because my custom quartz.properties are ignored (Thus instead of PostgreSQLDelegate the StdJDBCDelegate is used which is unable to read BLOB from DB).
I use quartz grails plugin version 0.4.2 which contains empty grails-app/conf/quartz.properties and I think there is some class loader issue which loads this empty file instead of my own quartz.properties file.
Looking into the plugin the properties file is configured in QuartzGrailsPlugin.groovy's spring bean:
quartzScheduler(SchedulerFactoryBean) {
configLocation = "classpath:quartz.properties"
...
(There is some spring bean builder magic which converts the "classpath:quartz.properties" String to spring's Resource class, since SchedulerFactoryBean's configLocation property is of type Resource).
When I debug the initialization on line 554 of SchedulerFactoryBean the configLocation leads to empty file despite my quartz.properties are not empty.
When I manually change the quartz spring bean to read file from different location everything works:
quartzScheduler(SchedulerFactoryBean) {
configLocation = "classpath:data/quartz.properties"
...
However I can't change the quartz plugin itself. Do you have any idea how to fix this locally ?
I use grails version 2.1.2

java.lang.LinkageError: "javax/activation/DataHandler"

So, I recently upgraded our Grails app from version 1.3.7 to 2.3.4. I'm now getting an exception in a SOAP handler that attempts to extract the message content and log it to the DB. This worked in 1.3.7, but I'm assuming that some new dependency or something has messed with the classpath.
The code looks like this:
private String extractSOAPMessage(SOAPMessageContext smc) {
Source source = smc.getMessage().getSOAPPart().getContent()
TransformerFactory factory = TransformerFactory.newInstance()
Transformer transformer = factory.newTransformer()
transformer.setOutputProperty( OutputKeys.METHOD, "xml" )
java.io.StringWriter writer = new StringWriter()
Result result = new StreamResult( writer )
transformer.transform( source, result )
return writer.toString()
}
The exception I'm seeing is:
Caused by: java.lang.LinkageError: loader constraint violation: loader (instance of <bootloader>) previously initiated loading for a different type with name "javax/activation/DataHandler"
It happens on this line:
Source source = smc.getMessage().getSOAPPart().getContent()
It looks like the culprit is the getSOAPart() call.
Note that I am using the 1.1.1 version of the cxf plugin for Grails. Any help on this would be greatly appreciated. I've found several similar issues with solutions, but none of them have been for the "javax/activation/DataHandler", so I am not sure what's going on here.
I suspect something has a transitive dependency on the activation library which you need to exclude - try running a dependency-report. Since Java 6 that JAR has been un-necessary as it's built in to the core Java class library, but many things still have dependencies on it so they can work on Java 5 (or date back to when Java 5 was still in widespread use).

Using Grails 1.3.7 with EclipseLink 2.2.0 JPA Provider

I try to use Grails 1.3.7 with plugin gorm-jpa 0.7.1 to enable JPA persistence using EclipseLink 2.2.0 as a persistence provider.
When running the app and clicking on the controller of a JPA annotated entity I get an "UnwantedTokenException" from JPQLParser of EclipseLink:
Executing action [list] of controller [model.PersonController] caused exception:
An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing the query [select person from model.Person as person ], line 1, column 24: syntax error at [.].
Internal Exception: UnwantedTokenException(found=., expected 80);
at org.eclipse.persistence.internal.libraries.antlr.runtime.BaseRecognizer.recoverFromMismatchedToken(BaseRecognizer.java:587)
[...]
at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.parse(JPQLParser.java:134)
It seems that EclipseLink has a problem with the dot in "model.Person".
How to solve this issue?
To reproduce the issue setup a grails project as follows:
grails create-app GrailsJPA
cd GrailsJPA
grails uninstall-plugin hibernate
grails install-plugin gorm-jpa
grails create-domain-class model.Person
Edit "grails-app\domain\model\Person.groovy" as follows:
package model
import javax.persistence.*;
#Entity
class Person {
#Id
#GeneratedValue
long id;
#Basic
long version;
#Basic
String firstName
#Basic
String lastName
static constraints = {
firstName(nullable:true)
lastName(nullable:true)
}
}
Generate controller and view for the defined entity:
grails generate-controller model.Person
grails generate-view model.Person
Edit "grails-app\conf\spring\resources.groovy" as follows:
beans = {
entityManagerFactory(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) {
beanClassLoader = ref("classLoader")
dataSource = ref("dataSource")
loadTimeWeaver = new org.springframework.instrument.classloading.SimpleLoadTimeWeaver()
}
transactionManager(org.springframework.orm.jpa.JpaTransactionManager) {
entityManagerFactory = entityManagerFactory
}
}
Create a file "web-app\WEB-INF\classes\META-INF\persistence.xml" as follows:
<?xml version="1.0" encoding="UTF-8"?>
<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_1_0.xsd" version="1.0">
<persistence-unit name="manager" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>model.Person</class>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
Download EclipseLink 2.2.0 installer ZIP from http://www.eclipse.org/eclipselink/downloads/2.2.0 and extract "eclipselink.jar" from "eclipselink\jlib\" in ZIP to grails project dir:
lib\eclipselink.jar
Now run the grails application:
grails run-app
Browse to
http://localhost:8080/GrailsJPA
Now click on controller "model.PersonController" to reproduce the above exception.
Any ideas on how to resolve this issue?
I managed to get EclipseLink 2.3.0 JPA provider to work with domain classes that are not inside a package in the following way.
In the following I will show how to setup a grails application that is using EclipseLink as a JPA provider to persist domain classes and run the application in a Tomcat 6 web container.
Start by
creating a new grails project
uninstall the default hibernate plugin
install the gorm-jpa plugin which enables gorm-like behaviour on top of JPA
create a new domain class "Person" for testing
grails create-app GrailsJPA
cd GrailsJPA
grails uninstall-plugin hibernate
grails install-plugin gorm-jpa
grails create-domain-class Person
Hint: Do not put domain classes in packages. EclipseLink will fail when processing e.g. "model.Person" because of the dot in the name, but will do fine with e.g. "Person" (compare to above post).
Edit "grails-app\domain\Person.groovy" as follows:
import javax.persistence.*;
#Entity
class Person {
#Id
#GeneratedValue
long id;
#Basic
long version;
#Basic
String firstName
#Basic
String lastName
static constraints = {
firstName(nullable:true)
lastName(nullable:true)
}
}
Generate a controller and a view for the defined entity:
grails generate-controller Person
grails generate-view Person
Now we need to modify the generated controller slightly, so that all actions modifying the entity (save, edit, update, delete) are encapsulated in a transaction (compare to bug GPGORMJPA-6). This is done by encapsulating the whole action into a "Person.withTransaction" block.
Edit "grails-app\controllers\PersonController.groovy" as follows:
[...]
def save = {
Person.withTransaction {
[...original code stays in this block...]
}
}
[...]
def edit = {
Person.withTransaction {
[...original code stays in this block...] }
}
}
def update = {
Person.withTransaction {
[...original code stays in this block...]
}
}
def delete = {
Person.withTransaction {
[...original code stays in this block...]
}
}
[...]
Now we define a persitence unit "manager" that specifies a set of classes to manage persistence for (class "Person") and which JPA provider to use for these classes (in our case EclipseLink).
Create a file "web-app\WEB-INF\classes\META-INF\persistence.xml" as follows:
<?xml version="1.0" encoding="UTF-8"?>
<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_1_0.xsd" version="1.0">
<persistence-unit name="manager" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>Person</class>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
Please note: The file will be deleted if "target" dir of project is cleaned, e.g. when "grails clean" is called explicitly. So it's a good idea to make a backup of the file outside of the "target" dir.
To make EclipseLink available to the grails project, download EclipseLink 2.3.0 installer ZIP and extract "eclipselink.jar" from "eclipselink\jlib\" in ZIP to "lib" folder of grails project:
lib\eclipselink.jar
Now we need to make sure, that an "entityManagerFactory" and "transactionManager" bean are created when the web application is started. The beans will provide the needed access to the JPA provider that will manage all the persistency.
Edit "grails-app\conf\spring\resources.groovy" as follows:
beans = {
entityManagerFactory(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) {
dataSource = ref("dataSource")
beanClassLoader = ref("classLoader")
loadTimeWeaver = new org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver()
}
transactionManager(org.springframework.orm.jpa.JpaTransactionManager) {
entityManagerFactory = entityManagerFactory
}
}
Please note that we specified a special loadTimeWeaver in the above declarations, that enables the JPA persistence provider to hook into java bytecode on the fly during runtime. When using EclipseLink this is essential. If just using org.springframework.instrument.classloading.SimpleLoadTimeWeaver for testing purposes, this enables the web app to start, but when accessing JPA entities you will encounter exceptions like "0 is not a known entity type", as the persistence provider is unable to hook into the management of the entity classes at runtime.
The use of InstrumentationLoadTimeWeaver is a bit of a hassle, as it will only work, if
the java virtual machine executing the web app server is started using "spring-agent" java agent, AND
our web app is loaded by the Tomcat server using a special classloader named "TomcatInstrumentableClassLoader"
To achieve this, first download spring-agent-2.5.6.SEC02.jar and spring-instrument-tomcat-3.0.5.RELEASE.jar.
Assume that you have installed Tomcat server in directory %CATALINA_HOME%.
Copy the downloaded jar files "spring-agent-2.5.6.SEC02.jar" and "spring-instrument-tomcat-3.0.5.RELEASE.jar" to %CATALINA_HOME%\lib
Now we modify "%CATALINA_HOME%\bin\catalina.bat" that is used by e.g. the start and stop scripts of Tomcat to make sure the JVM executing Tomcat runs with the "spring-agent" java agent.
Add the following to "%CATALINA_HOME%\bin\catalina.bat" in section "Execute The Requested Command" after all the echos:
if exist "%CATALINA_HOME%\lib\spring-agent-2.5.6.SEC02.jar" set JAVA_OPTS=%JAVA_OPTS% -javaagent:%CATALINA_HOME%\lib\spring-agent-2.5.6.SEC02.jar
When Tomcat is started, the script will now check if "spring-agent-2.5.6.SEC02.jar" is in the lib dir, and if this is the case, it will add it as the java agent to the JAVA_OPTS that are used as command line parameters to the JVM when starting Tomcat.
To enable the "TomcatInstrumentableClassLoader" as class loader for our web application we add the file "web-app\META-INF\context.xml" to our grails project, with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
</Context>
Please note that the tags in "context.xml" are case sensitive. So do not try to change <Context> to <context> (or similar things) - this will fail!
Before we package and deploy our web application, we define which datasource to use for persistency. For testing, we just define a HSQLDB in-memeory database.
Edit "grails-app\conf\DataSource.groovy" as follows:
[...]
development {
dataSource {
dbCreate = "create-drop"
url = "jdbc:hsqldb:mem:testDB"
}
}
test {
dataSource {
dbCreate = "create-drop"
url = "jdbc:hsqldb:mem:testDb"
}
}
production {
dataSource {
dbCreate = "create-drop"
url = "jdbc:hsqldb:mem:testDB"
}
}
[...]
Now we are ready to create a WAR archive of our web app using:
grails war
The WAR will be placed in the "target" directory of our project.
In "%CATALINA_HOME%\webapps"
create a directory "GrailsJPA"
extract all contents of the created WAR archive into this directory
Please note: Do not place WAR in "%CATALINA_HOME%\webapps" and hope that it is deployed on startup of Tomcat. This will fail!
Now start the Tomcat server using script
"%CATALINA_HOME%\bin\startup.bat"
After Tomcat is up and running, use your browser to browse to
http://localhost:8080/GrailsJPA
Now click on controller "PersonController" to create, update, list and delete Person entities via JPA using EclipseLink JPA provider.
But using domain classes that are inside of a package will still fail with the exception mentioned in the above post. This issue is still unresolved.
Download links
Grails 1.3.7
http://grails.org/Download
EclipseLink 2.3.0
http://www.eclipse.org/eclipselink/downloads/2.3.0
Tomcat 6
http://tomcat.apache.org/download-60.cgi
spring-instrument-tomcat-3.0.5.RELEASE.jar
http://mvnrepository.com/artifact/org.springframework/spring-instrument-tomcat
spring-agent-2.5.6.SEC02.jar
http://mvnrepository.com/artifact/org.springframework/spring-agent

Grails: I can't use ws-client plugin

I'm using grails 1.3.6 and installed ws-client plugin.
I getting error in the following hello world:
def wsdlURL = "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL"
def proxy = webService.getClient(wsdlURL)
def result = proxy.CelsiusToFahrenheit(0)
result = "${result} degrees Farhenheit"
render result
Error:
Could not initialize class
com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl
But I have this class (Ctrl+Shift+T in STS find the class)
Thanks.
Related question: here
I removed another plugin (gsolr) that had conflicts and works.
Note: another solution is create a plugin project to wrap ws-client plugin.
(I this way there is no conflict beetween classes)

Resources