My question is what deployment descriptor I use to bind a JNDI name to my
Entity Beans.
I am stuck.
My applicartion deployes with no error messages. I have some Servlets included
that all work.
AND ... deploying my application even creates all the required database tables
correctly.
However, when I pass a Game object to a Servlets doPost () where I want the
Servlet to create the GameBean, I cannot find my Bean Objects.
And when I look in the JNDI list in the console they are not there.
If anyone is willing to help, here are the sections of the code I think are
relevant for one Bean:
<ejb-jar>
| <enterprise-beans>
| <!-- MemberBean -->
| <entity>
| <description>MemberBean Definition</description>
| <display-name>MemberBean</display-name>
| <small-icon/>
| <large-icon/>
| <ejb-name>MemberEJB</ejb-name>
| <local-home>org.projects.games.go.MemberLocalHome</local-home>
| <local>org.projects.games.go.MemberLocal</local>
| <ejb-class>org.projects.games.go.MemberBean</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>MemberSchema</abstract-schema-name>
| <cmp-field><field-name>id</field-name></cmp-field>
| .... other fields
| <primkey-field>id</primkey-field>
| <resource-ref>
| <description/>
| <res-ref-name>DefaultDS</res-ref-name>
| <res-type>javax.sql.DataSource</res-type>
| <res-auth>Container</res-auth>
| <res-sharing-scope>Shareable</res-sharing-scope>
| </resource-ref>
| </entity>
| ...
| </enterprise-beans>
| </ejb-jar><jbosscmp-jdbc>
| <enterprise-beans>
| <!-- MemberBean -->
| <entity>
| <ejb-name>MemberEJB</ejb-name>
| <create-table>true</create-table>
| <table-name>plays</table-name>
| <cmp-field>
| <field-name>id</field-name>
| <column-name>id</column-name>
| <not-null/><auto-increment/>
| </cmp-field>
| .... other fields
| <entity-command name="mysql-get-generated-keys"
| class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCMySQLCreateCommand"/>
| </entity>
| ...
| </enterprise-beans>
| </jbosscmp-jdbc><jboss>
| <enterprise-beans>
| <!-- MemberBean -->
| <entity>
| <ejb-name>MemberEJB</ejb-name>
| <local-jndi-name>ejb/MemberLocalHome</local-jndi-name>
| <resource-ref>
| <res-ref-name>DefaultDS</res-ref-name>
| <jndi-name>java:/DefaultDS</jndi-name>
| </resource-ref>
| </entity>
| ...
| <enterprise-beans>
| </jboss>
The Local Client Method
void saveCurrentGame() {
| System.out.println ("Saving Game");
| String urlString;
| URL url;
| URLConnection urlConnection;
| HttpURLConnection httpConnection;
| ObjectOutputStream out;
| InputStream in;
| // Local vs. Remote Server
| urlString = "http://localhost:8080/X/servlet/SaveGameServlet";
| System.out.println ("URL: " + urlString);
| try {
| // Configure connection
| url = new URL (urlString);
| urlConnection = url.openConnection ();
| System.out.println("Connection Opened.");
| httpConnection = (HttpURLConnection) urlConnection;
| httpConnection.setRequestMethod ("POST");
| httpConnection.setDoOutput(true);
| httpConnection.setDoInput(true);
| System.out.println("Connection Configured");
| // POST Game
| out = new ObjectOutputStream(httpConnection.getOutputStream ());
| System.out.println("OutputStream Instantiated");
| out.writeObject(model.getGame ());
| out.flush();
| out.close ();
| System.out.println("New Game object POSTed");
| // Get response
| in = (InputStream) httpConnection.getContent ();
| System.out.println("POST returned");
| System.out.println("*****Begining printContent()*****");
| BufferedReader reader =
| new BufferedReader (
| new InputStreamReader (in) );
| while (true) {
| int i = in.read ();
| if (i <0) break;
| System.out.print ((char) i);
| }
| in.close ();
| System.out.println("*****End printContent()*****\n");
| } catch (MalformedURLException me) {
| System.out.println("Malformed URL Exception");
| } catch (ProtocolException pe) {
| System.out.println("Protocal Exception");
| } catch (IOException io) {
| System.out.println("IO Exception");
| }
|
| }
The Servlet doPost () public void doPost(HttpServletRequest request,
HttpServletResponse response)
| throws IOException, ServletException {
|
| response.setContentType("text/html");
| PrintWriter out = response.getWriter();
|
| out.println("Beginning doPost() in UploadGameServlet");
| ObjectInputStream in =
| new ObjectInputStream( request.getInputStream () );
| out.println("Got ObjectInputStream from request");
| Game game = null;
| try {
| game = (Game) in.readObject();
| out.println("Game Object Instantiated");
| } catch (ClassNotFoundException cnf) {
| out.println("Class Not Found Exception");
| } catch (Exception e) {
| out.println("Other Exception");
| }
| in.close ();
| Object ref = null;
| GameLocalHome home = null;
| GameLocal gameBean = null;
| try {
| Context jndiContext = new InitialContext();
| out.println("getInitialContext() returned: "+jndiContext);
|
| // THIS IS WERE IT BRANCHES TO NAMINGEXCEPTION BELOW
|
| ref = jndiContext.lookup("ejb/GameLocalHome");
| out.println("Got jndiContext for GameBean");
| home = (GameLocalHome) ref;
| out.println("Cast ref to home X");
| gameBean = home.create(game);
| out.println("GameBean created");
| } catch (CreateException ce) {
| out.println("Create Exception ");
| } catch (NamingException ne) {
| out.println("Naming Exception");
| }
| out.println("BYE");
| }
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3866370#3866370
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3866370
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user