This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

Clinton Morrison

Greenhorn
+ Follow
since Jun 28, 2007
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Clinton Morrison

I am receiving the following error javax.servlet.ServletException: PWC1232: Exceeded maximum depth for nested request dispatches: 20, when deploying a war to Glassfish v 3.0.1. When I reach the request dispatcher I seem to be stuck in a infinite loop. The code is as follows

web.xml



Contoller Servlet



log
11 years ago
Hi,
I am trying to set a variable that will allow me to skip execution of the maven-scm-plugin. Below is the snippet from my pom.xml, which is being used in my local Eclipse environment, I do not want a checkout each time the build runs. However I cannot find a way to skip this execution. I have tried using the <skip>true</skip> in various places. I cannot see where I am going wrong?

Regards
Clinton

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<executions>
<execution>
<id>common</id>
<phase>prepare-package</phase>
<configuration>
<skip>true</skip>
<connectionUrl>scm:vss|${vss.applications}|/application/${project.artifactId}/mainline/src</connectionUrl>
<developerConnectionUrl>scm:vss|${vss.applications}|/application/${project.artifactId}/mainline/src</developerConnectionUrl>
<workingDirectory>.\src\main\java</workingDirectory>
</configuration>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
11 years ago
I am trying to run the client below, but I am receiving the following error Exception in thread "main" javax.naming.NameNotFoundException: Greeter not bound. I have also tried using java:Greeter/remote and having a @EJB private static Greeter greeter variable. When I check the jmx-console I see the GreeterBean is bound. I am not sure where I am going wrong. I am running JBoss 5 and java 6. Is there another way to call the EJB?





jmx-console
12 years ago
When I try to run the batch script below it keeps failing. I am not sure were I am going wrong with my classpath as I have my log4j in the folder ${testing.lib}. Is there a better way to reference my classpath?

Thanks in advance
Clinton

JUNIT SCRIPT
[code]
<?xml version="1.0" encoding="UTF-8"?>
<project name="testing tier" default="report" basedir=".">
<property file="junit_build.properties" />

<target name="init">
<echo message="Clean the directory ${target.report.dir}" />
<delete dir="${target.report.dir}" />
<mkdir dir="${target.report.dir}" />
</target>

<target name="test" depends="init">
<echo message="Run the JUnit Tests in ${target.classes.test.dir}" />
<junit printsummary="yes" haltonerror="yes" haltonfailure="no" fork="yes">
<classpath>
<pathelement location="${common-nge}/bin" />
<pathelement location="${common-us}/bin" />
<pathelement location="${services}/bin" />
<pathelement location="${ts2-consumer}/bin" />
<pathelement location="${common-nge-fe}/bin" />
<pathelement location="${common-us-fe}/bin" />
<pathelement location="${services-fe}/bin" />
<pathelement location="${ts2-consumer-fe}/bin" />
<pathelement location="${testing.lib}" />
<pathelement location="${target.classes.test.dir}" />
</classpath>

<jvmarg value="-DclientConfig=C:/build-apps/us/COMMON-US/etc/config/" />
<jvmarg value="-DlazyLoadConfigs=true" />
<jvmarg value="-DconfigRefreshCheckInterval=0" />

<formatter type="plain" usefile="false" />
<formatter type="xml" />
<batchtest todir="${target.report.dir}" fork="yes">
<fileset dir="${src.test.dir}">
<include name="${tests}" />
<exclude name="${suites}" />
<exclude name="${cactus}" />
</fileset>
</batchtest>
</junit>
</target>

<target name="report" depends="test">
<mkdir dir="${target.report.dir}/html" />
<junitreport todir="${target.report.dir}">
<fileset dir="${target.report.dir}">
<include name="TEST-*.xml" />
</fileset>
<report todir="${target.report.dir}/html" />
</junitreport>
</target>
</project>
[code]

ERROR MESSAGE
Buildfile: C:\build-apps\us\UnitTestTier\junit_build.xml
init:
[echo] Clean the directory report
[delete] Deleting directory C:\build-apps\us\UnitTestTier\report
[mkdir] Created dir: C:\build-apps\us\UnitTestTier\report
test:
[echo] Run the JUnit Tests in C:/build-apps/us/UnitTestTier/bin
[junit] Running com.tsys.common.config.TestAdvisorConfig
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.031 sec
[junit] Testsuite: com.tsys.common.config.TestAdvisorConfig
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.031 sec
[junit] Testcase: testRead took 0.015 sec
[junit] Caused an ERROR
[junit] org/apache/log4j/Priority
[junit] java.lang.NoClassDefFoundError: org/apache/log4j/Priority
[junit] at com.tsys.common.config.AdvisorConfig.read(AdvisorConfig.java:56)
[junit] at com.tsys.common.config.TestAdvisorConfig.testRead(TestAdvisorConfig.java:61)

