Example usage for javax.management AttributeNotFoundException AttributeNotFoundException

List of usage examples for javax.management AttributeNotFoundException AttributeNotFoundException

Introduction

In this page you can find the example usage for javax.management AttributeNotFoundException AttributeNotFoundException.

Prototype

public AttributeNotFoundException(String message) 

Source Link

Document

Constructor that allows a specific error message to be specified.

Usage

From source file:org.jolokia.converter.json.ListExtractor.java

private Object extractWithPath(ObjectToJsonConverter pConverter, List pList, Stack<String> pStack,
        boolean jsonify, String pPathPart) throws AttributeNotFoundException {
    try {/* w  w  w .  j  av a2s  .co m*/
        int idx = Integer.parseInt(pPathPart);
        return pConverter.extractObject(pList.get(idx), pStack, jsonify);
    } catch (NumberFormatException exp) {
        ValueFaultHandler faultHandler = pConverter.getValueFaultHandler();
        return faultHandler.handleException(
                new AttributeNotFoundException("Index '" + pPathPart + "' is not numeric for accessing list"));
    } catch (IndexOutOfBoundsException exp) {
        ValueFaultHandler faultHandler = pConverter.getValueFaultHandler();
        return faultHandler.handleException(new AttributeNotFoundException(
                "Index '" + pPathPart + "' is out-of-bound for a list of size " + pList.size()));
    }
}

From source file:com.joyent.manta.http.PoolStatsMBean.java

@Override
public void setAttribute(final Attribute attribute)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    throw new AttributeNotFoundException("Not supported");
}

From source file:org.eclipse.smila.management.jmx.AgentMBean.java

/**
 * {@inheritDoc}//from  w w w.  j  ava 2 s .  c  o  m
 * 
 * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute)
 */
public void setAttribute(final Attribute attribute)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    final ModelMBeanAttributeInfo info = _beanInfo.getAttribute(attribute.getName());
    if (info == null) {
        final String msg = "MBean " + _beanInfo.getClassName()
                + " doesnt contain attribute Information for method " + attribute.getName()
                + ", please check if you have defined a gettter and setter for this Attriubute!";
        _log.error(msg);
        throw new AttributeNotFoundException(msg);
    }
    final Descriptor descriptor = info.getDescriptor();
    final String setterMethod = (String) (descriptor.getFieldValue("setMethod"));
    final String setterSignatureClass = (String) (descriptor.getFieldValue("setterSignatureClass"));
    invoke(setterMethod, new Object[] { attribute.getValue() }, new String[] { setterSignatureClass });
}

From source file:uk.ac.diamond.cas.shibboleth.authentication.handler.ShibbolethAuthenticationHandler.java

@Override
protected final Principal authenticateUsernamePasswordInternal(final String username, final String password)
        throws GeneralSecurityException, PreventedException {

    logger.debug("Attempting to authenticate {} at {}", username, IdP);

    try {/*w  w w . j a  v a 2 s  .  co  m*/
        // Initialise the library
        DefaultBootstrap.bootstrap();
        final BasicParserPool parserPool = new BasicParserPool();
        parserPool.setNamespaceAware(true);

        // Set proxy
        HttpHost proxy = null;
        logger.debug("Setting proxy");
        if ((this.proxyHost != null) && (!this.proxyHost.isEmpty())) {
            if (this.proxyPort == 0) {
                proxy = new HttpHost(this.proxyHost, 8080);
            } else {
                proxy = new HttpHost(this.proxyHost, this.proxyPort);
            }
        }
        logger.debug("Set proxy successfully");

        // Instantiate a copy of the client, try to authentication, catch any errors that occur
        ShibbolethECPAuthClient ecpClient = new ShibbolethECPAuthClient(proxy, this.IdP, this.SP,
                disableCertCheck);
        Response response = ecpClient.authenticate(username, password);
        logger.debug("Successfully authenticated {}", username);

        // if the attribute is empty, we simply authenticate and return the username as principal
        if ((this.attribute == null) || (this.attribute.isEmpty())) {
            return new SimplePrincipal(username);
        }

        // get the first assertion in the response. Any exceptions here are a problem
        List<Attribute> attributes = response.getAssertions().get(0)
                // get the first (and should be only) attribute statement
                .getAttributeStatements().get(0)
                // get all attributes
                .getAttributes();

        // if there are no attributes, we can't do a lookup.
        if (attributes.isEmpty()) {
            throw new AttributeNotFoundException("The Shibboleth Identity Provider at " + this.IdP
                    + " returned a SAML assertion with no attributes");
        }

        // trawl the attributes to check if we can find ours
        String lookupAttributeValue = null;
        boolean idFound = false;
        for (Attribute attribute : attributes) {
            if ((attribute.getName().equals(this.attribute))
                    || (attribute.getFriendlyName().equals(this.attribute))) {
                idFound = true;
                XMLObject attributeValue = attribute.getAttributeValues().get(0);
                if (attributeValue instanceof XSString) {
                    lookupAttributeValue = ((XSString) attributeValue).getValue();
                } else if (attributeValue instanceof XSAny) {
                    lookupAttributeValue = ((XSAny) attributeValue).getTextContent();
                }
                logger.debug("Attribute: " + this.attribute + ", value: " + lookupAttributeValue);
                break;
            } // if getName()...
        } // for attribute...

        // Attribute was not found in the SAML statement
        if (!idFound) {
            throw new AttributeNotFoundException("The attribute " + this.attribute
                    + " was not returned by the Shibboleth Identity Provider.");
        }

        logger.info("Authentication was successful. Credential {} mapped to {}", username,
                lookupAttributeValue);
        return new SimplePrincipal(lookupAttributeValue);

    } catch (final AttributeNotFoundException e) {
        logger.debug("AttributeNotFoundException raised: {}", e.toString());
        throw new FailedLoginException(e.toString());
    } catch (final AuthenticationException e) {
        logger.debug("AuthenticationException raised: {}", e.toString());
        throw new FailedLoginException(e.toString());
    } catch (final IOException e) {
        logger.debug("IOException raised: {}", e.toString());
        throw new PreventedException(e);
    } catch (final Exception e) {
        logger.debug("Exception raised: {}", e.toString());
        throw new PreventedException(e);
    }
}

