cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing Queue Connection Factory from java application

0 Kudos

Hi,

I am trying to access the queue connection factory from a standalone java application. I am using the following code

<b>Properties props = new Properties();
QueueConnectionFactory queueConnFact = null;		
try{
props.put("Context.INITIAL_CONTEXT_FACTORY", "com.sap.engine.services.jndi.InitialContextFactoryImpl");
props.put("Context.PROVIDER_URL", "server:50004");
props.put("Context.SECURITY_PRINCIPAL", "user");
props.put("Context.SECURITY_CREDENTIALS", "pass");
			
Context ctx = new InitialContext(props);
			
// Look up the connection factory
queueConnFact = (QueueConnectionFactory)PortableRemoteObject.narrow(ctx.lookup("jmsfactory/default/QueueConnectionFactory"), QueueConnectionFactory.class);</b>

However i get the following exception.

<i><b>Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial</b></i>

Please do let me know what additional i have to do make the code work.

Regards

Sidharth

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Sidharth,

Take a look at

HTH

Martin

0 Kudos

Hi Martin,

The thread that you pointed to discusses some other issue.

Mine is different than that.

Regards

Sidharth

Former Member
0 Kudos

Hi,

Don't know why but the URL points to somewhere else

The lookup is not right. It must be :


try {
      factory = (QueueConnectionFactory) cxt.lookup("jmsfactory/default/QueueConnectionFactory");
} catch (NamingException ne) {
      System.out.println( "NamingException -> "" + ne.getMessage() + """);
}

HTH

Martin

0 Kudos

Hi Martin,

The code still does not work. I am getting the same error.

I dont why but the java application is not able to load the QueueConnectionFactory class.

DO i need to make some settings in the java project for eg add some libraries.

Regards

Sidharth

Former Member
0 Kudos

Hi,

Sorry I didn't saw it earlier:

remove all quotes from Context.XXXXX, i.e.

props.put("Context.PROVIDER_URL", "server:50004");

should be

props.put(Context.PROVIDER_URL, "server:50004");

And yes, you gotta have logging.jar, exception.jar, jms.jar and sapj2eeclient.jar in your CLASSPATH.

You can find them at: C:\usr\sap\{SID_NUMBER}\JC\j2ee\j2eeclient directory.

HTH

Martin

0 Kudos

Hi Martin,

Now i get the stack trace which i have pasted below

java.lang.NoClassDefFoundError: com/sap/tc/logging/LogController
	at com.sap.engine.services.security.login.SecurityContext.setAnonymousPrincipal(SecurityContext.java:492)
	at com.sap.engine.services.security.login.TicketGenerator.getSecuritySession(TicketGenerator.java:119)
	at com.sap.engine.services.security.login.SecurityContext.load(SecurityContext.java:230)
	at com.sap.engine.services.rmi_p4.Message.loadContextObject(Message.java:363)
	at com.sap.engine.services.rmi_p4.Message.parseMessage(Message.java:239)
	at com.sap.engine.services.rmi_p4.Message.getByteArrayInputStream(Message.java:314)
	at com.sap.engine.services.rmi_p4.Call.getResultStream(Call.java:176)
	at com.sap.engine.services.security.remote.RemoteSecurity_Stub.getRemoteLoginContext(RemoteSecurity_Stub.java:657)
	at com.sap.engine.services.security.remote.login.RemoteLoginContext.<init>(RemoteLoginContext.java:93)
	at com.sap.engine.services.jndi.implclient.LoginHelper.clientSideLogin(LoginHelper.java:78)
	at com.sap.engine.services.jndi.InitialContextFactoryImpl.getInitialContext(InitialContextFactoryImpl.java:402)
	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
	at javax.naming.InitialContext.init(InitialContext.java:219)
	at javax.naming.InitialContext.<init>(InitialContext.java:195)
	at com.wipro.jmsproducer.CProducer.main(CProducer.java:31)
Exception in thread "main"

Former Member
0 Kudos

Hi,

The logging.jar is not in CLASSPATH of your program, add it.

See my previous post.

HTH

Answers (0)