下面列出了怎么用javax.management.ServiceNotFoundException的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 500 - Internal Server Error
*/
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(ServiceNotFoundException.class)
public Response handleServiceException(ServiceNotFoundException e) {
String msg = "服务内部异常:" + e.getMessage();
log.error(msg, e);
return new Response().failure(msg);
}
/**
* Appends the specified URL to the list of URLs to search for classes and
* resources.
* @exception ServiceNotFoundException The specified URL is malformed.
*/
public void addURL(String url) throws ServiceNotFoundException {
try {
URL ur = new URL(url);
if (!Arrays.asList(getURLs()).contains(ur))
super.addURL(ur);
} catch (MalformedURLException e) {
if (MLET_LOGGER.isLoggable(Level.FINEST)) {
MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
"addUrl", "Malformed URL: " + url, e);
}
throw new
ServiceNotFoundException("The specified URL is malformed");
}
}
/**
* Appends the specified URL to the list of URLs to search for classes and
* resources.
* @exception ServiceNotFoundException The specified URL is malformed.
*/
public void addURL(String url) throws ServiceNotFoundException {
try {
URL ur = new URL(url);
if (!Arrays.asList(getURLs()).contains(ur))
super.addURL(ur);
} catch (MalformedURLException e) {
if (MLET_LOGGER.isLoggable(Level.FINEST)) {
MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
"addUrl", "Malformed URL: " + url, e);
}
throw new
ServiceNotFoundException("The specified URL is malformed");
}
}
/**
* Appends the specified URL to the list of URLs to search for classes and
* resources.
* @exception ServiceNotFoundException The specified URL is malformed.
*/
public void addURL(String url) throws ServiceNotFoundException {
try {
URL ur = new URL(url);
if (!Arrays.asList(getURLs()).contains(ur))
super.addURL(ur);
} catch (MalformedURLException e) {
if (MLET_LOGGER.isLoggable(Level.FINEST)) {
MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
"addUrl", "Malformed URL: " + url, e);
}
throw new
ServiceNotFoundException("The specified URL is malformed");
}
}
/**
* Appends the specified URL to the list of URLs to search for classes and
* resources.
* @exception ServiceNotFoundException The specified URL is malformed.
*/
public void addURL(String url) throws ServiceNotFoundException {
try {
URL ur = new URL(url);
if (!Arrays.asList(getURLs()).contains(ur))
super.addURL(ur);
} catch (MalformedURLException e) {
if (MLET_LOGGER.isLoggable(Level.FINEST)) {
MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
"addUrl", "Malformed URL: " + url, e);
}
throw new
ServiceNotFoundException("The specified URL is malformed");
}
}
/**
* Appends the specified URL to the list of URLs to search for classes and
* resources.
* @exception ServiceNotFoundException The specified URL is malformed.
*/
public void addURL(String url) throws ServiceNotFoundException {
try {
URL ur = new URL(url);
if (!Arrays.asList(getURLs()).contains(ur))
super.addURL(ur);
} catch (MalformedURLException e) {
if (MLET_LOGGER.isLoggable(Level.FINEST)) {
MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
"addUrl", "Malformed URL: " + url, e);
}
throw new
ServiceNotFoundException("The specified URL is malformed");
}
}
/**
* Appends the specified URL to the list of URLs to search for classes and
* resources.
* @exception ServiceNotFoundException The specified URL is malformed.
*/
public void addURL(String url) throws ServiceNotFoundException {
try {
URL ur = new URL(url);
if (!Arrays.asList(getURLs()).contains(ur))
super.addURL(ur);
} catch (MalformedURLException e) {
if (MLET_LOGGER.isLoggable(Level.FINEST)) {
MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
"addUrl", "Malformed URL: " + url, e);
}
throw new
ServiceNotFoundException("The specified URL is malformed");
}
}
/**
* Appends the specified URL to the list of URLs to search for classes and
* resources.
* @exception ServiceNotFoundException The specified URL is malformed.
*/
public void addURL(String url) throws ServiceNotFoundException {
try {
URL ur = new URL(url);
if (!Arrays.asList(getURLs()).contains(ur))
super.addURL(ur);
} catch (MalformedURLException e) {
if (MLET_LOGGER.isLoggable(Level.FINEST)) {
MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
"addUrl", "Malformed URL: " + url, e);
}
throw new
ServiceNotFoundException("The specified URL is malformed");
}
}
/**
* Appends the specified URL to the list of URLs to search for classes and
* resources.
* @exception ServiceNotFoundException The specified URL is malformed.
*/
public void addURL(String url) throws ServiceNotFoundException {
try {
URL ur = new URL(url);
if (!Arrays.asList(getURLs()).contains(ur))
super.addURL(ur);
} catch (MalformedURLException e) {
if (MLET_LOGGER.isLoggable(Level.FINEST)) {
MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
"addUrl", "Malformed URL: " + url, e);
}
throw new
ServiceNotFoundException("The specified URL is malformed");
}
}
/**
* Appends the specified URL to the list of URLs to search for classes and
* resources.
* @exception ServiceNotFoundException The specified URL is malformed.
*/
public void addURL(String url) throws ServiceNotFoundException {
try {
URL ur = new URL(url);
if (!Arrays.asList(getURLs()).contains(ur))
super.addURL(ur);
} catch (MalformedURLException e) {
if (MLET_LOGGER.isLoggable(Level.DEBUG)) {
MLET_LOGGER.log(Level.DEBUG, "Malformed URL: " + url, e);
}
throw new
ServiceNotFoundException("The specified URL is malformed");
}
}
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
String testSrc = System.getProperty("test.src");
System.out.println("test.src = " + testSrc);
String urlCodebase;
if (testSrc.startsWith("/")) {
urlCodebase =
"file:" + testSrc.replace(File.separatorChar, '/') + "/";
} else {
urlCodebase =
"file:/" + testSrc.replace(File.separatorChar, '/') + "/";
}
String mletFile = urlCodebase + args[0];
System.out.println("MLet File = " + mletFile);
try {
mlet.getMBeansFromURL(mletFile);
System.out.println(
"TEST FAILED: Expected ServiceNotFoundException not thrown");
error = true;
} catch (ServiceNotFoundException e) {
if (e.getCause() == null) {
System.out.println("TEST FAILED: Got unexpected null cause " +
"in ServiceNotFoundException");
error = true;
} else if (!(e.getCause() instanceof IOException)) {
System.out.println("TEST FAILED: Got unexpected non-null " +
"cause in ServiceNotFoundException");
error = true;
} else {
System.out.println("TEST PASSED: Got expected non-null " +
"cause in ServiceNotFoundException");
error = false;
}
e.printStackTrace(System.out);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
try {
mlet.getMBeansFromURL("bogus://whatever");
System.out.println("TEST FAILED: Expected " +
ServiceNotFoundException.class +
" exception not thrown.");
error = true;
} catch (ServiceNotFoundException e) {
if (e.getCause() == null) {
System.out.println("TEST FAILED: Got null cause in " +
ServiceNotFoundException.class +
" exception.");
error = true;
} else {
System.out.println("TEST PASSED: Got non-null cause in " +
ServiceNotFoundException.class +
" exception.");
error = false;
}
e.printStackTrace(System.out);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
try {
mlet.getMBeansFromURL("bogus://whatever");
System.out.println("TEST FAILED: Expected " +
ServiceNotFoundException.class +
" exception not thrown.");
error = true;
} catch (ServiceNotFoundException e) {
if (e.getCause() == null) {
System.out.println("TEST FAILED: Got null cause in " +
ServiceNotFoundException.class +
" exception.");
error = true;
} else {
System.out.println("TEST PASSED: Got non-null cause in " +
ServiceNotFoundException.class +
" exception.");
error = false;
}
e.printStackTrace(System.out);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
String testSrc = System.getProperty("test.src");
System.out.println("test.src = " + testSrc);
String urlCodebase;
if (testSrc.startsWith("/")) {
urlCodebase =
"file:" + testSrc.replace(File.separatorChar, '/') + "/";
} else {
urlCodebase =
"file:/" + testSrc.replace(File.separatorChar, '/') + "/";
}
String mletFile = urlCodebase + args[0];
System.out.println("MLet File = " + mletFile);
try {
mlet.getMBeansFromURL(mletFile);
System.out.println(
"TEST FAILED: Expected ServiceNotFoundException not thrown");
error = true;
} catch (ServiceNotFoundException e) {
if (e.getCause() == null) {
System.out.println("TEST FAILED: Got unexpected null cause " +
"in ServiceNotFoundException");
error = true;
} else if (!(e.getCause() instanceof IOException)) {
System.out.println("TEST FAILED: Got unexpected non-null " +
"cause in ServiceNotFoundException");
error = true;
} else {
System.out.println("TEST PASSED: Got expected non-null " +
"cause in ServiceNotFoundException");
error = false;
}
e.printStackTrace(System.out);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
try {
mlet.getMBeansFromURL("bogus://whatever");
System.out.println("TEST FAILED: Expected " +
ServiceNotFoundException.class +
" exception not thrown.");
error = true;
} catch (ServiceNotFoundException e) {
if (e.getCause() == null) {
System.out.println("TEST FAILED: Got null cause in " +
ServiceNotFoundException.class +
" exception.");
error = true;
} else {
System.out.println("TEST PASSED: Got non-null cause in " +
ServiceNotFoundException.class +
" exception.");
error = false;
}
e.printStackTrace(System.out);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
try {
mlet.getMBeansFromURL("bogus://whatever");
System.out.println("TEST FAILED: Expected " +
ServiceNotFoundException.class +
" exception not thrown.");
error = true;
} catch (ServiceNotFoundException e) {
if (e.getCause() == null) {
System.out.println("TEST FAILED: Got null cause in " +
ServiceNotFoundException.class +
" exception.");
error = true;
} else {
System.out.println("TEST PASSED: Got non-null cause in " +
ServiceNotFoundException.class +
" exception.");
error = false;
}
e.printStackTrace(System.out);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
String testSrc = System.getProperty("test.src");
System.out.println("test.src = " + testSrc);
String urlCodebase;
if (testSrc.startsWith("/")) {
urlCodebase =
"file:" + testSrc.replace(File.separatorChar, '/') + "/";
} else {
urlCodebase =
"file:/" + testSrc.replace(File.separatorChar, '/') + "/";
}
String mletFile = urlCodebase + args[0];
System.out.println("MLet File = " + mletFile);
try {
mlet.getMBeansFromURL(mletFile);
System.out.println(
"TEST FAILED: Expected ServiceNotFoundException not thrown");
error = true;
} catch (ServiceNotFoundException e) {
if (e.getCause() == null) {
System.out.println("TEST FAILED: Got unexpected null cause " +
"in ServiceNotFoundException");
error = true;
} else if (!(e.getCause() instanceof IOException)) {
System.out.println("TEST FAILED: Got unexpected non-null " +
"cause in ServiceNotFoundException");
error = true;
} else {
System.out.println("TEST PASSED: Got expected non-null " +
"cause in ServiceNotFoundException");
error = false;
}
e.printStackTrace(System.out);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
try {
mlet.getMBeansFromURL("bogus://whatever");
System.out.println("TEST FAILED: Expected " +
ServiceNotFoundException.class +
" exception not thrown.");
error = true;
} catch (ServiceNotFoundException e) {
if (e.getCause() == null) {
System.out.println("TEST FAILED: Got null cause in " +
ServiceNotFoundException.class +
" exception.");
error = true;
} else {
System.out.println("TEST PASSED: Got non-null cause in " +
ServiceNotFoundException.class +
" exception.");
error = false;
}
e.printStackTrace(System.out);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
try {
mlet.getMBeansFromURL("bogus://whatever");
System.out.println("TEST FAILED: Expected " +
ServiceNotFoundException.class +
" exception not thrown.");
error = true;
} catch (ServiceNotFoundException e) {
if (e.getCause() == null) {
System.out.println("TEST FAILED: Got null cause in " +
ServiceNotFoundException.class +
" exception.");
error = true;
} else {
System.out.println("TEST PASSED: Got non-null cause in " +
ServiceNotFoundException.class +
" exception.");
error = false;
}
e.printStackTrace(System.out);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
String testSrc = System.getProperty("test.src");
System.out.println("test.src = " + testSrc);
String urlCodebase;
if (testSrc.startsWith("/")) {
urlCodebase =
"file:" + testSrc.replace(File.separatorChar, '/') + "/";
} else {
urlCodebase =
"file:/" + testSrc.replace(File.separatorChar, '/') + "/";
}
String mletFile = urlCodebase + args[0];
System.out.println("MLet File = " + mletFile);
try {
mlet.getMBeansFromURL(mletFile);
System.out.println(
"TEST FAILED: Expected ServiceNotFoundException not thrown");
error = true;
} catch (ServiceNotFoundException e) {
if (e.getCause() == null) {
System.out.println("TEST FAILED: Got unexpected null cause " +
"in ServiceNotFoundException");
error = true;
} else if (!(e.getCause() instanceof IOException)) {
System.out.println("TEST FAILED: Got unexpected non-null " +
"cause in ServiceNotFoundException");
error = true;
} else {
System.out.println("TEST PASSED: Got expected non-null " +
"cause in ServiceNotFoundException");
error = false;
}
e.printStackTrace(System.out);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
try {
mlet.getMBeansFromURL("bogus://whatever");
System.out.println("TEST FAILED: Expected " +
ServiceNotFoundException.class +
" exception not thrown.");
error = true;
} catch (ServiceNotFoundException e) {
if (e.getCause() == null) {
System.out.println("TEST FAILED: Got null cause in " +
ServiceNotFoundException.class +
" exception.");
error = true;
} else {
System.out.println("TEST PASSED: Got non-null cause in " +
ServiceNotFoundException.class +
" exception.");
error = false;
}
e.printStackTrace(System.out);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
String testSrc = System.getProperty("test.src");
System.out.println("test.src = " + testSrc);
String urlCodebase;
if (testSrc.startsWith("/")) {
urlCodebase =
"file:" + testSrc.replace(File.separatorChar, '/') + "/";
} else {
urlCodebase =
"file:/" + testSrc.replace(File.separatorChar, '/') + "/";
}
String mletFile = urlCodebase + args[0];
System.out.println("MLet File = " + mletFile);
try {
mlet.getMBeansFromURL(mletFile);
System.out.println(
"TEST FAILED: Expected ServiceNotFoundException not thrown");
error = true;
} catch (ServiceNotFoundException e) {
if (e.getCause() == null) {
System.out.println("TEST FAILED: Got unexpected null cause " +
"in ServiceNotFoundException");
error = true;
} else if (!(e.getCause() instanceof IOException)) {
System.out.println("TEST FAILED: Got unexpected non-null " +
"cause in ServiceNotFoundException");
error = true;
} else {
System.out.println("TEST PASSED: Got expected non-null " +
"cause in ServiceNotFoundException");
error = false;
}
e.printStackTrace(System.out);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
try {
mlet.getMBeansFromURL("bogus://whatever");
System.out.println("TEST FAILED: Expected " +
ServiceNotFoundException.class +
" exception not thrown.");
error = true;
} catch (ServiceNotFoundException e) {
if (e.getCause() == null) {
System.out.println("TEST FAILED: Got null cause in " +
ServiceNotFoundException.class +
" exception.");
error = true;
} else {
System.out.println("TEST PASSED: Got non-null cause in " +
ServiceNotFoundException.class +
" exception.");
error = false;
}
e.printStackTrace(System.out);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
try {
mlet.getMBeansFromURL("bogus://whatever");
System.out.println("TEST FAILED: Expected " +
ServiceNotFoundException.class +
" exception not thrown.");
error = true;
} catch (ServiceNotFoundException e) {
if (e.getCause() == null) {
System.out.println("TEST FAILED: Got null cause in " +
ServiceNotFoundException.class +
" exception.");
error = true;
} else {
System.out.println("TEST PASSED: Got non-null cause in " +
ServiceNotFoundException.class +
" exception.");
error = false;
}
e.printStackTrace(System.out);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}
/**
* <p>Captures the current state of this MBean instance and writes
* it out to the persistent store. The state stored could include
* attribute and operation values.</p>
*
* <p>If the implementation of this class does not support
* persistence, an {@link MBeanException} wrapping a {@link
* ServiceNotFoundException} is thrown.</p>
*
* <p>Persistence policy from the MBean and attribute descriptor
* is used to guide execution of this method. The MBean should be
* stored if 'persistPolicy' field is:</p>
*
* <PRE>{@literal != "never"
* = "always"
* = "onTimer" and now > 'lastPersistTime' + 'persistPeriod'
* = "NoMoreOftenThan" and now > 'lastPersistTime' + 'persistPeriod'
* = "onUnregister"
* }</PRE>
*
* <p>Do not store the MBean if 'persistPolicy' field is:</p>
* <PRE>{@literal
* = "never"
* = "onUpdate"
* = "onTimer" && now < 'lastPersistTime' + 'persistPeriod'
* }</PRE>
*
* @exception MBeanException Wraps another exception, or
* persistence is not supported
* @exception RuntimeOperationsException Wraps exceptions from the
* persistence mechanism
* @exception InstanceNotFoundException Could not find/access the
* persistent store
*/
public void store()
throws MBeanException, RuntimeOperationsException,
InstanceNotFoundException {
final ServiceNotFoundException x = new ServiceNotFoundException(
"Persistence not supported for this MBean");
throw new MBeanException(x, x.getMessage());
}
/**
* Loads a text file containing MLET tags that define the MBeans to
* be added to the MBean server. The location of the text file is specified by
* a URL. The MBeans specified in the MLET file will be instantiated and
* registered in the MBean server.
*
* @param url The URL of the text file to be loaded as URL object.
*
* @return A set containing one entry per MLET tag in the m-let text file loaded.
* Each entry specifies either the ObjectInstance for the created MBean, or a throwable object
* (that is, an error or an exception) if the MBean could not be created.
*
* @exception ServiceNotFoundException One of the following errors has occurred: The m-let text file does
* not contain an MLET tag, the m-let text file is not found, a mandatory
* attribute of the MLET tag is not specified, the value of url is
* null.
* @exception IllegalStateException MLet MBean is not registered with an MBeanServer.
*/
public Set<Object> getMBeansFromURL(URL url)
throws ServiceNotFoundException {
if (url == null) {
throw new ServiceNotFoundException("The specified URL is null");
}
return getMBeansFromURL(url.toString());
}
/**
* <p>Instantiates this MBean instance with the data found for
* the MBean in the persistent store. The data loaded could include
* attribute and operation values.</p>
*
* <p>This method should be called during construction or
* initialization of this instance, and before the MBean is
* registered with the MBeanServer.</p>
*
* <p>If the implementation of this class does not support
* persistence, an {@link MBeanException} wrapping a {@link
* ServiceNotFoundException} is thrown.</p>
*
* @exception MBeanException Wraps another exception, or
* persistence is not supported
* @exception RuntimeOperationsException Wraps exceptions from the
* persistence mechanism
* @exception InstanceNotFoundException Could not find or load
* this MBean from persistent storage
*/
public void load()
throws MBeanException, RuntimeOperationsException,
InstanceNotFoundException {
final ServiceNotFoundException x = new ServiceNotFoundException(
"Persistence not supported for this MBean");
throw new MBeanException(x, x.getMessage());
}
/**
* <p>Captures the current state of this MBean instance and writes
* it out to the persistent store. The state stored could include
* attribute and operation values.</p>
*
* <p>If the implementation of this class does not support
* persistence, an {@link MBeanException} wrapping a {@link
* ServiceNotFoundException} is thrown.</p>
*
* <p>Persistence policy from the MBean and attribute descriptor
* is used to guide execution of this method. The MBean should be
* stored if 'persistPolicy' field is:</p>
*
* <PRE>{@literal != "never"
* = "always"
* = "onTimer" and now > 'lastPersistTime' + 'persistPeriod'
* = "NoMoreOftenThan" and now > 'lastPersistTime' + 'persistPeriod'
* = "onUnregister"
* }</PRE>
*
* <p>Do not store the MBean if 'persistPolicy' field is:</p>
* <PRE>{@literal
* = "never"
* = "onUpdate"
* = "onTimer" && now < 'lastPersistTime' + 'persistPeriod'
* }</PRE>
*
* @exception MBeanException Wraps another exception, or
* persistence is not supported
* @exception RuntimeOperationsException Wraps exceptions from the
* persistence mechanism
* @exception InstanceNotFoundException Could not find/access the
* persistent store
*/
public void store()
throws MBeanException, RuntimeOperationsException,
InstanceNotFoundException {
final ServiceNotFoundException x = new ServiceNotFoundException(
"Persistence not supported for this MBean");
throw new MBeanException(x, x.getMessage());
}
/**
* Loads a text file containing MLET tags that define the MBeans to
* be added to the MBean server. The location of the text file is specified by
* a URL. The MBeans specified in the MLET file will be instantiated and
* registered in the MBean server.
*
* @param url The URL of the text file to be loaded as URL object.
*
* @return A set containing one entry per MLET tag in the m-let text file loaded.
* Each entry specifies either the ObjectInstance for the created MBean, or a throwable object
* (that is, an error or an exception) if the MBean could not be created.
*
* @exception ServiceNotFoundException One of the following errors has occurred: The m-let text file does
* not contain an MLET tag, the m-let text file is not found, a mandatory
* attribute of the MLET tag is not specified, the value of url is
* null.
* @exception IllegalStateException MLet MBean is not registered with an MBeanServer.
*/
public Set<Object> getMBeansFromURL(URL url)
throws ServiceNotFoundException {
if (url == null) {
throw new ServiceNotFoundException("The specified URL is null");
}
return getMBeansFromURL(url.toString());
}
/**
* <p>Captures the current state of this MBean instance and writes
* it out to the persistent store. The state stored could include
* attribute and operation values.</p>
*
* <p>If the implementation of this class does not support
* persistence, an {@link MBeanException} wrapping a {@link
* ServiceNotFoundException} is thrown.</p>
*
* <p>Persistence policy from the MBean and attribute descriptor
* is used to guide execution of this method. The MBean should be
* stored if 'persistPolicy' field is:</p>
*
* <PRE>{@literal != "never"
* = "always"
* = "onTimer" and now > 'lastPersistTime' + 'persistPeriod'
* = "NoMoreOftenThan" and now > 'lastPersistTime' + 'persistPeriod'
* = "onUnregister"
* }</PRE>
*
* <p>Do not store the MBean if 'persistPolicy' field is:</p>
* <PRE>{@literal
* = "never"
* = "onUpdate"
* = "onTimer" && now < 'lastPersistTime' + 'persistPeriod'
* }</PRE>
*
* @exception MBeanException Wraps another exception, or
* persistence is not supported
* @exception RuntimeOperationsException Wraps exceptions from the
* persistence mechanism
* @exception InstanceNotFoundException Could not find/access the
* persistent store
*/
public void store()
throws MBeanException, RuntimeOperationsException,
InstanceNotFoundException {
final ServiceNotFoundException x = new ServiceNotFoundException(
"Persistence not supported for this MBean");
throw new MBeanException(x, x.getMessage());
}