Example usage for java.lang NoSuchMethodException getMessage

List of usage examples for java.lang NoSuchMethodException getMessage

Introduction

In this page you can find the example usage for java.lang NoSuchMethodException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings.java

void mergePreferThis(ServiceSettings other) {
    Arrays.stream(getClass().getDeclaredMethods()).forEach(m -> {
        m.setAccessible(true);//w ww. j  a  v  a2  s .  co m
        if (!m.getName().startsWith("get")) {
            return;
        }

        String setterName = "s" + m.getName().substring(1);
        Method s;
        try {
            s = getClass().getDeclaredMethod(setterName, m.getReturnType());
        } catch (NoSuchMethodException e) {
            return;
        }

        try {
            Object oThis = m.invoke(this);
            Object oOther = m.invoke(other);

            if (oThis == null) {
                s.invoke(this, oOther);
            }
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new RuntimeException("Unable to merge service settings: " + e.getMessage(), e);
        } finally {
            m.setAccessible(false);
        }
    });
}

From source file:com.adf.bean.AbsBean.java

/**
 * IMPORT// ww w .  j  av a2 s.c o  m
 * */
private void setArrayColumn(String col, JSONArray arr)
        throws NoSuchFieldException, IllegalAccessException, IllegalArgumentException {
    Field f;
    f = getClass().getDeclaredField(col);
    f.setAccessible(true);
    Class<?> arrCls = f.getType();
    Class<?> objCls = getArrayObjectClass(arrCls);
    if (objCls != null) {
        Object array = Array.newInstance(objCls, arr.length());
        for (int i = 0; i < arr.length(); i++) {
            Object oi = arr.opt(i);
            if (oi.getClass() == objCls) {
                Array.set(array, i, arr.opt(i));
            } else {
                Constructor<?> cons;
                try {
                    cons = objCls.getDeclaredConstructor(String.class);
                    cons.setAccessible(true);
                    Object obj = cons.newInstance(oi.toString());
                    Array.set(array, i, obj);
                } catch (NoSuchMethodException e) {
                    LogUtil.err("setArrayColumn NoSuchMethodException, col " + col + " :" + e.getMessage());
                } catch (InstantiationException e) {
                    LogUtil.err("setArrayColumn InstantiationException, col " + col + " :" + e.getMessage());
                } catch (InvocationTargetException e) {
                    LogUtil.err("setArrayColumn InvocationTargetException, col " + col + " :" + e.getMessage());
                }
            }
        }
        f.set(this, array);
    } else {
        throw new IllegalArgumentException("Can not get Array Column Object class");
    }
}

From source file:net.mojodna.sprout.SproutAutoLoaderPlugIn.java

@SuppressWarnings("unchecked")
private void loadAction(final Class bean) {
    final Annotation[] annotations = bean.getAnnotations();

    for (int i = 0; i < annotations.length; i++) {
        final Annotation a = annotations[i];
        final Class type = a.annotationType();

        if (type.equals(SproutAction.class)) {
            final SproutAction form = (SproutAction) a;
            final String path = form.path();
            final Class<ActionConfig> mappingClass = form.mappingClass();
            final String scope = form.scope();
            final String name = form.name();
            final boolean validate = form.validate();
            final String input = form.input();
            final SproutProperty[] properties = form.properties();
            final SproutForward[] forwards = form.forwards();
            ActionConfig actionConfig = null;

            try {
                Constructor<ActionConfig> constructor = mappingClass.getDeclaredConstructor(new Class[] {});

                actionConfig = constructor.newInstance(new Object[] {});
            } catch (NoSuchMethodException nsme) {
                log.error("Failed to create a new instance of " + mappingClass.toString() + ", "
                        + nsme.getMessage());
            } catch (InstantiationException ie) {
                log.error("Failed to create a new instance of " + mappingClass.toString() + ", "
                        + ie.getMessage());
            } catch (IllegalAccessException iae) {
                log.error("Failed to create a new instance of " + mappingClass.toString() + ", "
                        + iae.getMessage());
            } catch (InvocationTargetException ite) {
                log.error("Failed to create a new instance of " + mappingClass.toString() + ", "
                        + ite.getMessage());
            }//from w  w  w.j  a v a  2s  .c  om

            if (actionConfig != null) {
                actionConfig.setPath(path);
                actionConfig.setType(bean.getName());
                actionConfig.setScope(scope);
                actionConfig.setValidate(validate);

                if (name.length() > 0) {
                    actionConfig.setName(name);
                }
                if (input.length() > 0) {
                    actionConfig.setInput(input);
                }

                if (properties != null && properties.length > 0) {
                    Map actionConfigBeanMap = new BeanMap(actionConfig);

                    for (int j = 0; j < properties.length; j++) {
                        actionConfigBeanMap.put(properties[j].property(), properties[j].value());
                    }
                }

                if (forwards != null && forwards.length > 0) {
                    for (int j = 0; j < forwards.length; j++) {
                        String fcModule = forwards[j].module();

                        actionConfig.addForwardConfig(makeForward(forwards[j].name(), forwards[j].path(),
                                forwards[j].redirect(), fcModule.length() == 0 ? null : fcModule));
                    }
                }
            }

            if (log.isDebugEnabled()) {
                log.debug("Action " + path + " -> " + bean.getName());
            }

            getModuleConfig().addActionConfig(actionConfig);
        }
    }
}

