#Resource DataSource ds and #EJB injection not working - weblogic.developer.interest.webservices.general(Archived)

Hi there,
I'm using wls 10.3 and I'm trying to inject a DataSource and EJB in one of my webservice (jax-rpc) and using the annotation because I'm just using the jwsc ant task to generate all my weblogic descriptor. When I tried to test the DataSource and EJB it is null. I have defined in the admin console a jdbc DataSource jndi named="jdbc/ppDataSource" and also created both SystemEJBRemote and SystemEJBLocal ejb's. Sample code below.
#SoapBinding(style=SOAPBinding.Style.DOCUMENT....)
#Stateless(mappedName="CustomerBeanWS")
#WebService(name="CustomerWS",
serviceName="CustomerWSService")
public class CustomerWSImpl
#EJB private SystemEJBLocal systemLocal;
#Resource DataSource(name="jdbc/DataSource") ds;
public void testInjection() {
// test ejb
if (systemLocal != null) {
systemLocal.hello();
} else {
System.out.println("SystemEJBLocal ref injection is null.");
}
if (ds != null) {
ds.getConnection();
} else {
System.out.println("DataSource ref injection is null.");
}
}
#Stateless
#Local( SystemEJBLocal.class )
#Remote( SystemEJBRemote.class )
public class SystemEJBImpl {
public void hello() {
System.out.println( "Hello EJB3!" );
}
}
Your help is very much appreciated.
Thanks 

Hi,
unfortunatly i had the same problem for ejb injection.
i resolved this with the following not nice workaround
Auto wire does not work with pojos.
So i used the declaration of references in the web.xml. The problem here is, the web.xml is automatically generated by the jwsc - ant task.
So I added to the existing web.xml the following lines
     <ejb-local-ref>
          <ejb-ref-name>ejb/IntegratorManager</ejb-ref-name>
          <ejb-ref-type>Session</ejb-ref-type>
          <local>com.abc.ipc.integrator.services.IntegratorManager</local>
          <ejb-link>IntegratorManagerBean</ejb-link>
     </ejb-local-ref>
In my WebService, i looked up the Session Bean and it works fine.
class MyWebService
     public IpcCoatService(){
          this.lookupIntegrationManager();
     }
     
     private IntegratorManager iManager;          
     
     private void lookupIntegrationManager(){
          try {
               Context ctx = new InitialContext();
               this.iManager = (IntegratorManager) ctx.lookup("java:comp/env/ejb/IntegratorManager");
               
          } catch (NamingException nExc) {
               myLogger.severe("Namingexception when lookup session bean " + nExc.getMessage() );
          }
     }
So i only have to solve the problem, to add the reference to the web.xml automatically.
hope this will help
bye
karpuz

Related

#Resource DataSource ds and #EJB injection not working

Hi there,
I'm using wls 10.3 and I'm trying to inject a DataSource and EJB in one of my webservice (jax-rpc) and using the annotation because I'm just using the jwsc ant task to generate all my weblogic descriptor. When I tried to test the DataSource and EJB it is null. I have defined in the admin console a jdbc DataSource jndi named="jdbc/ppDataSource" and also created both SystemEJBRemote and SystemEJBLocal ejb's. Sample code below.
#SoapBinding(style=SOAPBinding.Style.DOCUMENT....)
#Stateless(mappedName="CustomerBeanWS")
#WebService(name="CustomerWS",
serviceName="CustomerWSService")
public class CustomerWSImpl
#EJB private SystemEJBLocal systemLocal;
#Resource DataSource(name="jdbc/DataSource") ds;
public void testInjection() {
// test ejb
if (systemLocal != null) {
systemLocal.hello();
} else {
System.out.println("SystemEJBLocal ref injection is null.");
}
if (ds != null) {
ds.getConnection();
} else {
System.out.println("DataSource ref injection is null.");
}
}
#Stateless
#Local( SystemEJBLocal.class )
#Remote( SystemEJBRemote.class )
public class SystemEJBImpl {
public void hello() {
System.out.println( "Hello EJB3!" );
}
}
Your help is very much appreciated.
Thanks

Invoking weblogic ejb over iiop

