/** * Return the MBean Names of all the defined resource references for this * application. */ public String[] getResources() { ContextResource[] resources = ((NamingResources)this.resource).findResources(); ArrayList<String> results = new ArrayList<String>(); for (int i = 0; i < resources.length; i++) { try { ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resources[i]); results.add(oname.toString()); } catch (MalformedObjectNameException e) { IllegalArgumentException iae = new IllegalArgumentException ("Cannot create object name for resource " + resources[i]); iae.initCause(e); throw iae; } } return results.toArray(new String[results.size()]); }
/** * Create, register, and return an MBean for this * <code>ContextResource</code> object. * * @param resource The ContextResource to be managed * * @exception Exception if an MBean cannot be created or registered */ public static DynamicMBean createMBean(ContextResource resource) throws Exception { String mname = createManagedName(resource); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { Exception e = new Exception("ManagedBean is not found with "+mname); throw new MBeanException(e); } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); DynamicMBean mbean = managed.createMBean(resource); ObjectName oname = createObjectName(domain, resource); if( mserver.isRegistered( oname )) { mserver.unregisterMBean(oname); } mserver.registerMBean(mbean, oname); return (mbean); }
/** * Deregister the MBean for this * <code>ContextResource</code> object. * * @param resource The ContextResource to be managed * * @exception Exception if an MBean cannot be deregistered */ public static void destroyMBean(ContextResource resource) throws Exception { // If this is a user database resource need to destroy groups, roles, // users and UserDatabase mbean if ("org.apache.catalina.UserDatabase".equals(resource.getType())) { destroyMBeanUserDatabase(resource.getName()); } String mname = createManagedName(resource); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { return; } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); ObjectName oname = createObjectName(domain, resource); if( mserver.isRegistered(oname )) mserver.unregisterMBean(oname); }
@Test public void testListBindings() throws Exception { Tomcat tomcat = getTomcatInstance(); tomcat.enableNaming(); // No file system docBase required StandardContext ctx = (StandardContext) tomcat.addContext("", null); // Create the resource ContextResource cr = new ContextResource(); cr.setName("list/foo"); cr.setType("org.apache.naming.resources.TesterObject"); cr.setProperty("factory", "org.apache.naming.resources.TesterFactory"); ctx.getNamingResources().addResource(cr); // Map the test Servlet Bug23950Servlet bug23950Servlet = new Bug23950Servlet(); Tomcat.addServlet(ctx, "bug23950Servlet", bug23950Servlet); ctx.addServletMapping("/", "bug23950Servlet"); tomcat.start(); ByteChunk bc = getUrl("http://localhost:" + getPort() + "/"); assertEquals("org.apache.naming.resources.TesterObject", bc.toString()); }
@Test public void testBeanFactory() throws Exception { Tomcat tomcat = getTomcatInstance(); tomcat.enableNaming(); // No file system docBase required StandardContext ctx = (StandardContext) tomcat.addContext("", null); // Create the resource ContextResource cr = new ContextResource(); cr.setName("bug50351"); cr.setType("org.apache.naming.resources.TesterObject"); cr.setProperty("factory", "org.apache.naming.factory.BeanFactory"); cr.setProperty("foo", "value"); ctx.getNamingResources().addResource(cr); // Map the test Servlet Bug50351Servlet bug50351Servlet = new Bug50351Servlet(); Tomcat.addServlet(ctx, "bug50351Servlet", bug50351Servlet); ctx.addServletMapping("/", "bug50351Servlet"); tomcat.start(); ByteChunk bc = getUrl("http://localhost:" + getPort() + "/"); assertEquals("value", bc.toString()); }
/** * Return the MBean Names of all the defined resource references for this * application. */ public String[] getResources() { ContextResource[] resources = ((NamingResources)this.resource).findResources(); ArrayList results = new ArrayList(); for (int i = 0; i < resources.length; i++) { try { ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resources[i]); results.add(oname.toString()); } catch (MalformedObjectNameException e) { IllegalArgumentException iae = new IllegalArgumentException ("Cannot create object name for resource " + resources[i]); iae.initCause(e); throw iae; } } return ((String[]) results.toArray(new String[results.size()])); }
/** * Return the MBean Names of all the defined resource references for this * application. */ public String[] getResources() { ContextResource[] resources = getNamingResources().findResources(); ArrayList results = new ArrayList(); for (int i = 0; i < resources.length; i++) { try { ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resources[i]); results.add(oname.toString()); } catch (MalformedObjectNameException e) { IllegalArgumentException iae = new IllegalArgumentException ("Cannot create object name for resource " + resources[i]); iae.initCause(e); throw iae; } } return ((String[]) results.toArray(new String[results.size()])); }
/** * Create, register, and return an MBean for this * <code>ContextResource</code> object. * * @param resource The ContextResource to be managed * * @exception Exception if an MBean cannot be created or registered */ static DynamicMBean createMBean(ContextResource resource) throws Exception { String mname = createManagedName(resource); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { Exception e = new Exception("ManagedBean is not found with "+mname); throw new MBeanException(e); } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); DynamicMBean mbean = managed.createMBean(resource); ObjectName oname = createObjectName(domain, resource); if( mserver.isRegistered( oname )) { mserver.unregisterMBean(oname); } mserver.registerMBean(mbean, oname); return (mbean); }
/** * Deregister the MBean for this * <code>ContextResource</code> object. * * @param resource The ContextResource to be managed * * @exception Exception if an MBean cannot be deregistered */ static void destroyMBean(ContextResource resource) throws Exception { String mname = createManagedName(resource); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { return; } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); ObjectName oname = createObjectName(domain, resource); if( mserver.isRegistered(oname )) mserver.unregisterMBean(oname); }
/** * Return the MBean Names of all the defined resource references for this * application. */ public String[] getResources() { ContextResource[] resources = ((NamingResources)this.resource).findResources(); ArrayList results = new ArrayList(); for (int i = 0; i < resources.length; i++) { try { ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resources[i]); results.add(oname.toString()); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException ("Cannot create object name for resource " + resources[i]); } } return ((String[]) results.toArray(new String[results.size()])); }
/** * Return the MBean Names of all the defined resource references for this * application. */ public String[] getResources() { ContextResource[] resources = getNamingResources().findResources(); ArrayList results = new ArrayList(); for (int i = 0; i < resources.length; i++) { try { ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resources[i]); results.add(oname.toString()); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException ("Cannot create object name for resource " + resources[i]); } } return ((String[]) results.toArray(new String[results.size()])); }
/** * Create, register, and return an MBean for this * <code>ContextResource</code> object. * * @param resource The ContextResource to be managed * * @exception Exception if an MBean cannot be created or registered */ public static ModelMBean createMBean(ContextResource resource) throws Exception { String mname = createManagedName(resource); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { Exception e = new Exception("ManagedBean is not found with "+mname); throw new MBeanException(e); } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); ModelMBean mbean = managed.createMBean(resource); ObjectName oname = createObjectName(domain, resource); mserver.registerMBean(mbean, oname); return (mbean); }
/** * Deregister the MBean for this * <code>ContextResource</code> object. * * @param resource The ContextResource to be managed * * @exception Exception if an MBean cannot be deregistered */ public static void destroyMBean(ContextResource resource) throws Exception { String mname = createManagedName(resource); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { return; } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); ObjectName oname = createObjectName(domain, resource); mserver.unregisterMBean(oname); }
/** * Set the specified resources in the naming context. */ public void addResource(ContextResource resource) { // Create a reference to the resource. Reference ref = new ResourceRef (resource.getType(), resource.getDescription(), resource.getScope(), resource.getAuth()); // Adding the additional parameters, if any addAdditionalParameters(resource.getNamingResources(), ref, resource.getName()); try { if (debug >= 2) { log(" Adding resource ref " + resource.getName()); log(" " + ref); } createSubcontexts(envCtx, resource.getName()); envCtx.bind(resource.getName(), ref); } catch (NamingException e) { log(sm.getString("naming.bindFailed", e)); } }
/** * Return the MBean Names of all the defined resource references for this * application. */ public String[] getResources() { ContextResource[] resources = ((NamingResources) this.resource).findResources(); ArrayList<String> results = new ArrayList<String>(); for (int i = 0; i < resources.length; i++) { try { ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resources[i]); results.add(oname.toString()); } catch (MalformedObjectNameException e) { IllegalArgumentException iae = new IllegalArgumentException( "Cannot create object name for resource " + resources[i]); iae.initCause(e); throw iae; } } return results.toArray(new String[results.size()]); }
/** * Create, register, and return an MBean for this * <code>ContextResource</code> object. * * @param resource * The ContextResource to be managed * * @exception Exception * if an MBean cannot be created or registered */ public static DynamicMBean createMBean(ContextResource resource) throws Exception { String mname = createManagedName(resource); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { Exception e = new Exception("ManagedBean is not found with " + mname); throw new MBeanException(e); } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); DynamicMBean mbean = managed.createMBean(resource); ObjectName oname = createObjectName(domain, resource); if (mserver.isRegistered(oname)) { mserver.unregisterMBean(oname); } mserver.registerMBean(mbean, oname); return (mbean); }
/** * Deregister the MBean for this <code>ContextResource</code> object. * * @param resource * The ContextResource to be managed * * @exception Exception * if an MBean cannot be deregistered */ public static void destroyMBean(ContextResource resource) throws Exception { // If this is a user database resource need to destroy groups, roles, // users and UserDatabase mbean if ("org.apache.catalina.UserDatabase".equals(resource.getType())) { destroyMBeanUserDatabase(resource.getName()); } String mname = createManagedName(resource); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { return; } String domain = managed.getDomain(); if (domain == null) domain = mserver.getDefaultDomain(); ObjectName oname = createObjectName(domain, resource); if (mserver.isRegistered(oname)) mserver.unregisterMBean(oname); }
@Override public void addContextResource(Context context, List<ApplicationResource> resourceList, boolean contextBound) { NamingResources namingResources = context.getNamingResources(); for (ContextResource contextResource : namingResources.findResources()) { ApplicationResource resource = new ApplicationResource(); logger.info("reading resource: {}", contextResource.getName()); resource.setApplicationName(context.getName()); resource.setName(contextResource.getName()); resource.setType(contextResource.getType()); resource.setScope(contextResource.getScope()); resource.setAuth(contextResource.getAuth()); resource.setDescription(contextResource.getDescription()); resourceList.add(resource); } }
@Test public void testListBindings() throws Exception { Tomcat tomcat = getTomcatInstance(); tomcat.enableNaming(); // Must have a real docBase - just use temp StandardContext ctx = (StandardContext) tomcat.addContext("", System.getProperty("java.io.tmpdir")); // Create the resource ContextResource cr = new ContextResource(); cr.setName("list/foo"); cr.setType("org.apache.naming.resources.TesterObject"); cr.setProperty("factory", "org.apache.naming.resources.TesterFactory"); ctx.getNamingResources().addResource(cr); // Map the test Servlet Bug23950Servlet bug23950Servlet = new Bug23950Servlet(); Tomcat.addServlet(ctx, "bug23950Servlet", bug23950Servlet); ctx.addServletMapping("/", "bug23950Servlet"); tomcat.start(); ByteChunk bc = getUrl("http://localhost:" + getPort() + "/"); assertEquals("org.apache.naming.resources.TesterObject", bc.toString()); }
public void addContextResource(Context context, List resourceList, boolean contextBound) { NamingResources namingResources = context.getNamingResources(); ContextResource[] resources = namingResources.findResources(); for (int i = 0; i < resources.length; i++) { ContextResource contextResource = resources[i]; ApplicationResource resource = new ApplicationResource(); logger.info("reading resource: " + contextResource.getName()); resource.setApplicationName(context.getName()); resource.setName(contextResource.getName()); resource.setType(contextResource.getType()); resource.setScope(contextResource.getScope()); resource.setAuth(contextResource.getAuth()); resource.setDescription(contextResource.getDescription()); //lookupResource(resource, contextBound, false); resourceList.add(resource); } }