From source file:org.jolokia.converter.json.ArrayExtractor.java

private Object extractWithPath(ObjectToJsonConverter pConverter, Object pValue, Stack<String> pPath,
        boolean jsonify, String pPathPart) throws AttributeNotFoundException {
    try {/*from   w  w w .j a  va  2s  .  c o  m*/
        Object obj = Array.get(pValue, Integer.parseInt(pPathPart));
        return pConverter.extractObject(obj, pPath, jsonify);
    } catch (NumberFormatException exp) {
        ValueFaultHandler faultHandler = pConverter.getValueFaultHandler();
        return faultHandler.handleException(
                new AttributeNotFoundException("Index '" + pPathPart + "' is not numeric for accessing array"));
    } catch (ArrayIndexOutOfBoundsException exp) {
        ValueFaultHandler faultHandler = pConverter.getValueFaultHandler();
        return faultHandler.handleException(new AttributeNotFoundException(
                "Index '" + pPathPart + "' is out-of-bound for array of size " + Array.getLength(pValue)));
    }
}

From source file:catalina.mbeans.ContextResourceMBean.java

/**
 * Obtain and return the value of a specific attribute of this MBean.
 *
 * @param name Name of the requested attribute
 *
 * @exception AttributeNotFoundException if this attribute is not
 *  supported by this MBean//from   w  w w  . ja  v  a  2 s.c o  m
 * @exception MBeanException if the initializer of an object
 *  throws an exception
 * @exception ReflectionException if a Java reflection exception
 *  occurs when invoking the getter
 */
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException {

    // Validate the input parameters
    if (name == null)
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"),
                "Attribute name is null");

    ContextResource cr = null;
    try {
        cr = (ContextResource) getManagedResource();
    } catch (InstanceNotFoundException e) {
        throw new MBeanException(e);
    } catch (InvalidTargetObjectTypeException e) {
        throw new MBeanException(e);
    }

    String value = null;
    if ("auth".equals(name)) {
        return (cr.getAuth());
    } else if ("description".equals(name)) {
        return (cr.getDescription());
    } else if ("name".equals(name)) {
        return (cr.getName());
    } else if ("scope".equals(name)) {
        return (cr.getScope());
    } else if ("type".equals(name)) {
        return (cr.getType());
    } else {
        NamingResources nr = cr.getNamingResources();
        if (nr == null) {
            throw new AttributeNotFoundException("Cannot find naming resource " + cr.getName());
        }
        ResourceParams rp = nr.findResourceParams(cr.getName());
        if (rp == null) {
            throw new AttributeNotFoundException("Cannot find resource param " + cr.getName());
        }
        value = (String) rp.getParameters().get(name);
        if (value == null) {
            throw new AttributeNotFoundException("Cannot find attribute " + name + rp);
        }
    }

    return value;

}

From source file:org.eclipse.gyrex.monitoring.internal.mbeans.MetricSetMBean.java

@Override
public Object getAttribute(final String attributeName)
        throws AttributeNotFoundException, MBeanException, ReflectionException {
    if (ID.equals(attributeName)) {
        return metricSet.getId();
    } else if (DESCRIPTION.equals(attributeName)) {
        return metricSet.getDescription();
    } else if (PROPERTIES.equals(attributeName)) {
        return properties;
    } else if (metricTypesByAttributeName.containsKey(attributeName)) {
        final CompositeType type = metricTypesByAttributeName.get(attributeName);
        final BaseMetric metric = metricByAttributeName.get(attributeName);
        if ((type != null) && (metric != null)) {
            final Map<String, ?> rawValues = metric.getAttributeValues();
            final String[] metricAttributeNames = type.keySet().toArray(new String[0]);
            final Object[] metricValues = new Object[metricAttributeNames.length];
            for (int i = 0; i < metricValues.length; i++) {
                Object rawValue = rawValues.get(metricAttributeNames[i]);
                // convert if necessary
                if (null != rawValue) {
                    final OpenType detectedTyp = detectType(rawValue.getClass());
                    if ((SimpleType.STRING == detectedTyp) && !(rawValue instanceof String)) {
                        rawValue = String.valueOf(rawValue);
                    }//from   w w w  .  ja  va2s .  co m
                }
                metricValues[i] = rawValue;
            }
            try {
                return new CompositeDataSupport(type, metricAttributeNames, metricValues);
            } catch (final OpenDataException e) {
                throw new MBeanException(e);
            }
        }
    }

    throw new AttributeNotFoundException(String.format("attribute %s not found", attributeName));
}

