[Beginners Corner] - Re: Cannot Get InitialContext Lookup to Work
by kurzweil4
My code has various things commented out that I have experimented with.
Here is the persistence.xml. I am sure that my data connection is working properly because I tested it by manually opening the data connection in a JSP.
| <?xml version="1.0" encoding="windows-1252" ?>
| <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" xmlns="http://java.sun.com/xml/ns/persistence">
| <persistence-unit name="Model">
| <jta-data-source>java:/hr</jta-data-source>
| <class>ice.data.table.model.Departments</class>
| <!--class>ice.data.table.model.DepPublicFacade</class>
| <class>ice.data.table.model.DepPublicFacadeLocal</class>
| <class>ice.data.table.model.DepPublicFacadeBean</class-->
| <properties>
| <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
| <property name="hibernate.hbm2ddl.auto" value="validate"/>
| </properties>
| </persistence-unit>
| </persistence>
|
Here in the web.xml, I tried to create an ejb reference, but the problem I ran into was that JBoss gave me an error that it was expecting a local home tag, and since I am using EJB 3.0, I don't have one. I updated the document schema version to 2.5, but JBoss still asked for a local home tag.
| <?xml version = '1.0' encoding = 'windows-1252'?>
| <!--web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"-->
| <web-app version= "2.5"
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
| <description>Empty web.xml file for Web Application</description>
| <context-param>
| <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
| <param-value>server</param-value>
| </context-param>
| <context-param>
| <param-name>javax.faces.application.CONFIG_FILES</param-name>
| <param-value>/WEB-INF/faces-config.xml</param-value>
| </context-param>
| <!--ejb-local-ref>
| <ejb-ref-name>ejb/DepPublicFacade</ejb-ref-name>
| <ejb-ref-type>Session</ejb-ref-type>
| <local>ice.data.table.model.DepPublicFacade</local>
| <ejb-link>DepPublicFacade</ejb-link>
| </ejb-local-ref-->
| <listener>
| <listener-class>com.icesoft.faces.util.event.servlet.ContextEventRepeater</listener-class>
| </listener>
| <listener>
| <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
| </listener>
| <servlet>
| <servlet-name>Faces Servlet</servlet-name>
| <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
| <load-on-startup>1</load-on-startup>
| </servlet>
| <servlet>
| <servlet-name>Persistent Faces Servlet</servlet-name>
| <servlet-class>com.icesoft.faces.webapp.xmlhttp.PersistentFacesServlet</servlet-class>
| <load-on-startup>1</load-on-startup>
| </servlet>
| <servlet>
| <servlet-name>Blocking Servlet</servlet-name>
| <servlet-class>com.icesoft.faces.webapp.xmlhttp.BlockingServlet</servlet-class>
| <load-on-startup>1</load-on-startup>
| </servlet>
| <servlet>
| <servlet-name>uploadServlet</servlet-name>
| <servlet-class>com.icesoft.faces.component.inputfile.FileUploadServlet</servlet-class>
| <load-on-startup>1</load-on-startup>
| </servlet>
| <servlet-mapping>
| <servlet-name>Faces Servlet</servlet-name>
| <url-pattern>/faces/*</url-pattern>
| </servlet-mapping>
| <servlet-mapping>
| <servlet-name>Persistent Faces Servlet</servlet-name>
| <url-pattern>/xmlhttp/*</url-pattern>
| </servlet-mapping>
| <servlet-mapping>
| <servlet-name>Persistent Faces Servlet</servlet-name>
| <url-pattern>*.iface</url-pattern>
| </servlet-mapping>
| <servlet-mapping>
| <servlet-name>Persistent Faces Servlet</servlet-name>
| <url-pattern>*.jspx</url-pattern>
| </servlet-mapping>
| <servlet-mapping>
| <servlet-name>Blocking Servlet</servlet-name>
| <url-pattern>/block/*</url-pattern>
| </servlet-mapping>
| <servlet-mapping>
| <servlet-name>uploadServlet</servlet-name>
| <url-pattern>/uploadHtml</url-pattern>
| </servlet-mapping>
| <session-config>
| <session-timeout>35</session-timeout>
| </session-config>
| <mime-mapping>
| <extension>html</extension>
| <mime-type>text/html</mime-type>
| </mime-mapping>
| <mime-mapping>
| <extension>txt</extension>
| <mime-type>text/plain</mime-type>
| </mime-mapping>
| </web-app>
|
My Entity. I tried various ways of structuring the JNDI name for lookup() from various web sites, but none of them worked.
| package ice.data.table.model;
|
| import java.io.Serializable;
|
| import javax.annotation.Resource;
|
| import javax.persistence.Column;
| import javax.persistence.Entity;
| import javax.persistence.Id;
| import javax.persistence.NamedQuery;
|
| @Entity
| @NamedQuery( name = "Departments.findAll",
| query = "select o from Departments o" )
| public class Departments implements Serializable
| {
| @Id
| @Column( name="DEPARTMENT_ID", nullable = false )
| private Long departmentId;
| @Column( name="DEPARTMENT_NAME", nullable = false )
| private String departmentName;
| @Column( name="LOCATION_ID" )
| private Long locationId;
| @Column( name="MANAGER_ID" )
| private Long managerId;
|
| public Departments()
| {
| }
|
| public Long getDepartmentId()
| {
| return departmentId;
| }
|
| public void setDepartmentId( Long departmentId )
| {
| this.departmentId = departmentId;
| }
|
| public String getDepartmentName()
| {
| return departmentName;
| }
|
| public void setDepartmentName( String departmentName )
| {
| this.departmentName = departmentName;
| }
|
| public Long getLocationId()
| {
| return locationId;
| }
|
| public void setLocationId( Long locationId )
| {
| this.locationId = locationId;
| }
|
| public Long getManagerId()
| {
| return managerId;
| }
|
| public void setManagerId( Long managerId )
| {
| this.managerId = managerId;
| }
| }
|
My service:
| package ice.data.table.model;
|
| import java.util.List;
|
| import javax.ejb.EJB;
| import javax.ejb.Stateless;
|
| import javax.persistence.EntityManager;
| import javax.persistence.PersistenceContext;
|
| @Stateless( name="DepPublicFacade" )
| public class DepPublicFacadeBean implements DepPublicFacade, DepPublicFacadeLocal
| {
| @PersistenceContext( unitName="Model" )
| private EntityManager em;
|
| public DepPublicFacadeBean()
| {
| }
|
| public Object mergeEntity( Object entity )
| {
| return em.merge(entity);
| }
|
| public Object persistEntity( Object entity )
| {
| em.persist(entity);
| return entity;
| }
|
| /** <code>select o from Departments o</code> */
| public List<Departments> queryDepartmentsFindAll()
| {
| return em.createNamedQuery("Departments.findAll").getResultList();
| }
|
| public void removeDepartments( Departments departments )
| {
| departments = em.find(Departments.class, departments.getDepartmentId());
| em.remove(departments);
| }
| }
|
My local and remotes:
| package ice.data.table.model;
|
| import java.util.List;
|
| import javax.ejb.Remote;
|
| @Remote
| public interface DepPublicFacade
| {
| Object mergeEntity( Object entity );
|
| Object persistEntity( Object entity );
|
| List<Departments> queryDepartmentsFindAll();
|
| void removeDepartments( Departments departments );
| }
|
| package ice.data.table.model;
|
| import java.util.List;
|
| import javax.ejb.Local;
|
| @Local
| public interface DepPublicFacadeLocal
| {
| Object mergeEntity( Object entity );
|
| Object persistEntity( Object entity );
|
| List<Departments> queryDepartmentsFindAll();
|
| void removeDepartments( Departments departments );
| }
|
And finally the bean from my WAR where I am calling the above code from the EJB JAR:
| package ice.data.table.view;
|
| import ice.data.table.model.DepPublicFacade;
| import ice.data.table.model.DepPublicFacadeLocal;
| import ice.data.table.model.Departments;
| import java.util.List;
|
| import javax.ejb.EJB;
|
| import javax.ejb.EJBContext;
|
| import javax.ejb.SessionContext;
|
| import javax.naming.Binding;
| import javax.naming.Context;
| import javax.naming.InitialContext;
| import javax.naming.NameClassPair;
| import javax.naming.NamingEnumeration;
| import javax.naming.NamingException;
|
| public class DepartmentsBean
| {
| private DepPublicFacade model;
|
| public DepartmentsBean()
| {
| try
| {
| final Context context = getInitialContext();
|
| /*
| NamingEnumeration<NameClassPair> ne = context.list( "java:comp/env" ); //"IceDataTable/DepPublicFacade.remote" );///DepPublicFacade/local" );
|
| NameClassPair ncp;
|
| System.out.println( ne.hasMore() );
|
| while ( ne.hasMore() )
| {
|
| ncp = ( NameClassPair ) ne.next();
|
| System.out.println( ncp.getName() );
| System.out.println( "\t" + ncp.getClass() );
| System.out.println( "\t" + ncp.getClassName() );
|
| }
| /*
| while ( ne.hasMore() )
| {
| ncp = ( NameClassPair ) ne.next();
| System.out.println( ncp.getName() + ": " + ncp.getClass() + ": " + ncp.getNameInNamespace() + ": " + ncp.getClassName() );
| }*/
| //model = (DepPublicFacade)context.lookup("DepPublicFacade");
| model = (DepPublicFacade)context.lookup("java:comp/env/DepPublicFacade");
| }
| catch (Exception ex)
| {
| ex.printStackTrace();
| }
| }
|
| public List getDepartments()
| {
| return model.queryDepartmentsFindAll();
| }
|
| private static Context getInitialContext() throws NamingException
| {
| // Get InitialContext for Embedded OC4J
| // The embedded server must be running for lookups to succeed.
| return new InitialContext();
| }
| }
|
Thank you for your response. Any help you can provide is appreciated.
Kurzweil4
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4071266#4071266
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4071266
18Â years, 8Â months
[JBoss Seam] - Seam 2.0 beta : Booking example on tomcat 6 : Local server i
by julou
Since I have done migration from Seam 1.2 to Seam 2.0 beta with an application like Booking Example with Javabean, I've got the error message:
ERROR 06-08 18:04:45,265 (NamingHelper.java:getInitialContext:33) -Could not obtain initial context
javax.naming.NamingException: Local server is not initialized
at org.jnp.interfaces.LocalOnlyContextFactory.getInitialContext(LocalOnlyContextFactory.java:45)
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
My configuration was using a jboss-beans.xml file which has been removed from Seam 2.0, the Jndi Server SingletonNamingServer does not exist anymore. Have you an idea from solving that probleme of connecting my datasource without that SingletonNamingServer class ?
I have tried to connect by a resource of in server.xml but in that cas I get the error message "jndi ressource is read only"
Thanks.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4071262#4071262
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4071262
18Â years, 8Â months
[JBossWS] - Re: JBoss 4.0.x migration to 4.2.x
by dlgrasse
Thanks for the idea. I removed the existing jbossws.sar dir in JBoss4.2.1, and installed JBoss2.0.0GA via the ant script, but got the same results.
Troubleshooting this as if it were strictly an XML validation issue, I was able to remove the error mentioned in the first post. A second issue persisted though (org.jboss.ws.WSException: Cannot obtain java type mapping for {some wsdl schema type}). I was hoping it was caused by the schema error, but unfortunately it wasn't.
Working through this problem I was able to resolve it by changing the contents of the jaxrpc-mapping file. Originally the java-xml-type-mapping's were mapping the wsdl element names to Java types. I had to change them to the schema types to get it to work. Here's an example of what I did:
jaxrpc-mapping.xml
| <java-xml-type-mapping>
| <java-type>{mapped Java type}</java-type>
|
| <!--root-type-qname>impl:getReflistsRequest</root-type-qname>
| <qname-scope>element</qname-scope-->
|
| <root-type-qname>tns1:ReflistsInput</root-type-qname>
| <qname-scope>complexType</qname-scope>
| </java-xml-type-mapping>
|
In my wsdl file is the following in the wsdl:types section:
| <wsdl:types>
| <schema xmlns='http://www.w3.org/2001/XMLSchema'
| targetNamespace='{impl namespace}'
| elementFormDefault='qualified'
| >
| <import namespace='{tns1 namespace}' schemaLocation='{schema file}'/>
|
| <element name='getReflistsRequest' type='tns1:ReflistsInput'/>
| </schema>
| </wsdl:types>
|
Where I originally had the mapping to the wsdl element name, I had to change it to point to the underlying schema-defined XML type.
Is this the expected behavior - a change from the earlier JBossWS implementation? Or is there a way to point to the wsdl names by namespace resolution?
dlgrasse
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4071254#4071254
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4071254
18Â years, 8Â months