BUILD FAILED
C:\build-apps\us\UnitTestTier\junit_build.xml:13: Test com.tsys.common.config.TestAdvisorConfig failed

Total time: 1 second
12 years ago
I am receiving the error below when trying to run my Test Case using cactus. How can I add my customized struts actionservlet without it throwing the exception? I am making the call to super.setUp() after i set my customized actionservlet.

Thanks
Clinton

properties



Test Case
/**
* The Class TestUsernameGeneralAction.
*/
public class TestUsernameGeneralAction extends CactusStrutsTestCase {

/** The action path. */
private static String ACTION_PATH = "/UsernameStep1";

/** The Struts config file name. */
private static String CONFIG_FILE_NAME = "/WEB-INF/struts-config-signon.xml";

/**
* Instantiates a new test username general action.
*
* @param name the name
*/
public TestUsernameGeneralAction(String name) {
super(name);
}

/* (non-Javadoc)
* @see servletunit.struts.MockStrutsTestCase#setUp()
*/
public void setUp() throws Exception {
GeneralActionServlet actionServlet = new GeneralActionServlet();
setActionServlet(actionServlet);
super.setUp();
setConfigFile(CONFIG_FILE_NAME);
setRequestPathInfo(ACTION_PATH);
}

/* (non-Javadoc)
* @see servletunit.struts.MockStrutsTestCase#tearDown()
*/
public void tearDown() throws Exception {
super.tearDown();
}

/**
* Test username general action.
*/
public void testUsernameGeneralAction() {
actionPerform();
verifyNoActionErrors();
verifyForwardPath("UsernameStep1");

}

ERROR MESSAGE
junit.framework.AssertionFailedError: You are overriding the setUp() method without calling super.setUp(). You must call the superclass setUp() and tearDown() methods in your TestCase subclass to ensure proper initialization.
at servletunit.struts.CactusStrutsTestCase.init(CactusStrutsTestCase.java:87)
at servletunit.struts.CactusStrutsTestCase.setActionServlet(CactusStrutsTestCase.java:498)
at com.tsysebs.commercial.businessprocess.forgotusername.TestUsernameGeneralAction.setUp(TestUsernameGeneralAction.java:54)
at junit.framework.TestCase.runBare(TestCase.java:128)
at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:155)
at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:120)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:94)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:218)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java:1)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:102)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:218)
at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java:1)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:73)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:218)
at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java:1)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
12 years ago
I am receiving the error below any ideas what I am doing wrong? I am using Jboss / eclipse / cactus. I have placed my cactus jars in C:\jboss-eap-4.3\jboss-as\server\default\lib. Also placed my cactus.properties application /WEB-INF/classes and updated the web.xml accordingly. The error I am receiving is shown below.

Thanks in advance
Clinton

java.lang.NoSuchFieldError: config
at servletunit.struts.CactusStrutsTestCase.setUp(CactusStrutsTestCase.java:105)
at com.tsysebs.commercial.businessprocess.forgotusername.TestUsernameGeneralAction.setUp(TestUsernameGeneralAction.java:53)
at junit.framework.TestCase.runBare(TestCase.java:128)
at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:155)
at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:120)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:94)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:218)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java:1)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:102)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:218)
at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java:1)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:73)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:218)
at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java:1)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)

12 years ago
I was trying to use validations using Regular expressions. The first expression should only allow text in the value 01 - 07. The value must contain the '0' at the beginning. This expression works fine. The second expression should only allow text in the range 001 - 999. However the expression I have written allows 000 - 999. Do you know how I can not allow the value 000 but allow the rest of the expression? Using Struts 1.1.

Thanks in advance
Clinton

First Expression
<field property="rate" depends="required,mask">
<arg0 key="label.offermgmt.rate" />
<var>
<var-name>mask</var-name>
<var-value>^[0]{1}[1-7]{1}$</var-value>
</var>
</field>