Hi,
I am trying to invoke my EJB ( stateless session ) through iiop protocol. My client
code is based on the sample bean provided by weblogic. I have the client code
aatached.
When I run the client I get the following exception ...
Exception in thread "main" java.lang.ClassCastException at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(Unknown
Source) at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
at Client.narrow(Client.java:115) at Client.lookupHome(Client.java:131)
at Client.<init>(Client.java:41) at Client.main(Client.java:73)
I am invoking the EJB in the same way as it has been suggested by weblogic. I
reffered to this url
http://e-docs.bea.com/wls/docs61/rmi_iiop/API_rmi_iiop.html#1044525
Can someone tell me what am I doing wrong? My EJB is OK as I can invoke it nicely
from a t3 client. I am using weblogic 6.1 sp 2
--------------------
Shubhrajit
This is the code of the client
import java.rmi.RemoteException;
import java.util.Properties;
import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import shub.ejb.test.*;
public class Client {
private static final String JNDI_NAME = "shub.ejb.test.Far2CentHome";
private String url;
private Far2CentHome home;
private static boolean remote = false;
public Client(String url)
throws NamingException
{
this.url = url;
home = lookupHome();
}
public static void main(String[] args) throws Exception {
log("\nBeginning statelessSession.Client...\n");
String url = "iiop://localhost:7001";
// Parse the argument list
     if(args.length != 1){
          System.out.println("Wrong usage");
          System.exit(1);
     }
     log("\nBeginning statelessSession.FartoCentClient...\n");
     float d = (new Float(args[0])).floatValue();
Client client = null;
try {
client = new Client(url);
} catch (NamingException ne) {
System.exit(1);
}
try {
client.example(d);
} catch (Exception e) {
log("There was an exception while creating and using the Trader.");
log("This indicates that there was a problem communicating with the server:
"+e);
}
log("\nEnd statelessSession.Client...\n");
}
/**
* Runs this example.
*/
public void example(float d)
throws CreateException, RemoteException, RemoveException
{
// create a FartoCent
log("Creating a FartoCent");
Far2Cent fartocent = (Far2Cent)narrow(home.create(), Far2Cent.class);
log("Success");
log("Far= "+d+" Cent="+fartocent.getCent(d));
}
/**
* RMI/IIOP clients should use this narrow function
*/
private Object narrow(Object ref, Class c) {
return PortableRemoteObject.narrow(ref, c);
}
/**
* Lookup the EJBs home in the JNDI tree
*/
private Far2CentHome lookupHome()
throws NamingException
{
// Lookup the beans home using JNDI
Context ctx = getInitialContext();
try {
Object home = ctx.lookup(JNDI_NAME);
System.out.println(home.toString());
return (Far2CentHome) narrow(home, Far2CentHome.class);
} catch (NamingException ne) {
log("The client was unable to lookup the EJBHome. Please make sure ");
log("that you have deployed the ejb with the JNDI name "+JNDI_NAME+" on
the WebLogic server at "+url);
throw ne;
}
}
private Context getInitialContext() throws NamingException {
try {
// Get an InitialContext
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.cosnaming.CNCtxFactory");
h.put(Context.PROVIDER_URL, url);
return new InitialContext(h);
} catch (NamingException ne) {
log("We were unable to get a connection to the WebLogic server at "+url);
log("Please make sure that the server is running.");
throw ne;
}
}
private static void log(String s) {
System.out.println(s);
}
}
Putting the thread on top again so that it is visible to others

Primitive int[] and Integer[] array type not supported

Hi there,
I have a stateless ejb exposed as webservice using jax-rpc 1.1 and one of my methods accepts a parameter of int[] array. When I run the wls clientgen ant task and I look at the generated client stub for that webservice the parameter is no longer int[] but this one "com.starcomsoft.ArrayOfJavaLangint_Literal". Below is a snippet of client stub code produced by wls clientgen.
public class CustomerWS_Stub
extends weblogic.wsee.jaxrpc.StubImpl
implements com.starcomsoft.pp.customer.jws.CustomerWS, /**/java.io.Serializable
{
public CustomerWS_Stub(weblogic.wsee.wsdl.WsdlPort port,
weblogic.wsee.jaxrpc.ServiceImpl service)
throws javax.xml.rpc.ServiceException
{
super(port, com.starcomsoft.pp.customer.jws.CustomerWS.class, service);
}
/**
* Operation Name : {http://www.starcomsoft.com}findAddresses1 */
public java.lang.Object[] findAddresses1(com.starcomsoft.ArrayOfint_Literal idSet) throws java.rmi.RemoteException {
java.util.ArrayList _args = new java.util.ArrayList();
_args.add(idSet);
try {
java.lang.Object result = invoke("findAddresses1", _args.toArray());
return (java.lang.Object[])_result;
} catch (javax.xml.rpc.JAXRPCException wlsexception) {
throw new java.rmi.RemoteException(_wls_exception.getMessage(), wlsexception.getLinkedCause());
} catch (javax.xml.rpc.soap.SOAPFaultException wlsexception) {
throw new java.rmi.RemoteException(_soapFault2String(_wls_exception), wlsexception);
} catch (java.lang.Throwable wlsexception) {
throw new java.rmi.RemoteException(_wls_exception.getMessage(), wlsexception);
}
}
And here is my webservice class:
#SOAPBinding(style=SOAPBinding.Style.DOCUMENT, use=SOAPBinding.Use.LITERAL,
     parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)
#Stateless(mappedName = "CustomerBeanWS")
#WebService(name = "CustomerWS",
               serviceName = "CustomerWSService",
               targetNamespace = "http://www.starcomsoft.com")
public class CustomerWSImpl implements CustomerEJBRemote, CustomerEJBLocal {
     #WebMethod()
     #TransactionAttribute(TransactionAttributeType.REQUIRED)
     public List<Address> findAddresses1(int[] idSet) {
          AddressDAO dao = new AddressDAO();
          List<Address> addrList = dao.loadAddresses(idSet);
          return addrList;
     }
}
I also tried using Integer[] type but the same type is produced - that is "com.starcomsoft.ArrayOfJavaLangint_Literal".
I'm stuck and your help is very much appreciated.

unable call ejb remote in weblogic 10.3

hi all,
I am trying to call a remote service deployed in weblogic 10.3 here are my classes
#Stateless (mappedName = "ejb/engine")
#TransactionManagement(value=TransactionManagementType.CONTAINER)
public class JsacEngineEJB implements JsacEngineEJBRemote {
     #Override
     public User getUserByID(String userId) {
          User ret = null;
          try {
               .....
          return ret;
     }
}
#Remote
public interface JsacEngineEJBRemote {
public User getUserByID(String userId);
}
private static Object jndiLookup(String jndiName) throws NamingException {
          final Object obj;
          try {
          obj = ctx.lookup(jndiName);     
          } catch (NamingException e) {
               log.logFatal("Can not found JNDI name: " + jndiName);
               throw e;
          }
          return obj;
     }
String jndi = "ejb/engine#"
final String jndiName =jndi+beanClass.getCanonicalName();
final T bean = (T)jndiLookup(jndiName);
the exception
java.lang.reflect.UndeclaredThrowableException
     at $Proxy61.getUserByID(Unknown Source)
     
java.lang.NoSuchMethodException:
     at java.lang.Class.getMethod(Class.java:1605)
     at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.getTargetMethod(RemoteBusinessIntfProxy.java:162)
     at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:53)
     
