OPENSHIFT + j_security_check problems - openshift

I have Java code with j_security_check that works on a local Tomcat + MySQL server. I am not able to get it working on the Openshift Jboss (Tomcat) cartridge.
----web.xml code snippet:----
<security-constraint>
<web-resource-collection>
<web-resource-name>Validate</web-resource-name>
<url-pattern>/user/*</url-pattern>
<http-method>POST</http-method>
<http-method>GET</http-method>
</web-resource-collection>
<!-- Authorize the service and programmer roles -->
<auth-constraint>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
<!-- Use form-based authentication to provide access -->
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/validation/login.jsp</form-login-page>
<form-error-page>/validation/login_error.jsp</form-error-page>
</form-login-config>
--------META-INF/context.xml:-----
<Context path="/musicStoreOTUser">
<Resource auth="Container"
driverClassName="com.mysql.jdbc.Driver"
logAbandoned="true"
maxActive="100"
maxIdle="30"
maxWait="10000"
name="jdbc/musicDB"
password="ask4_sgh"
removeAbandoned="true"
removeAbandonedTimeout="60"
type="javax.sql.DataSource"
url="jdbc:mysql://127.7.245.2:3306/mydb"
username="admin1234"/>
<Realm className="org.apache.catalina.realm.JDBCRealm"
connectionName="admin1234"
connectionPassword="ask4_sgh"
connectionURL="jdbc:mysql://127.7.245.2:3306/mydb"
dataSourceName="jdbc/musicDB"
debug="99"
driverName="com.mysql.jdbc.Driver"
roleNameCol="Rolename"
userCredCol="Password"
userNameCol="EmailAddress"
userRoleTable="RoleTable"
userTable="PassTable"/>
When I log in in the login form, I simply get Login incorrect. No messages are logged in the jbossews.log file.
Appreciate any thoughts.
Thanks,

Related

There was an error communicating with the database. Please contact the application administrator

i just running Bitnami Tomcat 8.5.24-2 in the google Cloud. and i need to connect to mysql and i do following as orbeon steps:
Create a new user orbeon with password orbeon and new schema orbeon.
Create the tables used for Orbeon Forms in the orbeon schema.
Download mysql-connector-java-5.1.33-bin.jar and copy it in xampp\tomcat\lib.
4 Edit Tomcat's server.xml, and within the for Orbeon Forms adding a <Resource>
auth="Container"
type="javax.sql.DataSource"
initialSize="3"
maxActive="10"
maxIdle="10"
maxWait="30000"
poolPreparedStatements="true"
testOnBorrow="true"
validationQuery="select 1"
username="orbeon"
password="orbeon"
url="jdbc:mysql://localhost:3306/orbeon?useUnicode=true&characterEncoding=UTF8"/>
and for Valve in same file
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log"
suffix=".txt"
pattern="%h %l %u %t "%r" %s %b"/>
<property as="xs:string"
name="oxf.fr.persistence.provider.orbeon.library.*"
value="mysql"/>
and on Orbeon properties-local.xml
<properties xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:oxf="http://www.orbeon.com/oxf/processors">
<property as="xs:string"
me="oxf.fr.persistence.provider.*.*.*"
value="mysql"/>
</properties>

web services.Error: com.mysql.jdbc.CommunicationsException: Communications link failure java.io.EOFException [duplicate]

My webapp is running on Tomcat 5.5, I declared the datasource in web.xml:
<resource-ref>
<res-ref-name>jdbc/OrdiniWebDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
In context.xml (tomcat conf):
<Resource
auth="Container"
driverClassName="com.mysql.jdbc.Driver"
maxActive="100"
maxIdle="30"
maxWait="10000"
name="jdbc/OrdiniWebDS"
password="[mypassword]"
type="javax.sql.DataSource"
url="jdbc:mysql://[myHost:port]/ordiniweb"
username="[myusername]"
/>
The database is a MySql 5.0.
Everything works well except that sometimes, after several hours of "unuse", at first access I got this Exception:
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.io.EOFException
STACKTRACE:
java.io.EOFException
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1956)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2368)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2867)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1616)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1708)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3255)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1293)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1428)
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
at com.blasetti.ordiniweb.dao.OrdiniDAO.caricaOrdine(OrdiniDAO.java:263)
...
** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago.
com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2579)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2867)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1616)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1708)
com.mysql.jdbc.Connection.execSQL(Connection.java:3255)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1293)
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1428)
org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
com.blasetti.ordiniweb.dao.OrdiniDAO.caricaOrdine(OrdiniDAO.java:263)
...
I need to refresh and it works well again. Any idea? Thanks.
MySQL drops unused connections after a while because it assumes that the other side forgot to close it.
What you need to do is to configure a check that Tomcat should apply before it reuses a pooled connection. To do this, add ?autoReconnect=true&useUnicode=true&characterEncoding=utf8 to the end of the URL and add validationQuery="Select 1" to the Resource element:
<Resource
auth="Container"
driverClassName="com.mysql.jdbc.Driver"
maxActive="100"
maxIdle="30"
maxWait="10000"
name="jdbc/OrdiniWebDS"
password="[mypassword]"
type="javax.sql.DataSource"
url="jdbc:mysql://[myHost:port]/ordiniweb?autoReconnect=true&useUnicode=true&characterEncoding=utf8"
username="[myusername]"
validationQuery="Select 1"
/>
[EDIT] This page gives more details: Configuring a MySQL Datasource in Apache Tomcat

How to configure Tapestry5, Hibernate, Tomcat7, JNDI, Mysql

I've been trying to figure out how to configure Tapestry5, Hibernate, Tomcat7, and Mysql, but have not been able to get it to work. Could someone possible tell me what I'm doing wrong?
To began with, Tapestry is already configured to work with hibernate and jetty without issue, I'm having difficulties setting up a connection pool with Tomcat7
What I have thus far.
MyApp Configuration
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.datasource">java:comp/env/jdbc/rolemanager</property>
<property name="hbm2ddl.auto">create</property>
<property name="hibernate.show_sql">false</property>
</session-factory>
</hibernate-configuration>
myapp/Web Pages/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>rolemanager Tapestry 5 Application</display-name>
<context-param>
<!-- The only significant configuration for Tapestry 5, this informs Tapestry
of where to look for pages, components and mixins. -->
<param-name>tapestry.app-package</param-name>
<param-value>com.mycompany.rolemanager</param-value>
</context-param>
<filter>
<filter-name>app</filter-name>
<filter-class>org.apache.tapestry5.TapestryFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>app</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<resource-ref>
<description>MyDatabase Description</description>
<res-ref-name>jdbc/rolemanager</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
Tomcat Configuration
Tomcat7/conf/server.xml
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
<Resource name="jdbc/rolemanager" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="test" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/rolemanager"/>
</GlobalNamingResources>
Tomcat7/conf/context.xml
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<!-- Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) -->
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
-->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<ResourceLink global="jdbc/rolemanager" name="jdbc/rolemanager" type="javax.sql.DataSource"/>
</Context>
Console Error
I'm getting the following console error.
SEVER: Parse error in application web.xml file at jndi:localhost/WEB-INF/web.xml
java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml addResourceRef
It appeared to be an issue with a dependency in my pom adding conflicting classes. I was able to remove the conflicting classes from my class path and fix resolve my issue.

Is this xml well formed for a context.xml?

I'm working out of Murach's Java servlets and JSP, chapter 14 on connecting to MySQL, which I am not able to do. I'm using Netbeans and Tomcat. If I try to run the code with the following context.xml file then the code won't run. It says
[Fatal Error] :3:2: The markup in the document following the root element must
be well-formed.
/Users/user/NetBeansProjects/LearnYou/nbproject/build-impl.xml:724:3
Deployment error: Tomcat configuration file /Users/user/NetBeansProjects/LearnYou/web/META-INF/context.xml seems to be broken. Please make sure it is parseable and valid.
If I comment out all but the first line then the code runs but never connects to MySQL.
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/projectname"/>
<Resource
name="jdbc/ULearniversity" auth="Container"
maxActive="100" maxIdle="50" maxWait="60000"
username="uName" password="password"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/MyDataBase?autoReconnect=true"
logAbandoned="true" removeAbandoned="true"
removeAbandonedTimeout="60" type="javax.sql.DataSource"
/>
</Context>
You're closing the Context tag immediately. Remove the / before the >.
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/projectname">
<Resource
name="jdbc/ULearniversity" auth="Container"
maxActive="100" maxIdle="50" maxWait="60000"
username="root" password="rootpassword"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/MyDataBase?autoReconnect=true"
logAbandoned="true" removeAbandoned="true"
removeAbandonedTimeout="60" type="javax.sql.DataSource"
/>
</Context>

Keep JDBC references outside web.xml to deploy in Jetty, like in tomcat

I try to move some services from my Tomcat Server to Jetty, just to make some comparisons. Obviously I don't want to change my services, but I experiment some issues to deploy them with JDBC.
My services all use the same database to access datas, so I wrote my own library to make my requests. The services don't have any informations about the database, they just know they have to use the library. In this library I make connections with the database using this kind of code:
InitialContext ictx = new InitialContext();
Context envCtx = (Context) ictx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/mysql");
In Tomcat my services work well just adding a line in context.xml:
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" maxActive="100" maxIdle="30" maxWait="10000" name="jdbc/mysql" username="login" password="password" type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/mysql" />
So I just want to do the same in Jetty. I added the following block in my jetty.xml:
<New id="mysql" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/mysql</Arg>
<Arg>
<New class="org.apache.commons.dbcp.BasicDataSource">
<Set name="driverClassName">com.mysql.jdbc.Driver</Set>
<Set name="url">jdbc:mysql://localhost:3306/mysql</Set>
<Set name="username">login</Set>
<Set name="password">password</Set>
</New>
</Arg>
</New>
The server starts well and seem to work, but I get an error when I try to access to my services. In jetty's manual I found it's explictly written that I have to add some informations in web.xml like:
<resource-ref>
<description>My DataSource Reference</description>
<res-ref-name>jdbc/DSTest</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
So I wonder if there is any other solution, than write the same lines in all my web.xml services' files? Like adding a common xml file for all my server with the same informations ?
You can add it to the webdefault.xml that is used as the foundation for processing web.xml.
This file is typically located in etc/webdefault.xml of the distribution.
cheers