Second Expression
<field property="optionSet" depends="required,mask">
<arg0 key="label.offermgmt.option" />
<var>
<var-name>mask</var-name>
<var-value>^[0-9]{1}[0-9]{1}[0-9]{1}$</var-value>
</var>
</field>
When using JBoss 4.2, mysql 5 and EJB 2.x I receive the following error Could not create entity
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'product_id' cannot be null. I cannot see where I am going wrong? What is making the product_id null and how can I correct this?

Thanks in advance


Test Client
package com.product.test;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.NamingException;

/**
* The Class TestClient.
*/
public class TestClient {

/**
* Gets the initial context.
*
* @return the initial context
*
* @throws NamingException
* the naming exception
*/
public static Context getInitialContext()
throws javax.naming.NamingException {
Properties p = new Properties();
p.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
p.setProperty("java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces");
p.setProperty("java.naming.provider.url", "localhost");
return new javax.naming.InitialContext(p);
}

/**
* The main method.
*
* @param args
* the arguments
*/
public static void main(String[] args) {
try
{
Context jndiContext = getInitialContext();
Object obj=jndiContext.lookup("ProductManagerHomeRemote");
com.javasrc.licenseserver.ejb.productmanager.ProductManagerHomeRemote home = (com.javasrc.licenseserver.ejb.productmanager.ProductManagerHomeRemote)
javax.rmi.PortableRemoteObject.narrow(obj,com.javasrc.licenseserver.ejb.productmanager.ProductManagerHomeRemote.class);
com.javasrc.licenseserver.ejb.productmanager.ProductManagerRemote productManager = home.create();
productManager.addKeyToProduct( "My Product 1", new Integer( 1 ), "My Key" );
/*
* productManager.addProduct( new Integer( 1 ), "My Product 1" );
* productManager.addProduct( new Integer( 2 ), "My Product 2" );
* productManager.addProduct( new Integer( 3 ), "My Product 3" );
* productManager.removeProduct( "My Product 1" );
* productManager.removeProduct( "My Product 2" );
* productManager.removeProduct( "My Product 3" );
* productManager.addProduct( new Integer( 1 ), "My Product 1" );
* productManager.addProduct( new Integer( 2 ), "My Product 2" );
* productManager.addProduct( new Integer( 3 ), "My Product 3" );
*/
}
catch( Exception e )
{
e.printStackTrace();
}
}
}


ejb-jar.xml
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise
JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">

<ejb-jar>
<enterprise-beans>
<entity>
<ejb-name>ProductEJB</ejb-name>
<home>
com.javasrc.licenseserver.ejb.product.ProductHomeRemote
</home>
<remote>
com.javasrc.licenseserver.ejb.product.ProductRemote
</remote>
<local-home>
com.javasrc.licenseserver.ejb.product.ProductHomeLocal
</local-home>
<local>
com.javasrc.licenseserver.ejb.product.ProductLocal
</local>
<ejb-class>
com.javasrc.licenseserver.ejb.product.ProductBean
</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>Product</abstract-schema-name>
<cmp-field>
<field-name>id</field-name>
</cmp-field>
<cmp-field>
<field-name>name</field-name>
</cmp-field>
<primkey-field>id</primkey-field>
<security-identity>
<use-caller-identity />
</security-identity>
<query>
<query-method>
<method-name>findByName</method-name>
<method-params>
<method-param>java.lang.String</method-param>
</method-params>
</query-method>
<ejb-ql>
SELECT OBJECT(p) FROM Product p WHERE p.name = ?1
</ejb-ql>
</query>
</entity>
<entity>
<ejb-name>ProductKeyEJB</ejb-name>
<home>
com.javasrc.licenseserver.ejb.productkey.ProductKeyHomeRemote
</home>
<remote>
com.javasrc.licenseserver.ejb.productkey.ProductKeyRemote
</remote>
<local-home>
com.javasrc.licenseserver.ejb.productkey.ProductKeyHomeLocal
</local-home>
<local>
com.javasrc.licenseserver.ejb.productkey.ProductKeyLocal
</local>
<ejb-class>
com.javasrc.licenseserver.ejb.productkey.ProductKeyBean
</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>ProductKey</abstract-schema-name>
<cmp-field>
<field-name>id</field-name>
</cmp-field>
<cmp-field>
<field-name>key</field-name>
</cmp-field>
<primkey-field>id</primkey-field>
<security-identity>
<use-caller-identity />
</security-identity>
</entity>
<session>
<ejb-name>ProductManagerEJB</ejb-name>
<home>
com.javasrc.licenseserver.ejb.productmanager.ProductManagerHomeRemote
</home>
<remote>
com.javasrc.licenseserver.ejb.productmanager.ProductManagerRemote
</remote>
<ejb-class>
com.javasrc.licenseserver.ejb.productmanager.ProductManagerBean
</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<ejb-local-ref>
<ejb-ref-name>ProductHomeLocal</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local-home>
com.javasrc.licenseserver.ejb.product.ProductHomeLocal
</local-home>
<local>
com.javasrc.licenseserver.ejb.product.ProductHomeLocal
</local>
<!-- ejb-link is required by jboss for local-refs. -->
<ejb-link>ProductEJB</ejb-link>
</ejb-local-ref>
</session>
</enterprise-beans>

