cancel
Showing results for 
Search instead for 
Did you mean: 

External JMX client cannot connect to MBeanServer

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (7)

Answers (7)

Former Member
0 Kudos

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 Kudos

try port number 50104 instead of 50004

Former Member
0 Kudos

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

ravindra_bollapalli2
Active Contributor
0 Kudos
Former Member
0 Kudos

You guys have wrong key.

Should change the key to "/Services/Memory/AllocatedMemory".

Have a fun.

Former Member
0 Kudos

Hello Madhu,

i have the same problems too! - Can you email me your code to my e-mail-adress: ralf.steffens@t-systems.com ?

Thanks in advance.

Best Regards,

Ralf

Former Member
0 Kudos

Hello Madhu,

i have the same problems too! - Can you email me your code to my e-mail-adress: ralf.steffens@t-systems.com ?

Thanks in advance.

Best Regards,

Ralf

Former Member
0 Kudos

Hi Vladimir

thanks for your reply.

The real server name is called sap-640-sapdb and I called with the correct server name

(I have just changed password and server in the example code).

It was up and running, of course.

I could make it work, but only if my Client class is running localy on sap-640-sapdb.

I could not make it work to run remotely from my PC. I get the exception:


Caused by: java.rmi.ServerException: The server, that the client is connected with, isn't working.
The object is not redirectable!

Meanwhile I have installed a complete SAP NetWeaver Dev. Environment on my PC.

I get exactly the same error message, when I want to connect with Visual Administrator installed with the J2EE instance on my Windows PC to the J2EE instance running on the Linux box sap-640-sapdb.

Isn't it possible to use P4 protocol remotely?

Thanks, Bernd

Former Member
0 Kudos

Hi Bernd

I am successful in using a JMX client remotely for logging the HTTP session data from SAP WebAS 710 release. I have done this in the context of monitoring the number of HTTP sessions to correlate with Memory utilized on WebAS.

The piece of code that I wrote is more or less similar to what you posted in the thread here.

If you would like to have a look at it, just let me know so that I can mail it to your id.

Thanks and Regards

Madhu

Former Member
0 Kudos

Hi Madhu:

I find the same problem. Can you mail your code to me?

My email is : dhl_garf@hotmail.com

Thank you very much!

Best regards.

Garf

hans_harder
Explorer
0 Kudos

Hi Madhu, Garf

I have same problem, can you mail it also to me ?

My email is : postbus111@gmail.com

Thanks

hans

Former Member
0 Kudos

Hi Madhu,

I am using SAP WAS 6.4. I am having problems in connecting from a remote JMX client to obtain the metrics. Can you please email me your code?

My email-id is sridhar1975@gmail.com.

Thanks and Regards,

Sridhar Raj

Vlado
Advisor
Advisor
0 Kudos

Hi Bernd,

First, you have figured it out about the sapj2eeclient.jar - congratulations The reason for the current problem could be that your Web AS Java is not running. Please check that you have specified the correct connection parameters (my-server:50004) and that the server there is up and running.

Best regards,

Vladimir