     Truncated. see log file for complete stacktrace
any idea???
Best regards 
Hi,
It seems that the Followinf line of code is causing the issue:
String jndi = "ejb/engine#"
<font color=red>final String jndiName =jndi+beanClass.getCanonicalName();</font><BR>
final T bean = (T)jndiLookup(jndiName);
Is it possible for you to Not to use the ".getCanonicalName()" method. Rather u can use a Simple Custom JNDI Name for your EJBs. Like: http://weblogic-wonders.com/weblogic/2009/08/21/custom-jndi-ejb3/
Sometimes we get the following errors if we dont generate the EJB Client artifacts to be used at client end. Please try generating EJB Client JAR...as well: http://weblogic-wonders.com/weblogic/2010/04/02/generating-ejb3-clientjar/
java.lang.NoSuchMethodException:
at java.lang.Class.getMethod(Class.java:1605)
at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.getTargetMethod(RemoteBusinessIntfProxy.java:162)
.
.
Thanks
Jay SenSharma 
Lookup the session bean remote interface using the mapped name. The global JNDI name for a session bean remote business interface is derived from the remote business interface name. The format of the global JNDI name is mappedName#qualified_name_of_businessInterface.
InitialContext context = new InitialContext();
TestSessionEJB beanRemote = (TestSessionEJB) context.lookup("EJB3-SessionEJB#model.TestSessionEJB"); 
the problem is not the jndi because the service is returned
by the container, is when I try to access some method
within the service throws the exception there :(

ClassNotFoundException: trying to load OC4J JNDI InitialContextFactory

Hello!
Trying to make a call to an EJB deployed in OCJ4 from a oracle java stored proc. After loaded orion.jar and crimson.jar lib into SCOTT schema, I can't get the JNDI Context working because of this error:
============================================
javax.naming.NoInitialContextException: Cannot instantiate class:
com.evermind.server.ApplicationClientInitialContextFactory. Root exception is
java.lang.ClassNotFoundException:
com/evermind/server/ApplicationClientInitialContextFactory
at java.lang.Class.forName0(Class.java)
at java.lang.Class.forName(Class.java)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:45)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java)
at javax.naming.InitialContext.init(InitialContext.java)
at javax.naming.InitialContext.<init>(InitialContext.java)
===============================
I did load the java with "loadjava" with on time with the "resolve" option and time time no option and still no working.
Here is the EJB client code:
=======================================
import java.sql.*;
import java.util.*;
import javax.naming.*;
import com.evermind.server.ApplicationClientInitialContextFactory;
class EmpRemoteCall {
public static void main(String[] args) {
System.out.println(getEmpName());
}
public static String getEmpName() {
String ejbUrl = "java:comp/env/ejb/Emp";
String username = "admin";
String password = "admin";
Hashtable environment = new Hashtable();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.ApplicationClientInitialContextFactory");
environment.put(Context.PROVIDER_URL, "ormi://127.0.0.1/testemp");
environment.put(Context.SECURITY_PRINCIPAL, username);
environment.put(Context.SECURITY_CREDENTIALS, password);
//environment.put(Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);
//environment.put(javax.naming.Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
com.kboum.sertir.essais.EmpHome homeInterface = null;
try {
Class.forName("com.evermind.server.ApplicationClientInitialContextFactory", true, ClassLoader.getSystemClassLoader());
System.out.println("Creating an initial context");
Context ic = new InitialContext(environment);
System.out.println("Looking for the EJB published as 'java:comp/env/ejb/Emp'");
homeInterface = (com.kboum.sertir.essais.EmpHome) ic.lookup(ejbUrl);
}
catch (CommunicationException e) {
System.out.println("Unable to connect: " + ejbUrl);
e.printStackTrace();
//System.exit(1);
}
catch (NamingException e) {
System.out.println("Exception occurred!");
System.out.println("Cause: This may be an unknown URL, or some" +
" classes required by the EJB are missing from your classpath.");
System.out.println("Suggestion: Check the components of the URL," +
" and make sure your project includes a library containing the" +
" EJB .jar files generated by the deployment utility.");
e.printStackTrace();
//System.exit(1);
}
catch (ClassNotFoundException e) {
System.out.println("Unable to connect: " + ejbUrl);
e.printStackTrace();
//System.exit(1);
}
try {
System.out.println("Creating a new EJB instance");
com.kboum.sertir.essais.Emp remoteInterface = homeInterface.findByPrimaryKey(Integer.valueOf("7369"));
System.out.println(remoteInterface.getENAME());
System.out.println(remoteInterface.getSAL());
remoteInterface.setSAL(2);
System.out.println(remoteInterface.getSAL());
return remoteInterface.getENAME();
}
catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
return "error";
}
} 
I guess from the error its pretty clear that the initial context factory u r using doesnt exist. Did u try with "oracle.aurora.jndi.*" as ur PKG_PREFIXES_URL when setting values in ur Hashtable.
I mean
environment.put(Context.PKG_PREFIXES_URL, "oracle.aurora.jndi.*"; 
The package prefix in the code extract was correct - i.e. "oracle.aurora.jndi". A value of "oracle.aurora.jndi.*" would be incorrect.
The problem is that the context factory implementation specified (com.evermind.server.ApplicationClientInitialContextFactory
) can't be found, the mostly likely reason being that the library containing the class isn't on the classpath.
Cheers,
ax
null 
Is there a way to add jar libraries to the Oracle JVM CLASSPATH? Is this the same as the system's CLASSPATH env. variable?
Thank you!
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Alex McClennan (alex#orion.co.nz):
The package prefix in the code extract was correct - i.e. "oracle.aurora.jndi". A value of "oracle.aurora.jndi.*" would be incorrect.
The problem is that the context factory implementation specified (com.evermind.server.ApplicationClientInitialContextFactory
) can't be found, the mostly likely reason being that the library containing the class isn't on the classpath.
Cheers,
ax<HR></BLOCKQUOTE>
null 
Oh yeah sorry just a type, its "oracle.aurora.jndi". Yeah its the samething, u just include the jar file in ur classpath.

Categories

Resources