<relationships>
<ejb-relation>
<ejb-relation-name>Product-ProductKey</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>
Product-has-many-ProductKeys
</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<ejb-name>ProductEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>productKeys</cmr-field-name>
<cmr-field-type>java.util.Set</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>
ProductKey-belongs-to-Product
</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<cascade-delete />
<relationship-role-source>
<ejb-name>ProductKeyEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>product</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>

</relationships>

<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>ProductEJB</ejb-name>
<method-name>*</method-name>
</method>
<method>
<ejb-name>ProductKeyEJB</ejb-name>
<method-name>*</method-name>
</method>
<method>
<ejb-name>ProductManagerEJB</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>

</ejb-jar>

jbosscmp-jdbc.xml
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE jbosscmp-jdbc PUBLIC
"-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN"
"http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">

<jbosscmp-jdbc>

<defaults>
<datasource>java:/LicenseServerDS</datasource>
<datasource-mapping>mySQL</datasource-mapping>
<create-table>false</create-table>
<remove-table>false</remove-table>
</defaults>

<enterprise-beans>
<entity>
<ejb-name>ProductEJB</ejb-name>
<table-name>Product</table-name>
<cmp-field>
<field-name>id</field-name>
<column-name>product_id</column-name>
</cmp-field>
<cmp-field>
<field-name>name</field-name>
<column-name>product_name</column-name>
</cmp-field>
</entity>
<entity>
<ejb-name>ProductKeyEJB</ejb-name>
<table-name>ProductKey</table-name>
<cmp-field>
<field-name>id</field-name>
<column-name>pk_id</column-name>
</cmp-field>
<cmp-field>
<field-name>key</field-name>
<column-name>pk_key</column-name>
</cmp-field>
</entity>
</enterprise-beans>

<relationships>
<ejb-relation>
<ejb-relation-name>Product-ProductKey</ejb-relation-name>
<foreign-key-mapping />
<ejb-relationship-role>
<ejb-relationship-role-name>
Product-has-many-ProductKeys
</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>id</field-name>
<column-name>product_id</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>
ProductKey-belongs-to-Product
</ejb-relationship-role-name>
<key-fields />
</ejb-relationship-role>
</ejb-relation>
</relationships>

</jbosscmp-jdbc>

jboss.xml
<?xml version="1.0"?>

<jboss>
<enterprise-beans>
<entity>
<ejb-name>ProductEJB</ejb-name>
<local-jndi-name>ProductHomeLocal</local-jndi-name>
</entity>
<entity>
<ejb-name>ProductKeyEJB</ejb-name>
<local-jndi-name>ProductKeyHomeLocal</local-jndi-name>
</entity>
<session>
<ejb-name>ProductManagerEJB</ejb-name>
<jndi-name>ProductManagerHomeRemote</jndi-name>
</session>
</enterprise-beans>
</jboss>


ProductBean
package com.javasrc.licenseserver.ejb.product;

import java.util.Set;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.naming.InitialContext;

import com.javasrc.licenseserver.ejb.productkey.ProductKeyHomeLocal;
import com.javasrc.licenseserver.ejb.productkey.ProductKeyLocal;

