cancel
Showing results for 
Search instead for 
Did you mean: 
Subscribe

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

0 Likes
View Entire Topic
Former Member
0 Likes

Hello,

I reviewed the links you posted and they do provide the best information SAP has available.

The link to the the forum post is somewhat relevant - though it appears for an internal JMX Client to register an MBean. There is no code posted, only the error message and some xml config for a local J2EE application. What isn't disucssed in the post is how to monitor or query that bean. Again, I am working on an external JMX Client.

The SAP Help Documentation for 630 almost worked! I got the same error message however and was given warnings by NetWeaver Developer Studio the methods were deprecated. I am using 700 NW04S. Here is where the 630 documentation differed:

MBeanServerConnection mbsc =

JmxClientFactory.getJmxClient().getMBeanServerConnection

(P4ConnectorClient.ADDRESS_PREFIX, connectionProperties);

The PDF link is a copy of the SAP Help Documentation for version 700. An excerpt from the article:

import java.util.Properties;

import javax.naming.Context;

import com.sap.jmx.remote.JmxConnectionFactory;

...

// set the connection properties for the RMI-P4 connection

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>");

// create the MBeanServerConnection

MBeanServerConnection mbsc =

JmxConnectionFactory.getMBeanServerConnection(JmxConnectionFactory.

PROTOCOL_ENGINE_P4, connectionProperties);

This is what based my above code on. The documentation states this is what is needed to create a connection to the MBean Server. There is a final note:

If you are either accessing a local MBeanServer from an application, or using

the RMI-P4 JMX Connector, you have to be logged in with a user in the default

administrator role.

I am following this article exactly, as I have used the Admin user for the Java AS. This user is in the Administrators group, has the Administrator role - as well Content Admin, System Admin and User admin. Becuase of this, I don't think this is a permission issue.

I have also tried this from a Portal Abstract Component, (internal JMX Client) and get similar results:

java.rmi.RemoteException: unable to create connector; nested exception is: java.lang.ClassCastException

Thanks!

Former Member
0 Likes

try port number 50104 instead of 50004