From source file:com.qualogy.qafe.business.integration.java.JavaServiceProcessor.java

/**
 * The actual method calll is processed in this method
 * @param clazz//from   www. j a  v a2 s  . c om
 * @param parameterTypes
 * @param instance
 * @param parameters
 * @param context 
 * @throws thrown when anything goes wrong upon calling the method
 * @return the outcome
 */
private Object executeMethod(JavaClass resource, String actualMethodName, Class[] parameterClasses,
        Object[] parameters, ApplicationContext context) throws ExternalException {
    Object instance = resource.getInstance();
    Object result = null;
    try {
        result = resource.getMethod(actualMethodName, parameterClasses).invoke(instance, parameters);
        if (instance instanceof HasMessage) {
            HasMessage hasMessage = (HasMessage) instance;
            List<String> messages = hasMessage.getMessages();
            for (String message : messages) {
                context.getWarningMessages().add(message);
            }
        }
    } catch (NoSuchMethodException e) {
        String errorMessage = resolveErrorMessage(e);
        throw new ExternalException(errorMessage, errorMessage, e);
    } catch (InvocationTargetException e) {
        String errorMessage = resolveErrorMessage(e.getTargetException());
        throw new ExternalException(e.getMessage(), errorMessage, e.getTargetException());
    } catch (IllegalAccessException e) {
        String errorMessage = resolveErrorMessage(e);
        throw new ExternalException(e.getMessage(), errorMessage, e.getCause());
    } catch (Exception e) {
        String errorMessage = resolveErrorMessage(e);
        throw new ExternalException(e.getMessage(), errorMessage, e.getCause());
    }
    return result;
}

From source file:com.concursive.connect.indexer.LuceneIndexer.java

private boolean indexDeleteItem(IndexWriter writer, Object item, String deleteTerm) throws IOException {
    // Determine the object's indexer key term for deletion
    Indexer objectIndexer = (Indexer) getObjectIndexer(item.getClass().getName() + "Indexer");
    if (objectIndexer == null) {
        return false;
    }//from  ww w .j  a  v  a2  s  . co m
    // Delete the previous item from the index
    Object o = null;
    try {
        // now we are ready for the next to last step..to call upon the method in the
        // class instance we have.
        Method method = objectIndexer.getClass().getMethod(deleteTerm, Object.class);
        o = method.invoke(objectIndexer, item);
    } catch (NoSuchMethodException nm) {
        LOG.error("No Such Method Exception for method " + deleteTerm + ". MESAGE = " + nm.getMessage(), nm);
    } catch (IllegalAccessException ia) {
        LOG.error("Illegal Access Exception. MESSAGE = " + ia.getMessage(), ia);
    } catch (Exception e) {
        LOG.error("Exception. MESSAGE = " + e.getMessage(), e);
    }
    if (o != null) {
        LOG.debug("Deleting with deleteTerm: " + deleteTerm);
        writer.deleteDocuments((Term) o);
    }
    return true;
}

From source file:com.concursive.connect.indexer.LuceneIndexer.java

protected boolean indexAddItem(IndexWriter writer, Object item, boolean modified) throws Exception {
    if (writer == null) {
        throw new NullPointerException("Writer is null");
    }/*from   www  .j a va  2  s  . c  o  m*/
    if (item == null) {
        throw new NullPointerException("Item is null");
    }

    if (modified) {
        // Delete the previous item from the index
        indexDeleteItem(writer, item, "getSearchTerm");
    }
    try {
        Indexer objectIndexer = (Indexer) getObjectIndexer(item.getClass().getName() + "Indexer");
        if (objectIndexer == null) {
            return false;
        }
        // Add the item to the index
        Object o = null;
        try {
            // now we are ready for the next to last step..to call upon the method in the
            // class instance we have.
            Method method = objectIndexer.getClass().getMethod("add",
                    new Class[] { writer.getClass(), Object.class, boolean.class });
            o = method.invoke(objectIndexer, new Object[] { writer, item, new Boolean(modified) });
        } catch (NoSuchMethodException nm) {
            LOG.error("No Such Method Exception for method add. MESAGE = " + nm.getMessage(), nm);
        } catch (IllegalAccessException ia) {
            LOG.error("Illegal Access Exception. MESSAGE = " + ia.getMessage(), ia);
        } catch (Exception e) {
            LOG.error("Exception. MESSAGE = " + e.getMessage(), e);
        }
    } catch (Exception io) {
        io.printStackTrace(System.out);
        throw new IOException("Writer: " + io.getMessage());
    }
    return true;
}