public abstract class ProductBean implements EntityBean
{
/**
* Adds the specified key to this product
*/
public void addProductKey( Integer id, String key ) throws EJBException
{
try
{
InitialContext jndiEnc = new InitialContext();
ProductKeyHomeLocal productKeyHome = ( ProductKeyHomeLocal )jndiEnc.lookup( "ProductKeyHomeLocal" );
ProductKeyLocal productKey = productKeyHome.create( id, key );

Set productKeys = getProductKeys();
productKeys.add( productKey );
}
catch( Exception e )
{
throw new EJBException( e );
}
}

public void ejbActivate() {}

public Integer ejbCreate( Integer id, String name ) throws CreateException
{
setId( id );
setName( name );
return null;
}

public void ejbLoad() {}
public void ejbPassivate() {}

public void ejbPostCreate( Integer id, String name )
{
}
public void ejbRemove() {}

public void ejbStore() {}
public abstract Integer getId();

public abstract String getName();
public abstract Set getProductKeys();
public void setEntityContext( EntityContext ctx ) {}
public abstract void setId( Integer id );
public abstract void setName( String name );
public abstract void setProductKeys( Set productKeys );
public void unsetEntityContext() {}
}

ProductManagerBean
package com.javasrc.licenseserver.ejb.productmanager;

import java.rmi.RemoteException;

import javax.ejb.SessionContext;
import javax.naming.InitialContext;

import com.javasrc.licenseserver.ejb.product.ProductHomeLocal;
import com.javasrc.licenseserver.ejb.product.ProductLocal;

public class ProductManagerBean implements javax.ejb.SessionBean
{
/**
*
*/
private static final long serialVersionUID = 3412364976175301892L;
public SessionContext context;
private InitialContext ic = null;

public void addKeyToProduct( String productName, Integer keyId, String key ) throws RemoteException
{
try
{
// Get our Product Home
InitialContext jndiContext = getInitialContext();
Object obj = jndiContext.lookup( "ProductHomeLocal" );
ProductHomeLocal productHome = ( ProductHomeLocal )obj;

// Find our product
ProductLocal product = productHome.findByName( productName );
product.addProductKey( keyId, key );
}
catch( Exception e )
{
e.printStackTrace();
}
}
public void addProduct( Integer id, String productName ) throws RemoteException
{
try
{
// Get our Product Home
InitialContext jndiContext = getInitialContext();
Object obj = jndiContext.lookup( "ProductHomeLocal" );
ProductHomeLocal productHome = ( ProductHomeLocal )obj;

// Create our product
ProductLocal product = productHome.create( id, productName );
}
catch( Exception e )
{
e.printStackTrace();
}
}
public void ejbActivate()
{
}
public void ejbCreate()
{
}
public void ejbPassivate()
{
}

public void ejbRemove()
{
}

public InitialContext getInitialContext() throws javax.naming.NamingException
{
if( ic == null )
{
ic = new InitialContext();
}
return ic;
}

public void removeProduct( String productName ) throws RemoteException
{
try
{
// Get our Product Home
InitialContext jndiContext = getInitialContext();
Object obj = jndiContext.lookup( "ProductHomeLocal" );
ProductHomeLocal productHome = ( ProductHomeLocal )obj;

// Find our product
ProductLocal product = productHome.findByName( productName );
product.remove();
}
catch( Exception e )
{
e.printStackTrace();
}
}

public void setSessionContext(SessionContext ctx)
{
context = ctx;
}

}

ProductKeyBean
package com.javasrc.licenseserver.ejb.productkey;

import javax.ejb.CreateException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;

import com.javasrc.licenseserver.ejb.product.ProductLocal;

public abstract class ProductKeyBean implements EntityBean
{
public void ejbActivate() {}

public Integer ejbCreate( Integer id, String key ) throws CreateException
{
setId( id );
setKey( key );
return null;
}

public void ejbLoad() {}
public void ejbPassivate() {}

public void ejbPostCreate( Integer id, String key )
{
}
public void ejbRemove() {}

public void ejbStore() {}
public abstract Integer getId();

public abstract String getKey();
public abstract ProductLocal getProduct();
public void setEntityContext( EntityContext ctx ) {}
public abstract void setId( Integer id );
public abstract void setKey( String key );
public abstract void setProduct( ProductLocal product );
public void unsetEntityContext() {}
}
I am running the class through the Eclipse IDE, JUnit plug in. When I check the class path I can see project?
13 years ago
When I run the class below through Eclipse JUnit plugin, I receive the error java.lang.NoSuchErrorField:config. I can't see what I am doing wrong? Thanks in advance.


Cactus Class
package testing.cactus;

import servletunit.struts.CactusStrutsTestCase;