From source file:com.ecyrd.management.SimpleMBean.java

/**
 *  Gets an attribute using reflection from the MBean.
 *  /*w  w  w .j ava2s.  co  m*/
 *  @param name Name of the attribute to find.
 *  @return The value returned by the corresponding getXXX() call
 *  @throws AttributeNotFoundException If there is not such attribute
 *  @throws MBeanException 
 *  @throws ReflectionException
 */
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException {
    Method m;
    Object res = null;
    try {
        String mname = "get" + StringUtils.capitalize(name);
        m = findGetterSetter(getClass(), mname, null);

        if (m == null)
            throw new AttributeNotFoundException(name);
        res = m.invoke(this, (Object[]) null);
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return res;
}

From source file:org.jolokia.converter.json.ObjectToJsonConverter.java

/**
 * Related to {@link #extractObjectWithContext} except that
 * it does not setup a context. This method is called back from the
 * various extractors to recursively continue the extraction, hence it is public.
 *
 * This method must not be used as entry point for serialization.
 * Use {@link #convertToJson(Object, List, JsonConvertOptions)} or
 * {@link #setInnerValue(Object, Object, List)} instead.
 *
 * @param pValue value to extract from// ww w. j a  v  a  2s . c om
 * @param pPathParts stack for diving into the object
 * @param pJsonify whether a JSON representation {@link org.json.simple.JSONObject}
 * @return extracted object either in native format or as {@link org.json.simple.JSONObject}
 * @throws AttributeNotFoundException if an attribute is not found during traversal
 */
public Object extractObject(Object pValue, Stack<String> pPathParts, boolean pJsonify)
        throws AttributeNotFoundException {
    ObjectSerializationContext stackContext = stackContextLocal.get();
    String limitReached = checkForLimits(pValue, stackContext);
    Stack<String> pathStack = pPathParts != null ? pPathParts : new Stack<String>();
    if (limitReached != null) {
        return limitReached;
    }
    try {
        stackContext.push(pValue);

        if (pValue == null) {
            return pathStack.isEmpty() ? null
                    : stackContext.getValueFaultHandler().handleException(
                            new AttributeNotFoundException("Cannot apply a path to an null value"));
        }

        if (pValue.getClass().isArray()) {
            // Special handling for arrays
            return arrayExtractor.extractObject(this, pValue, pathStack, pJsonify);
        }
        return callHandler(pValue, pathStack, pJsonify);
    } finally {
        stackContext.pop();
    }
}

From source file:org.hyperic.hq.product.jmx.MxUtil.java

static Double getJSR77Statistic(MBeanServerConnection mServer, ObjectName objName, String attribute)
        throws MalformedURLException, MalformedObjectNameException, IOException, MBeanException,
        AttributeNotFoundException, InstanceNotFoundException, ReflectionException, PluginException {

    Stats stats;//from  w  w  w  . j  a v  a 2  s  . co  m
    Boolean provider = (Boolean) mServer.getAttribute(objName, "statisticsProvider");
    if ((provider == null) || !provider.booleanValue()) {
        String msg = objName + " does not provide statistics";
        throw new PluginException(msg);
    }

    stats = (Stats) mServer.getAttribute(objName, "stats");

    if (stats == null) {
        throw new PluginException(objName + " has no stats");
    }

    String statName = attribute.substring(STATS_PREFIX.length());
    Statistic stat = stats.getStatistic(statName);
    if (stat == null) {
        String msg = "Statistic '" + statName + "' not found [" + objName + "]";
        throw new AttributeNotFoundException(msg);
    }

    long value;
    if (stat instanceof CountStatistic) {
        value = ((CountStatistic) stat).getCount();
    } else if (stat instanceof RangeStatistic) {
        value = ((RangeStatistic) stat).getCurrent();
    } else if (stat instanceof TimeStatistic) {
        // get the average time
        long count = ((TimeStatistic) stat).getCount();
        if (count == 0)
            value = 0;
        else
            value = ((TimeStatistic) stat).getTotalTime() / count;
    } else {
        String msg = "Unsupported statistic type [" + statName.getClass().getName() + " for [" + objName + ":"
                + attribute + "]";
        throw new MetricInvalidException(msg);
    }

    //XXX: handle bug with geronimo uptime metric
    if (statName.equals("UpTime")) {
        value = System.currentTimeMillis() - value;
    }

    return new Double(value);
}