From source file:org.wso2.carbon.micro.integrator.security.MicroIntegratorSecurityUtils.java

/**
 * This method initializes the user store manager class
 *
 * @param className   class name of the user store manager class
 * @param realmConfig realm configuration defined
 * @return initialized UserStoreManager class
 * @throws UserStoreException/*from w  w  w. j  ava 2  s  .c  om*/
 */
public static Object createObjectWithOptions(String className, RealmConfiguration realmConfig)
        throws UserStoreException {
    /*
    Since different User Store managers contain constructors requesting different sets of arguments, this method
    tries to invoke the constructor with different combinations of arguments
     */
    Class[] initClassOpt1 = new Class[] { RealmConfiguration.class, ClaimManager.class,
            ProfileConfigurationManager.class };
    Object[] initObjOpt1 = new Object[] { realmConfig, null, null };
    Class[] initClassOpt2 = new Class[] { RealmConfiguration.class, Integer.class };
    Object[] initObjOpt2 = new Object[] { realmConfig, -1234 };
    Class[] initClassOpt3 = new Class[] { RealmConfiguration.class };
    Object[] initObjOpt3 = new Object[] { realmConfig };
    Class[] initClassOpt4 = new Class[] {};
    Object[] initObjOpt4 = new Object[] {};
    try {
        Class clazz = Class.forName(className);
        Object newObject = null;
        if (log.isDebugEnabled()) {
            log.debug("Start initializing the UserStoreManager class with first option");
        }

        Constructor constructor;
        try {
            constructor = clazz.getConstructor(initClassOpt1);
            newObject = constructor.newInstance(initObjOpt1);
            return newObject;
        } catch (NoSuchMethodException e) {
            if (log.isDebugEnabled()) {
                log.debug("Cannont initialize " + className + " trying second option");
            }
        }

        try {
            constructor = clazz.getConstructor(initClassOpt2);
            newObject = constructor.newInstance(initObjOpt2);
            return newObject;
        } catch (NoSuchMethodException e) {
            if (log.isDebugEnabled()) {
                log.debug("Cannont initialize " + className + " using the option 2");
            }
        }

        try {
            constructor = clazz.getConstructor(initClassOpt3);
            newObject = constructor.newInstance(initObjOpt3);
            return newObject;
        } catch (NoSuchMethodException e) {
            if (log.isDebugEnabled()) {
                log.debug("Cannont initialize " + className + " using the option 3");
            }
        }

        try {
            constructor = clazz.getConstructor(initClassOpt4);
            newObject = constructor.newInstance(initObjOpt4);
            return newObject;
        } catch (NoSuchMethodException e) {
            if (log.isDebugEnabled()) {
                log.debug("Cannont initialize " + className + " using the option 4");
            }
            throw new UserStoreException(e.getMessage(), e);
        }
    } catch (Throwable e) {
        if (log.isDebugEnabled()) {
            log.debug("Cannot create " + className, e);
        }
        throw new UserStoreException(e.getMessage() + "Type " + e.getClass(), e);
    }
}

From source file:org.jwebsocket.plugins.rpc.RPCPlugIn.java

/**
 * remote procedure call (RPC)//from   ww w.  j  a  va2  s . c  o  m
 * @param aConnector 
 * @param aToken
 */
