on 12-11-2014 6:16 AM
Hi All,
I m working on JMS in SAP MII 12.2. I m trying to Asynchronously Receiving Messages Sent to a Topic following the example at, http://help.sap.com/saphelp_erp60_sp/helpdata/en/20/4cf81d8ff54c5588cb7e000cae6467/frameset.htm. I m writing a standalone Java Code and have added following jars to build path :
sap.com~tc~exception~impl.jar
sap.com~tc~logging~java~impl.jar
sap.com~tc~je~clientlib~impl.jar
But I m getting following exception,
com.sap.engine.services.jndi.persistent.exceptions.NoPermissionException: Exception during getInitialContext operation. Wrong security principles/credentials
private static final String USER = "Administrator";
private static final String PASSWORD = "abc123";
The username/password I m passing here is able to login to SAP MII and also able to check JNDI Browser in NWA.
Could you please point out what m I doing wrong here. Any pointers would be appreciated.
Thanks,
N G.
Hi NG
Could you follow the steps as mention in the SAP Note
699557 - Error in online deployment with ABAP user administration
BR
SS
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sriram,
Thanks for the reply.
The module you have provided is related to DeployManagerException. I m not able to appreciate how can I relate this to my NoPermissionException. Also, for the steps provided in document, I will have to contact the BASIS person to do all the work. So just wanted to make sure of the approach.
FYI, I m getting folowing error trace:
Could not create JNDI APIcontext: javax.naming.NoPermissionException: Exception during getInitialContext operation. Wrong security principal/credentials. [Root exception is com.sap.engine.services.security.exceptions.BaseLoginException: security_1010]
javax.naming.NoPermissionException: Exception during getInitialContext operation. Wrong security principal/credentials. [Root exception is com.sap.engine.services.security.exceptions.BaseLoginException: security_1010]
at com.sap.engine.services.jndi.InitialContextFactoryImpl.handleUserProblem(InitialContextFactoryImpl.java:427)
at com.sap.engine.services.jndi.InitialContextFactoryImpl.getInitialContext(InitialContextFactoryImpl.java:341)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.init(InitialContext.java:242)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
at SimpleClient.main(SimpleClient.java:44)
Caused by: com.sap.engine.services.security.exceptions.BaseLoginException: security_1010
at com.sap.engine.services.security.login.ModulesProcessAction.run(ModulesProcessAction.java:177)
at java.security.AccessController.doPrivileged(Native Method)
at com.sap.engine.services.security.login.FastLoginContext.login(FastLoginContext.java:234)
at com.sap.engine.services.security.remoteimpl.login.RemoteLoginContextHelperImpl.login(RemoteLoginContextHelperImpl.java:91)
at com.sap.engine.services.security.remoteimpl.login.RemoteLoginContextHelperImplp4_Skel.dispatch(RemoteLoginContextHelperImplp4_Skel.java:64)
at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:362)
at com.sap.engine.services.rmi_p4.server.ServerDispatchImpl.run(ServerDispatchImpl.java:69)
at com.sap.engine.services.rmi_p4.P4Message.process(P4Message.java:67)
at com.sap.engine.services.rmi_p4.P4Message.execute(P4Message.java:41)
at com.sap.engine.services.cross.fca.FCAConnectorImpl.executeRequest(FCAConnectorImpl.java:977)
at com.sap.engine.services.rmi_p4.P4Message.process(P4Message.java:57)
at com.sap.engine.services.cross.fca.MessageReader.run(MessageReader.java:55)
at com.sap.engine.core.thread.execution.Executable.run(Executable.java:122)
at com.sap.engine.core.thread.execution.Executable.run(Executable.java:101)
at com.sap.engine.core.thread.execution.CentralExecutor$SingleThread.run(CentralExecutor.java:327)
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at SimpleClient.main(SimpleClient.java:58)
Any pointers on this.
Thanks,
N G.
Please share the rest of the code that shows how you are creating your Java security principle for access the JNDI context. The above isn't enough to go on to help you out; also have a look here for ideas:
Creating an InitialContext - Java Development Manual - SAP Library
Which indicates it should look something like this:
Context ctx = null;
Hashtable env = new Hashtable();
env.put(Context.PROVIDER_URL, "<server>:<port>");
env.put(“force_remote”, “true”);
env.put(Context.SECURITY_PRINCIPAL, "MyUserName");
env.put(Context.SECURITY_CREDENTIALS, "MyPassword");
try {
ctx = new InitialContext(env);
} catch (NamingException ne) {
e.printStackTrace()
}
Sam
Hi Salvatore,
Thanks for the reply.
I m following the link at :
Asynchronously Receiving Messages Sent to a Topic - Using Java - SAP Library
and prepared this code
import java.util.Properties;
import javax.naming.*;
import javax.jms.*;
/**
* This class creates a topic connection, and then
* sends to and receives messages from the Topic.
*/
public class AsynchTopic implements javax.jms.MessageListener {
private static final String USER = "Administrator";
private static final String PASSWORD = "abc123";
private static final String SAP_NAMING_PROVIDER_URL = "saptestinst:50004";
private static final String SAP_INITIAL_CONTEXT_FACTORY_IMPL =
"com.sap.engine.services.jndi.InitialContextFactoryImpl";
TopicConnectionFactory topicConnectionFactory = null;
TopicConnection topicConnection = null;
Topic topic = null;
TopicSession topicSession = null;
TopicPublisher topicPublisher = null;
TopicSubscriber topicSubscriber = null;
TextMessage textMessage1 = null;
boolean flag = true;
String text = "test string";
/**
* Get InitialContext with default values.
*/
private InitialContext getInitialContext() {
try {
// set the properties for the InitalContext
Properties properties = new Properties();
properties.put(
Context.INITIAL_CONTEXT_FACTORY,
SAP_INITIAL_CONTEXT_FACTORY_IMPL);
properties.put(Context.PROVIDER_URL, SAP_NAMING_PROVIDER_URL);
properties.put(Context.SECURITY_PRINCIPAL, USER);
properties.put(Context.SECURITY_CREDENTIALS, PASSWORD);
// initialize and return the InitalContext with the specified
properties
return new InitialContext(properties);
} catch (NamingException ne) {
System.out.println("NamingException: " + ne);
}
return null;
}
/**
* Initializes JMS.
*/
private void initJMS() {
try {
InitialContext context = getInitialContext();
// look up the TopicConnectionFactory
topicConnectionFactory =
(TopicConnectionFactory) context.lookup(
" jmsfactory/default/TopicConnectionFactory");
// create topic connection
topicConnection = topicConnectionFactory.createTopicConnection();
// start the connection
topicConnection.start();
} catch (NamingException ne) {
System.out.println("NamingException: " + ne);
} catch (JMSException jmse) {
System.out.println("JMSException: " + jmse);
}
}
/**
* Closes all resorces used in this test. This should be called
* when you want to finish using JMS.
*/
private void closeJMS() {
try {
//closes the jms topic session
topicSession.close();
//closes the jms topic connection
topicConnection.close();
} catch (JMSException jmse) {
System.out.println("JMSException: " + jmse);
}
}
/**
* Create a topic, send and receive messages
* and then close the connection.
*/
public void aMethod() {
try {
// initializes all important data that will be used.
initJMS();
// create topic session
topicSession =
topicConnection.createTopicSession(
false,
Session.AUTO_ACKNOWLEDGE);
// topic session's topic
topic = topicSession.createTopic("ExampleTopic");
// create sender
topicPublisher = topicSession.createPublisher(topic);
//create subscriber
topicSubscriber = topicSession.createSubscriber(topic);
topicSubscriber.setMessageListener(this);
// create text message
textMessage1 = topicSession.createTextMessage();
textMessage1.setText(text);
// send the message
topicPublisher.publish(textMessage1);
//topic subscriber is waiting for messages.
while (flag) {
try {
Thread.sleep(1000);
} catch (Exception e) {
break;
}
}
// clears all resources used by JMS
closeJMS();
} catch (JMSException e) {
e.printStackTrace();
}
}
/**
* Implemented from the MessageListener interface.
* Allows for asynchronous message receipt. Here you can
* unpack the message.
* @param message the newly received message
*/
public void onMessage(Message message) {
// do something with the message received.
try {
System.out.println(
"Message reveived: " + ((TextMessage) message).getText());
flag = false;
} catch (JMSException jmse) {
jmse.printStackTrace();
}
}
}
The username/password I m passing here is able to login to SAP MII and also able to check JNDI Browser in NWA
I m not sure what is wrong here.
Thanks
N G
Hi Roman,
I have a similar class connecting to Queue.
JMS Client Example - Using Java - SAP Library
with name Simple client. It is also trying to connect to same SAP instance and getting the exception.
Code is as follows:
import java.util.Properties;
import javax.jms.*;
import javax.naming.*;
/**
* The SimpleClient class sends several messages to a queue.
*/
public class SimpleClient {
private static final String USER = "Administrator";
private static final String PASSWORD = "abc123";
private static final String SAP_NAMING_PROVIDER_URL = "saptestinst:50004";
private static final String SAP_INITIAL_CONTEXT_FACTORY_IMPL ="com.sap.engine.services.jndi.InitialContextFactoryImpl";
/**
* Main method.
*/
public static void main(String[] args) {
Context jndiContext = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Queue queue = null;
QueueSender queueSender = null;
TextMessage message = null;
final int NUM_MSGS = 3;
/* JNDI service naming environment properties initialization */
Properties ctxProp = new Properties();
ctxProp.put(Context.INITIAL_CONTEXT_FACTORY, SAP_INITIAL_CONTEXT_FACTORY_IMPL);
ctxProp.put(Context.PROVIDER_URL, SAP_NAMING_PROVIDER_URL);
ctxProp.put(Context.SECURITY_PRINCIPAL, USER);
ctxProp.put(Context.SECURITY_CREDENTIALS, PASSWORD);
/*
* Create a JNDI API InitialContext object.
*/
try {
jndiContext = new InitialContext(ctxProp);
} catch (NamingException e) {
System.out.println("Could not create JNDI API" + "context: " + e.toString());
e.printStackTrace();
}
/*
* Look up connection factory and queue. If either does not exist, exit.
* If you want to lookup to JMS Connector Factory you should specify
* argument with value "mdb". Otherwise, for using JMS Provider Factory
* directly the argument should be with value "java".
*/
if (args[0].equals("mdb")) {
System.out.println("Inside mdb");
try {
queueConnectionFactory =(QueueConnectionFactory) jndiContext.lookup("java:comp/env/jms/MyQueueConnectionFactory");
queue = (Queue) jndiContext.lookup("java:comp/env/jms/QueueName");
} catch (NamingException e) {
System.out.println("JNDI API lookup failed: " + e.toString());
System.exit(1);
}
} else if (args[0].equals("java")) {
System.out.println("Inside java");
try {
queueConnectionFactory =(QueueConnectionFactory) jndiContext.lookup("jmsfactory/default/QueueConnectionFactory");
queue = (Queue) jndiContext.lookup("jmsqueues/default/JMSTestDestination");
} catch (NamingException e) {
System.out.println("JNDI API lookup failed: " + e.toString());
e.printStackTrace();
System.exit(1);
}
}
/*
* Create connection. Create session from connection; false means
* session is not transacted. Create sender and text message. Send
* messages, verifying text slightly. Finally, close connection.
*/
try {
queueConnection = queueConnectionFactory.createQueueConnection();
queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
queueSender = queueSession.createSender(queue);
message = queueSession.createTextMessage();
for (int i = 0; i < NUM_MSGS; i++) {
message.setText("This is message: " + (i + 1));
System.out.println("Sending message: " + message.getText());
queueSender.send(message);
}
} catch (JMSException e) {
System.out.println(" JMS Exception occured: " + e.toString());
e.printStackTrace();
} finally {
if (queueConnection != null) {
try {
queueConnection.close();
} catch (JMSException e) {
e.printStackTrace();
}
}
System.exit(0);
}
}
}
I want to know, is there any specific role missing for the user, that its throwing the exception, or its some other issue.
Thanks,
N G
The easiest way is to rule out permissions all-together by assigning the AS Java Admin role to the account and see if it works. If not then perhaps access the JNDI context requires additional permissions...I also notice that you are casting to a Queue and not a Topic, not sure why this is the case.
Also, a while back I wrote something along these lines to prove it could be done:
//Look up a JMS connection factory
TopicConnectionFactory conFactory = (TopicConnectionFactory)jndi.lookup("jmsfactory/default/JMSTopicConnFactory_SamCastro");
// Create a JMS connection
TopicConnection connection = conFactory.createTopicConnection("Administrator", "abcd1234");
// Look up a JMS topic
Topic miiTopic = (Topic)jndi.lookup("jmstopics/default/JMSTopic_SamCastro");
// Create a JMS subscriber
TopicSubscriber subscriber = subSession.createSubscriber(miiTopic);
At the time it worked fine for me so please note there are permissions to access the JNDI lookup and also for the topic connection...verify you have permissions for both.
Sam
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.