Friday, January 23, 2015

openshift tomcat7 realm

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"

<web-app>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Entire Application</web-resource-name>
            <url-pattern>/protected/*</url-pattern>
        <!-- If you list http methods, only those methods are protected -->
<http-method>DELETE</http-method>
         <http-method>GET</http-method>
         <http-method>POST</http-method>
<http-method>PUT</http-method>
      </web-resource-collection>
      <auth-constraint>
         <!-- Anyone with one of the listed roles may access this area -->
<role-name>ROLENAME</role-name>
         <role-name>Administrator</role-name>
         <role-name>Power User</role-name>
         <role-name>User</role-name>
         <role-name>View Only</role-name>
      </auth-constraint>
    </security-constraint>

    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>My Password-Protected Web Application</realm-name>
        <login-config>
            <form-login-page>/loginForm.jsp</form-login-page>
            <form-error-page>/loginError.jsp</form-error-page>
        </login-config>
    </login-config>


<error-page>
  <exception-type>javax.servlet.ServletException</exception-type>
  <location>/error.htm</location>
</error-page>
<error-page>
  <error-code>500</error-code>
  <location>/test.jsp</location>
</error-page>


</web-app>



<Realm className="org.apache.catalina.realm.JDBCRealm"
        connectionURL="jdbc:mysql://localhost/stealth6_stealthtrader?user=stealth6&amp;password=gbury26"
        driverName="com.mysql.jdbc.Driver"
        roleNameCol="role_name"
        userCredCol="user_pass"
        userNameCol="user_name"
        userRoleTable="user_roles"
        userTable="users"/>


Thursday, January 15, 2015

Simple Eclipse Maven Hibernate Setup

create a JPA project using

pom.xml

<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>[4.2.6,4.2.9]</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.18.1-GA</version>
</dependency>
</dependencies>


src/hibernatecfg.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>
  <!--  Database connection settings  -->
  <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
  <property name="connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
  <property name="connection.username">csfox</property>
  <property name="connection.password">password</property>
  <property name="dialect">org.hibernate.dialect.OracleDialect</property>
  <!--  Echo all executed SQL to stdout  -->
  <property name="show_sql">true</property>
  <!--  Drop and re-create the database schema on startup  -->
  <property name="hbm2ddl.auto">create-drop</property>
  <mapping class="hibernate.Message"/>
 </session-factory>
</hibernate-configuration>

sample java table

@Entity
public class MyTable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    Long id;
    @Column(nullable = false)
    String value;

run java 
        Configuration configuration = new Configuration();
        configuration.configure();
        ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder();
        serviceRegistryBuilder.applySettings(configuration.getProperties());
        ServiceRegistry serviceRegistry = serviceRegistryBuilder.buildServiceRegistry();
        SessionFactory factory = configuration.buildSessionFactory(serviceRegistry);
Session session = factory.openSession();
        Transaction tx = session.beginTransaction();
        session.persist(object);
        tx.commit();
 List<MyTable > list = (List<MyTable>) session.createQuery(
            "from MyTable").list();
        session.close();


Tuesday, January 13, 2015

Simple Quick Struts2 Eclipse Project Setup

quick notes for simple eclipse struts2 project


new project ->other ->maven ->maven-archetype-webapp

The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

add facet runtime server

<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.20</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.3.20</version>

</dependency>

<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-tiles3-plugin</artifactId>
<version>2.3.15.1</version>
</dependency>


web.xml

<!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>Archetype Created Web Application</display-name>
<filter>
<filter-name>StrutsPrepareAndExecuteFilter</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>StrutsPrepareAndExecuteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

struts.xml

<struts>
<constant name="struts.devMode" value="true" />
<package name="default" extends="struts-default" namespace="/">
<action name="index">
<result>/index.jsp</result>
</action>
</package>
</struts>

forward

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<s:property value="name" />