Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JMX Connector

Status
Not open for further replies.

garlam

Programmer
Oct 15, 2004
10
IT
I developed a simple Java client in order to retrieve several information from WebSphere AS using JMX. Thi exception is raised:

"Could not create SOAP Connector to connect to host localhost at port 8880"

This is the code:

Code:
/*
 * XWasClient.java
 */

package com.xech.ws.client;

// Librerie WebSphere 
import com.ibm.websphere.management.AdminClient;
import com.ibm.websphere.management.AdminClientFactory;

import com.ibm.websphere.management.exception.ConnectorException;  

// Librerie java
import javax.management.ObjectName;
import javax.management.MalformedObjectNameException;

import java.util.Properties;
import java.util.Set;

/**
 * Client per WebSphere Application Server. Recupera i dati
 * tramite JMX.
 */
public class XWasClient {
	
	protected final int NUM_PARAMS 	= 4;
	
	protected final String USAGE		=	"USAGE: " + XWasClient.class.getName() + " <host> <port> <user> <password>";
	
	protected String host;
	protected String port;
	protected String user;
	protected String password;
	
	///////////
	
	/**
	 * Metodo main.
	 *
	 * @param args Argomenti passati da linea di comando
	 */
	public static void main(String args[]) {
		new XWasClient(args);
	}
	
	/////////////
	
	/**
	 * Costruttore
	 *
	 * @param args Argomenti passati da linea di comando
	 */
	public XWasClient(String args[]) {
		
		if (args.length < NUM_PARAMS) {
			System.out.println(USAGE);
			System.exit(0);
		}
		
		// parsing parametri
		host 			= args[0];
		port 			= args[1];
		user 			= args[2];
		password 	= args[3];
		
		System.out.println("HOST:     " + host);
		System.out.println("PORT:     " + port);
		System.out.println("USER:     " + user);
		System.out.println("PASSWORD: " + password);
		
		try {
			connect();
		}
		catch (ConnectorException e) {
			System.out.println("Exception creating admin client: " + e);
		}
		catch (Exception e) {
			System.out.println("Exception while contacting WAS server: " + e);
		}
	}
	
	/**
	 * Effettua la connessione all'application server
	 */
	protected void connect() throws ConnectorException, MalformedObjectNameException {
		
		// Costruisco il client
		
		Properties connectProps = new Properties();
		
		connectProps.setProperty(AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_SOAP);

		connectProps.setProperty(AdminClient.CONNECTOR_HOST, 	host);
		connectProps.setProperty(AdminClient.CONNECTOR_PORT, 	port);
		connectProps.setProperty(AdminClient.USERNAME, 				user);
		connectProps.setProperty(AdminClient.PASSWORD, 				password);

		AdminClient adminClient = AdminClientFactory.createAdminClient(connectProps);
		
		// Recupero i parametri
		
		String query = "WebSphere:*,type=JVM,j2eeType=JVM";
		ObjectName queryName = new ObjectName(query);
		ObjectName jvm = null;
		Set s = adminClient.queryNames(queryName, null);
		if (!s.isEmpty())
    	jvm = (ObjectName)s.iterator().next();
		else
    	System.out.println("jvm MBean was not found");
		
		
	}
}

Using the wsadmin client all works fine. Any suggestions ?

Thanks in advance,
Mauro.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top