public void rpc(WebSocketConnector aConnector, Token aToken) {
    // check if user is allowed to run 'rpc' command
    if (!SecurityFactory.checkRight(getUsername(aConnector), NS_RPC_DEFAULT + ".rpc")) {
        sendToken(aConnector, aConnector, createAccessDenied(aToken));
        return;
    }

    Token lResponseToken = createResponse(aToken);

    String lClassName = aToken.getString("classname");
    String lMethod = aToken.getString("method");
    Object lArgs = aToken.get("args");
    // TODO: Tokens should always be a map of maps
    if (lArgs instanceof JSONObject) {
        lArgs = new Token((JSONObject) lArgs);
    }

    String lMsg = null;

    if (mLog.isDebugEnabled()) {
        mLog.debug("Processing RPC to class '" + lClassName + "', method '" + lMethod + "', args: '" + lArgs
                + "'...");
    }

    String lKey = lClassName + "." + lMethod;
    if (mGrantedProcs.containsKey(lKey)) {
        // class is ignored until security restrictions are finished.
        try {
            // TODO: use RpcCallable here!
            Object lInstance = mClasses.get(lClassName);
            if (lInstance != null) {
                Object lObj = call(lInstance, lMethod, lArgs);
                lResponseToken.put("result", lObj);
            } else {
                lMsg = "Class '" + lClassName + "' not found or not properly loaded.";
            }
        } catch (NoSuchMethodException ex) {
            lMsg = "NoSuchMethodException calling '" + lMethod + "' for class " + lClassName + ": "
                    + ex.getMessage();
        } catch (IllegalAccessException ex) {
            lMsg = "IllegalAccessException calling '" + lMethod + "' for class " + lClassName + ": "
                    + ex.getMessage();
        } catch (InvocationTargetException ex) {
            lMsg = "InvocationTargetException calling '" + lMethod + "' for class " + lClassName + ": "
                    + ex.getMessage();
        }
    } else {
        lMsg = "Call to " + lKey + " is not granted!";
    }
    if (lMsg != null) {
        lResponseToken.put("code", -1);
        lResponseToken.put("msg", lMsg);
    }

    /* just for testing purposes of multi-threaded rpc's
    try {
    Thread.sleep(3000);
    } catch (InterruptedException ex) {
    }
     */

    sendToken(aConnector, aConnector, lResponseToken);
}

From source file:org.jahia.services.content.JCRNodePropertiesELResolver.java

public Object getValue(ELContext elContext, Object base, Object property) {
    if (elContext == null) {
        throw new NullPointerException();
    }/*from ww w  .j  a v a2 s  .c om*/
    if (base != null && base instanceof JCRNodeWrapper) {
        JCRNodeWrapper nodeWrapper = (JCRNodeWrapper) base;
        try {
            try {
                nodeWrapper.getClass().getMethod("get" + StringUtils.capitalize(property.toString()));
            } catch (NoSuchMethodException e) {
                final JCRPropertyWrapper jcrPropertyWrapper = nodeWrapper
                        .getProperty(property.toString().replace("_", ":"));
                if (jcrPropertyWrapper != null) {
                    elContext.setPropertyResolved(true);
                    return jcrPropertyWrapper;
                }
            }
        } catch (RepositoryException e) {
            logger.error(e.getMessage(), e);
        }
    }
    return null;
}

From source file:org.apache.hadoop.hive.serde2.protobuf.ProtobufSerDe.java

@Override
public void initialize(Configuration conf, Properties tbl) throws SerDeException {
    String columnNameProperty = tbl.getProperty(Constants.LIST_COLUMNS);
    String columnTypeProperty = tbl.getProperty(Constants.LIST_COLUMN_TYPES);
    String msgName = tbl.getProperty(Constants.PB_MSG_NAME);
    String outerName = tbl.getProperty(Constants.PB_OUTER_CLASS_NAME);

    List<String> columnNames = Arrays.asList(columnNameProperty.split(","));
    List<TypeInfo> columnTypes = TypeInfoUtils.getTypeInfosFromTypeString(columnTypeProperty);
    assert columnNames.size() == columnTypes.size();

    Class<?> tableMsgClass = ProtobufUtils.loadTableMsgClass(outerName, msgName);
    try {/* w  w w .ja v a  2 s  . c  o m*/
        parseFromMethod = tableMsgClass.getMethod("parseFrom", CodedInputStream.class);
    } catch (java.lang.NoSuchMethodException e) {
        throw new SerDeException(e.getMessage());
    }

    Descriptor tableMsgDescriptor = ProtobufUtils.getMsgDescriptor(tableMsgClass);
    List<FieldDescriptor> fieldDescriptors = tableMsgDescriptor.getFields();

    ArrayList<ObjectInspector> columnObjectInspectors = new ArrayList<ObjectInspector>(columnTypes.size());
    for (int i = 0; i < columnTypes.size(); ++i) {
        TypeInfo ti = columnTypes.get(i);
        ObjectInspector oi = ProtobufObjectInspectorFactory
                .getFieldObjectInspectorFromTypeInfo(columnTypes.get(i), fieldDescriptors.get(i));
        columnObjectInspectors.add(oi);
    }
    rowObjectInspector = ProtobufObjectInspectorFactory.getProtobufStructObjectInspector(columnNames,
            columnObjectInspectors, tableMsgDescriptor);
}