/**
* The Class LoginCactusTest.
*/
public class LoginCactusTest extends CactusStrutsTestCase {

/** The Constant ACTION_PATH. */
private static final String ACTION_PATH = "/ProcessLogin";

/**
* Instantiates a new login cactus test.
*
* @param testName the test name
*/
public LoginCactusTest(String testName) {

super(testName);
}

public void setUp() throws Exception {
super.setUp();
setConfigFile("/WEB-INF/struts-config-signon.xml");
setRequestPathInfo(ACTION_PATH);
}

/**
* Test valid user login.
*
* @throws Exception the exception
*/
public void testValidUserLogin() throws Exception {
actionPerform();
}
}

java.lang.NoSuchFieldError: config
at servletunit.struts.CactusStrutsTestCase.setUp(CactusStrutsTestCase.java:105)
at testing.cactus.LoginCactusTest.setUp(LoginCactusTest.java:25)
at junit.framework.TestCase.runBare(TestCase.java:128)
at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:155)
at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:120)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:94)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:225)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java:1)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:102)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:225)
at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java:1)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:73)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:225)
at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java:1)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1077)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:465)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:348)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:7047)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3902)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2773)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
13 years ago
I am running JBoss 4.2 and JDK 1.5. I try to run the following client class below I receive the error . Exception in thread Exception in thread "main" java.lang.ClassCastException
at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:229)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at simplebean.client.SimpleBeanClient.createBean(SimpleBeanClient.java:44)
at simplebean.client.SimpleBeanClient.main(SimpleBeanClient.java:37)
Caused by: java.lang.ClassCastException: $Proxy0
at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:212)

JAVA CLASS
/**
*
*/
package simplebean.client;

import java.rmi.RemoteException;
import java.util.Properties;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

import simplebean.interfaces.Simple;
import simplebean.interfaces.SimpleHome;

/**
* @author owner
*
*/
public class SimpleBeanClient {
Properties properties;

public SimpleBeanClient() {
properties = new Properties();
properties.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs",
"org.jboss.naming rg.jnp.interfaces");
properties.put("java.naming.provider.url", "jnp://localhost:1099");
properties.put("jnp.disableDiscovery", "true");
}

public static void main(String[] args) {
SimpleBeanClient beanClient = new SimpleBeanClient();
beanClient.createBean();
}

public void createBean() throws EJBException {
try {
InitialContext context = new InitialContext(properties);
Object object = context.lookup("ejb/SimpleBeanHome");
SimpleHome simpleHome = (SimpleHome) PortableRemoteObject.narrow(
object, SimpleHome.class);
Simple simple = simpleHome.create();
simple.setName("Gunter");
System.out.println(simple.getId());
System.out.println(simple.getName());
} catch (NamingException e) {
throw new EJBException(e);
} catch (RemoteException e) {
throw new EJBException(e);
} catch (CreateException e) {
throw new EJBException(e);
}
}
}
14 years ago
Thanks the jar is now deploying. I created a client below. However when I run the client I get the following error. I am using JBoss 4.2.

Thanks
Clinton



Error
Exception in thread "main" java.lang.ClassCastException
at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:229)

Class
package simplebean.client;

import java.rmi.RemoteException;
import java.util.Properties;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

import simplebean.interfaces.Simple;
import simplebean.interfaces.SimpleHome;

/**
* @author owner
*
*/
public class SimpleBeanClient {
Properties properties;

public SimpleBeanClient() {
properties = new Properties();
properties.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs",
"org.jboss.naming rg.jnp.interfaces");
properties.put("java.naming.provider.url", "jnp://localhost:1099");
properties.put("jnp.disableDiscovery", "true");
}

public static void main(String[] args) {
SimpleBeanClient beanClient = new SimpleBeanClient();
beanClient.createBean();
}

public void createBean() throws EJBException {
try {
InitialContext context = new InitialContext(properties);
Object object = context.lookup("ejb/SimpleBeanHome");
SimpleHome simpleHome = (SimpleHome) PortableRemoteObject.narrow(
object, SimpleHome.class);
Simple simple = simpleHome.create();
simple.setName("Gunter");
System.out.println(simple.getId());
System.out.println(simple.getName());
} catch (NamingException e) {
throw new EJBException(e);
} catch (RemoteException e) {
throw new EJBException(e);
} catch (CreateException e) {
throw new EJBException(e);
}
}
}
I am trying to deploy an simple entity bean to JBoss 4.2 and receive the error below. I am not sure where I am going wrong?
Thanks in advance
Clinton

