Hi there,
I'm trying to get an external JMX client to connect to a SAP Web AS ABAP+Java 640 (Unicode, SP 9).
My first problem was that I couldn't find the file
client.jar as written in "Compile and Run your Client" of
the JMX Service Interface documentation. I could solve the
"class not found" problems by using sapj2eeclient.jar, so
I think the file has just been renamed.
I then tried to run the following code, which has been
taken more or less from the "Connecting to an MBeanServer"
example.
import java.util.Properties;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.naming.Context;
import com.sap.jmx.ObjectNameFactory;
import com.sap.jmx.remote.JmxConnectionFactory;
public class Client {
public Client(
) {
}
private void run(
) {
try {
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");
props.setProperty(Context.SECURITY_PRINCIPAL, "J2EE_ADMIN");
props.setProperty(Context.SECURITY_CREDENTIALS, "password");
props.setProperty(Context.PROVIDER_URL, "my-server:50004");
MBeanServerConnection mbsc = null;
mbsc = JmxConnectionFactory.getMBeanServerConnection(
JmxConnectionFactory.PROTOCOL_ENGINE_P4, props);
String path = "Root/Services/Memory/AllocatedMemory";
ObjectName name = null;
name = ObjectNameFactory.getNameForMonitorPerNode(
ObjectName.quote(path), null, null);
System.out.println("ObjectName: " + name.getCanonicalName());
Integer value = (Integer)mbsc.invoke(name, "getValue", null, null);
System.out.println("Value: " + value);
}
catch(Exception ex) {
ex.printStackTrace();
}
}
public static void main(
String[] args
) {
new Client().run();
}
}
Unfortunately, I get the following error:
com.sap.engine.services.jmx.exception.JmxConnectorException: Unable to connect to connector server.
at com.sap.engine.services.jmx.connector.p4.P4ConnectorClient.<init>(P4ConnectorClient.java:96)
at com.sap.engine.services.jmx.connector.p4.ConnectorFactory.getJmxConnector(ConnectorFactory.java:31)
at com.sap.jmx.remote.JmxConnectionFactory.getConnector(JmxConnectionFactory.java:191)
at com.sap.jmx.remote.JmxConnectionFactory.getMBeanServerConnection(JmxConnectionFactory.java:92)
at Client.run(Client.java:29)
at Client.main(Client.java:51)
Caused by: com.sap.engine.services.jndi.persistent.exceptions.NamingException: Exception while trying to get InitialContext. [Root exception is com.sap.engine.services.security.exceptions.BaseLoginException: Cannot create new RemoteLoginContext instance.]
at com.sap.engine.services.jndi.InitialContextFactoryImpl.getInitialContext(InitialContextFactoryImpl.java:538)
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.sap.engine.services.jmx.connector.p4.P4ConnectorClient.<init>(P4ConnectorClient.java:69)
... 5 more
Caused by: com.sap.engine.services.security.exceptions.BaseLoginException: Cannot create new RemoteLoginContext instance.
at com.sap.engine.services.security.remote.login.RemoteLoginContext.<init>(RemoteLoginContext.java:98)
at com.sap.engine.services.jndi.implclient.LoginHelper.clientSideLogin(LoginHelper.java:78)
at com.sap.engine.services.jndi.InitialContextFactoryImpl.getInitialContext(InitialContextFactoryImpl.java:402)
... 10 more
Caused by: java.lang.NullPointerException
at com.sap.engine.services.security.remote.RemoteSecurity_Stub.getRemoteLoginContext(RemoteSecurity_Stub.java:678)
at com.sap.engine.services.security.remote.login.RemoteLoginContext.<init>(RemoteLoginContext.java:93)
... 12 more
Am I doing something wrong? Any help or hint would be
greatly appreciated.
Regards, Bernd
Request clarification before answering.
Hello,
I am working on a similar JMX External Client to pull data from the monitoring service. I am running into a similar error. Am I perhaps missing an import? If any of you could share your work on how to get a valid p4 connection/MBeanServerConnection that would be much appreciated.
import java.util.*;
import javax.naming.Context;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import com.sap.jmx.ObjectNameFactory;
import com.sap.jmx.remote.JmxConnectionFactory;
public class JMXProgram {
public static void main(String[] args) {
System.out.println(" Class execution started");
try {
Properties connectionProperties = new Properties();
connectionProperties.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.sap.engine.services.jndi.InitialContextFactoryImpl");
connectionProperties.setProperty(Context.PROVIDER_URL, "<hostname>:<p4_port>");
connectionProperties.setProperty(Context.SECURITY_PRINCIPAL, "<username>");
connectionProperties.setProperty(Context.SECURITY_CREDENTIALS, "<password>");
System.out.println(JmxConnectionFactory.PROTOCOL_ENGINE_P4);
MBeanServerConnection mbsc = JmxConnectionFactory.getMBeanServerConnection(JmxConnectionFactory.PROTOCOL_ENGINE_P4, connectionProperties);
System.out.println("Made it this far");
String path = "/Root/Services/Memory/AllocatedMemory";
ObjectName name = null;
name = ObjectNameFactory.getNameForMonitorPerNode(ObjectName.quote(path), null, null);
System.out.println("ObjectName: " + name.getCanonicalName());
Integer value = (Integer)mbsc.invoke(name, "getValue", null, null);
System.out.println("Value: " + value);
}
catch (Exception e) {
System.out.println("Exception caught!");
//System.out.println(e.getMessage());
System.out.println(e.toString());
}
System.out.println(" Class execution complete");
}
}
Here is the output of the program:
Class execution started
service:jmx:com.sap.engine.services.jmx.connector.p4:
Exception caught!
com.sap.engine.services.jmx.exception.JmxConnectorException: Unable to connect to connector server.
Class execution complete
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Justin,
check this might help full to u
http://nanobitinc.com/education/training/SAP/NetWeaver/Monitoring%20and%20Management.pdf
http://help.sap.com/saphelp_webas630/helpdata/en/64/617cfb94845d468b0498b4b2c53d74/content.htm
let me know am i reached ur destiny
bvr
Edited by: bvr on Apr 20, 2009 7:50 AM
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.