The return type of an ejbCreate(...) method must be the entity bean's primary key type.

15:17:30,064 ERROR [MainDeployer] Could not create deployment: file:/C:/jboss-4.2.2.GA/server/default/deploy/SimpleBean.jar/
org.jboss.deployment.DeploymentException: Verification of Enterprise Beans failed, see above for error messages.

ejb-jar.xml sample
<entity >
<description><![CDATA[Description for Simple]]></description>
<display-name>Name for Simple</display-name>

<ejb-name>Simple</ejb-name>

<home>simplebean.interfaces.SimpleHome</home>
<remote>simplebean.interfaces.Simple</remote>
<local-home>simplebean.interfaces.SimpleLocalHome</local-home>
<local>simplebean.interfaces.SimpleLocal</local>

<ejb-class>simplebean.ejb.SimpleCMP</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>simplebean.interfaces.SimplePK</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>Simple</abstract-schema-name>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>id</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>name</field-name>
</cmp-field>

<!-- Write a file named ejb-finders-SimpleBean.xml if you want to define extra finders. -->

</entity>

SimpleBean sample

public String ejbCreate() throws CreateException {
this.setId(SimpleUtil.generateGUID(this));
return null;
}

jboss.xml sample
<entity>
<ejb-name>Simple</ejb-name>
<jndi-name>ejb/Simple</jndi-name>
<local-jndi-name>SimpleLocal</local-jndi-name>

<method-attributes></method-attributes>

</entity>
Hi,
When the results page is being displayed it does not display the results for ${animals}. It just outputs Could be:. However when I convert it back to a standard jsp it displays ${animals}. I am using Tomcat and jsp version 2.0.

Thanks in advance
Clinton

*results.jsp*
<html xmlns:c="http://java.sun.com/jsp/jstl/core">
<head>
<title>Animal Results</title>
</head>
<body>
<h1>Animal Recommendations JSP</h1>
<table>
<c:forEach var="animals" items="${results}">
<tr>
<td>Could be:<jsp:text>${animals}</jsp:text></td>
</tr>
</c:forEach>
</table>
</body>
</html>

*index.jsp*
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Animal Selection Page</title>
</head>
<body>
<h1 align="center">Animal Selection Page</h1>
<form method="POST" action="SelectAnimal.do">Select animal
characteristics
<p>Color:</p>
<select name="color" size="1">
<option>white</option>
<option>brown</option>
<option>green</option>
<option>orange</option>
</select> <br />
<br />
<center><input type="submit" value="Submit" /></center>
</form>
</body>
</html>
14 years ago
JSP
Badri,
Thank you for the response. I am running the application on my local machine using the Sun Java System Application Server PE 8.2. I made some changes to the code but don't really know what I am trying to achieve here? When I tried to run the code I received the error below.

1) How can I retrieve the correct initial_context_factory
2) How can I retrieve the correct provider_url of the server?

Thanks again
Clinton

Error Message
javax.naming.NamingException: Cannot parse url: iiop://localhost:3700 [Root exce
ption is java.net.MalformedURLException: Not an LDAP URL: iiop://localhost:3700]

at com.sun.jndi.ldap.LdapURL.<init>(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(Unknown Source)
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at AdviceClient.go(AdviceClient.java:20)
at AdviceClient.main(AdviceClient.java:12)
Caused by: java.net.MalformedURLException: Not an LDAP URL: iiop://localhost:3700
Class
import javax.naming.Context;
import javax.naming.InitialContext;
import java.rmi.*;
import java.util.Hashtable;

import javax.rmi.*;
import headfirst.*;
import javax.ejb.*;

public class AdviceClient {
public static void main(String[] args){
new AdviceClient().go();
}

public void go(){
try{
Hashtable<Object, Object> env = new Hashtable<Object, Object>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "iiop://localhost:3700");
Context ctx = new InitialContext(env);


Object o = ctx.lookup("ejb/Advisor");

AdviceHome home = (AdviceHome)PortableRemoteObject.narrow(o, AdviceHome.class);
Advice advisor = home.create();
System.out.println(advisor.getMessage());

}
catch(Exception ex){
ex.printStackTrace();
}
}
}
[ November 12, 2007: Message edited by: Clinton Morrison ]