Search in sources :

Example 6 with NoSuchPropertyException

use of jp.ossc.nimbus.beans.NoSuchPropertyException in project nimbus by nimbus-org.

the class BeanFlowRestServerService method processReadParameter.

protected boolean processReadParameter(RestRequest request, RestResponse response, List paths, ResourceMetaData resource) throws Exception {
    if (journal != null) {
        journal.addInfo(JOURNAL_KEY_REQUEST_PARAMETERS, request.getRequest().getParameterMap());
    }
    if (request.getRequestObject() == null) {
        request.setRequestObject(request.getRequest().getParameterMap());
    } else {
        final Object requestObj = request.getRequestObject();
        Iterator entries = request.getRequest().getParameterMap().entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry entry = (Map.Entry) entries.next();
            Property prop = null;
            try {
                prop = propertyAccess.getProperty((String) entry.getKey());
            } catch (IllegalArgumentException e) {
                getLogger().write("BFRS_00027", new Object[] { resource.resourcePath.path, entry.getKey() }, e);
                if (journal != null) {
                    journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                }
                response.setResult(HttpServletResponse.SC_BAD_REQUEST);
                return false;
            }
            if (!prop.isReadable(requestObj)) {
                continue;
            }
            Class propType = null;
            try {
                propType = prop.getPropertyType(requestObj);
            } catch (NoSuchPropertyException e) {
                getLogger().write("BFRS_00012", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                if (journal != null) {
                    journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                }
                response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                return false;
            } catch (InvocationTargetException e) {
                getLogger().write("BFRS_00012", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                if (journal != null) {
                    journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                }
                response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                return false;
            }
            if (!prop.isWritable(requestObj, propType)) {
                continue;
            }
            if (propType.isAssignableFrom(String.class)) {
                try {
                    prop.setProperty(requestObj, propType, ((String[]) entry.getValue())[0]);
                } catch (NoSuchPropertyException e) {
                    getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                    if (journal != null) {
                        journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                    }
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                } catch (InvocationTargetException e) {
                    getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                    if (journal != null) {
                        journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                    }
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                }
            } else if (propType.isAssignableFrom(String[].class)) {
                try {
                    prop.setProperty(requestObj, propType, entry.getValue());
                } catch (NoSuchPropertyException e) {
                    getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                    if (journal != null) {
                        journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                    }
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                } catch (InvocationTargetException e) {
                    getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                    if (journal != null) {
                        journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                    }
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                }
            } else if (propType.isAssignableFrom(List.class) || propType.isAssignableFrom(Set.class)) {
                Collection collection = null;
                try {
                    collection = (Collection) prop.getProperty(requestObj);
                } catch (NoSuchPropertyException e) {
                    getLogger().write("BFRS_00014", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                    if (journal != null) {
                        journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                    }
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                } catch (InvocationTargetException e) {
                    getLogger().write("BFRS_00014", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                    if (journal != null) {
                        journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                    }
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                }
                if (collection == null) {
                    if (propType.isInterface()) {
                        collection = propType.isAssignableFrom(List.class) ? (Collection) new ArrayList() : new HashSet();
                    } else {
                        try {
                            collection = (Collection) propType.newInstance();
                        } catch (InstantiationException e) {
                            getLogger().write("BFRS_00015", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName(), propType }, e);
                            if (journal != null) {
                                journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                            }
                            response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                            return false;
                        } catch (IllegalAccessException e) {
                            getLogger().write("BFRS_00015", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName(), propType }, e);
                            if (journal != null) {
                                journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                            }
                            response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                            return false;
                        }
                    }
                }
                Type propGenericType = null;
                try {
                    propGenericType = prop.getPropertyGenericType(requestObj);
                } catch (NoSuchPropertyException e) {
                    getLogger().write("BFRS_00012", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                    if (journal != null) {
                        journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                    }
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                } catch (InvocationTargetException e) {
                    getLogger().write("BFRS_00012", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                    if (journal != null) {
                        journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                    }
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                }
                if (propGenericType instanceof ParameterizedType) {
                    Type[] elementTypes = ((ParameterizedType) propGenericType).getActualTypeArguments();
                    if (elementTypes.length == 0 || !(elementTypes[0] instanceof Class)) {
                        getLogger().write("BFRS_00016", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName(), propGenericType });
                        response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                        return false;
                    }
                    Class elementType = (Class) elementTypes[0];
                    try {
                        PropertyEditor editor = NimbusPropertyEditorManager.findEditor(elementType);
                        if (editor == null) {
                            getLogger().write("BFRS_00017", new Object[] { resource.resourcePath.path, entry.getKey(), elementType.getName() });
                            response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                            return false;
                        }
                        String[] params = (String[]) entry.getValue();
                        for (int i = 0; i < params.length; i++) {
                            editor.setAsText(params[i]);
                            collection.add(editor.getValue());
                        }
                        prop.setProperty(requestObj, propType, collection);
                    } catch (NoSuchPropertyException e) {
                        getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                        if (journal != null) {
                            journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                        }
                        response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                        return false;
                    } catch (InvocationTargetException e) {
                        getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                        if (journal != null) {
                            journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                        }
                        response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                        return false;
                    }
                } else {
                    try {
                        String[] params = (String[]) entry.getValue();
                        for (int i = 0; i < params.length; i++) {
                            collection.add(params[i]);
                        }
                        prop.setProperty(requestObj, propType, collection);
                    } catch (NoSuchPropertyException e) {
                        getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                        if (journal != null) {
                            journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                        }
                        response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                        return false;
                    } catch (InvocationTargetException e) {
                        getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                        if (journal != null) {
                            journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                        }
                        response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                        return false;
                    }
                }
            } else if (propType.isArray()) {
                Class componentType = propType.getComponentType();
                PropertyEditor editor = NimbusPropertyEditorManager.findEditor(componentType);
                if (editor == null) {
                    getLogger().write("BFRS_00017", new Object[] { resource.resourcePath.path, entry.getKey(), componentType.getName() });
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                }
                String[] params = (String[]) entry.getValue();
                Object array = Array.newInstance(componentType, params.length);
                try {
                    for (int i = 0; i < params.length; i++) {
                        editor.setAsText(((String[]) entry.getValue())[0]);
                        Array.set(array, i, editor.getValue());
                    }
                    prop.setProperty(requestObj, propType, array);
                } catch (IllegalArgumentException e) {
                    getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                    if (journal != null) {
                        journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                    }
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                } catch (NoSuchPropertyException e) {
                    getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                    if (journal != null) {
                        journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                    }
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                } catch (InvocationTargetException e) {
                    getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                    if (journal != null) {
                        journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                    }
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                }
            } else {
                PropertyEditor editor = NimbusPropertyEditorManager.findEditor(propType);
                if (editor == null) {
                    getLogger().write("BFRS_00017", new Object[] { resource.resourcePath.path, entry.getKey(), propType.getName() });
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                }
                editor.setAsText(((String[]) entry.getValue())[0]);
                try {
                    prop.setProperty(requestObj, propType, editor.getValue());
                } catch (NoSuchPropertyException e) {
                    getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                    if (journal != null) {
                        journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                    }
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                } catch (InvocationTargetException e) {
                    getLogger().write("BFRS_00013", new Object[] { resource.resourcePath.path, entry.getKey(), requestObj.getClass().getName() }, e);
                    if (journal != null) {
                        journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                    }
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ParameterizedType(java.lang.reflect.ParameterizedType) NoSuchPropertyException(jp.ossc.nimbus.beans.NoSuchPropertyException) PropertyEditor(java.beans.PropertyEditor) Property(jp.ossc.nimbus.beans.Property)

Example 7 with NoSuchPropertyException

use of jp.ossc.nimbus.beans.NoSuchPropertyException in project nimbus by nimbus-org.

the class BeanFlowRestServerService method processCreateRequestObject.

protected boolean processCreateRequestObject(RestRequest request, RestResponse response, List paths, ResourceMetaData resource, RequestMetaData requestData) throws Exception {
    if (requestData == null) {
        return true;
    }
    Map pathParameters = request.getPathParameterMap();
    Object requestObj = null;
    Class requestObjClass = null;
    try {
        requestObjClass = Utility.convertStringToClass(requestData.code, true);
    } catch (ClassNotFoundException e) {
        getLogger().write("BFRS_00004", new Object[] { resource.resourcePath.path, requestData.code }, e);
        if (journal != null) {
            journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
        }
        response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return false;
    }
    if (String.class.equals(requestObjClass)) {
        if (pathParameters != null && pathParameters.size() != 0) {
            requestObj = pathParameters.values().iterator().next();
        }
    } else if (String[].class.equals(requestObjClass)) {
        if (pathParameters != null && pathParameters.size() != 0) {
            requestObj = pathParameters.values().toArray();
        }
    } else if (Number.class.isAssignableFrom(requestObjClass)) {
        if (pathParameters != null && pathParameters.size() != 0) {
            String valStr = (String) pathParameters.values().iterator().next();
            try {
                if (Byte.class.isAssignableFrom(requestObjClass)) {
                    requestObj = Byte.valueOf(valStr);
                } else if (Short.class.isAssignableFrom(requestObjClass)) {
                    requestObj = Short.valueOf(valStr);
                } else if (Integer.class.isAssignableFrom(requestObjClass)) {
                    requestObj = Integer.valueOf(valStr);
                } else if (Long.class.isAssignableFrom(requestObjClass)) {
                    requestObj = Long.valueOf(valStr);
                } else if (Float.class.isAssignableFrom(requestObjClass)) {
                    requestObj = Float.valueOf(valStr);
                } else if (Double.class.isAssignableFrom(requestObjClass)) {
                    requestObj = Double.valueOf(valStr);
                } else if (BigInteger.class.isAssignableFrom(requestObjClass)) {
                    requestObj = new BigInteger(valStr);
                } else if (BigDecimal.class.isAssignableFrom(requestObjClass)) {
                    requestObj = new BigDecimal(valStr);
                } else {
                    getLogger().write("BFRS_00005", new Object[] { resource.resourcePath.path, requestObjClass.getName() });
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                }
            } catch (NumberFormatException e) {
                getLogger().write("BFRS_00026", new Object[] { resource.resourcePath.path, pathParameters.keySet().iterator().next(), valStr }, e);
                if (journal != null) {
                    journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                }
                response.setResult(HttpServletResponse.SC_BAD_REQUEST, "Illegal number format. val=" + valStr);
                return false;
            }
        }
    } else {
        try {
            requestObj = requestObjClass.newInstance();
        } catch (InstantiationException e) {
            getLogger().write("BFRS_00006", new Object[] { resource.resourcePath.path, requestObjClass.getName() }, e);
            if (journal != null) {
                journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
            }
            response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return false;
        } catch (IllegalAccessException e) {
            getLogger().write("BFRS_00006", new Object[] { resource.resourcePath.path, requestObjClass.getName() }, e);
            if (journal != null) {
                journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
            }
            response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return false;
        }
        if (pathParameters != null && pathParameters.size() != 0) {
            Iterator entries = pathParameters.entrySet().iterator();
            while (entries.hasNext()) {
                Map.Entry entry = (Map.Entry) entries.next();
                Property prop = null;
                try {
                    prop = propertyAccess.getProperty((String) entry.getKey());
                } catch (IllegalArgumentException e) {
                    getLogger().write("BFRS_00007", new Object[] { resource.resourcePath.path, entry.getKey() }, e);
                    if (journal != null) {
                        journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                    }
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                }
                if (!prop.isReadable(requestObj)) {
                    continue;
                }
                Class propType = null;
                try {
                    propType = prop.getPropertyType(requestObj);
                } catch (NoSuchPropertyException e) {
                    getLogger().write("BFRS_00008", new Object[] { resource.resourcePath.path, entry.getKey(), requestObjClass.getName() }, e);
                    if (journal != null) {
                        journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                    }
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                } catch (InvocationTargetException e) {
                    getLogger().write("BFRS_00008", new Object[] { resource.resourcePath.path, entry.getKey(), requestObjClass.getName() }, e);
                    if (journal != null) {
                        journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                    }
                    response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return false;
                }
                if (!prop.isWritable(requestObj, propType)) {
                    continue;
                }
                if (propType.isAssignableFrom(String.class)) {
                    try {
                        prop.setProperty(requestObj, propType, entry.getValue());
                    } catch (NoSuchPropertyException e) {
                        getLogger().write("BFRS_00009", new Object[] { resource.resourcePath.path, entry.getKey(), requestObjClass.getName() }, e);
                        if (journal != null) {
                            journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                        }
                        response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                        return false;
                    } catch (InvocationTargetException e) {
                        getLogger().write("BFRS_00009", new Object[] { resource.resourcePath.path, entry.getKey(), requestObjClass.getName() }, e);
                        if (journal != null) {
                            journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                        }
                        response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                        return false;
                    }
                } else {
                    PropertyEditor editor = NimbusPropertyEditorManager.findEditor(propType);
                    if (editor == null) {
                        getLogger().write("BFRS_00010", new Object[] { resource.resourcePath.path, entry.getKey(), propType.getName() });
                        response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                        return false;
                    }
                    editor.setAsText((String) entry.getValue());
                    try {
                        prop.setProperty(requestObj, propType, editor.getValue());
                    } catch (NoSuchPropertyException e) {
                        getLogger().write("BFRS_00009", new Object[] { resource.resourcePath.path, entry.getKey(), requestObjClass.getName() }, e);
                        if (journal != null) {
                            journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                        }
                        response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                        return false;
                    } catch (InvocationTargetException e) {
                        getLogger().write("BFRS_00009", new Object[] { resource.resourcePath.path, entry.getKey(), requestObjClass.getName() }, e);
                        if (journal != null) {
                            journal.addInfo(JOURNAL_KEY_EXCEPTION, e);
                        }
                        response.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                        return false;
                    }
                }
            }
        }
    }
    request.setRequestObject(requestObj);
    return true;
}
Also used : BigDecimal(java.math.BigDecimal) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchPropertyException(jp.ossc.nimbus.beans.NoSuchPropertyException) BigInteger(java.math.BigInteger) PropertyEditor(java.beans.PropertyEditor) Property(jp.ossc.nimbus.beans.Property)

Example 8 with NoSuchPropertyException

use of jp.ossc.nimbus.beans.NoSuchPropertyException in project nimbus by nimbus-org.

the class BlockadeInterceptorService method invokeFilter.

/**
 * コードマスタの閉塞マスタ及び特権ユーザマスタをチェックして、閉塞状態の場合は例外をthrowする。
 * <p>
 * サービスが開始されていない場合は、何もせずに次のインターセプタを呼び出す。<br>
 *
 * @param context 呼び出しのコンテキスト情報
 * @param chain 次のインターセプタを呼び出すためのチェーン
 * @return 呼び出し結果の戻り値
 * @exception Throwable 呼び出し先で例外が発生した場合、またはこのインターセプタで任意の例外が発生した場合。但し、
 *                本来呼び出される処理がthrowしないRuntimeException以外の例外をthrowしても
 *                、呼び出し元には伝播されない。
 */
public Object invokeFilter(ServletFilterInvocationContext context, InterceptorChain chain) throws Throwable {
    if (getState() != STARTED) {
        return chain.invokeNext(context);
    }
    final HttpServletRequest request = (HttpServletRequest) context.getServletRequest();
    String reqPath = request.getServletPath();
    if (request.getPathInfo() != null) {
        reqPath = reqPath + request.getPathInfo();
    }
    Map codeMasters = null;
    if (codeMasterFinder != null) {
        codeMasters = codeMasterFinder.getCodeMasters();
    } else {
        codeMasters = (Map) threadContext.get(ThreadContextKey.CODEMASTER);
    }
    if (codeMasters == null) {
        throw new BlockadeProcessException("CodeMaster is null.");
    }
    Object blockadeCodeMaster = codeMasters.get(blockadeCodeMasterKey);
    if (blockadeCodeMaster == null) {
        throw new BlockadeProcessException("BlockadeCodeMaster is null. key=" + blockadeCodeMasterKey);
    }
    Object specialUserCodeMaster = null;
    if (specialUserCodeMasterKey != null) {
        specialUserCodeMaster = codeMasters.get(specialUserCodeMasterKey);
    }
    boolean isSpecialUser = false;
    String userKey = null;
    if (specialUserCodeMaster != null) {
        Object requestObject = request.getAttribute(requestObjectAttributeName);
        if (requestObject == null) {
            throw new BlockadeProcessException("RequestObject is null.");
        }
        if (specialUserCodeMaster instanceof RecordList) {
            RecordList list = (RecordList) specialUserCodeMaster;
            Record primaryKey = list.createRecord();
            applySpecialUserMapping(requestObject, primaryKey);
            userKey = primaryKey.toString();
            isSpecialUser = list.searchByPrimaryKey(primaryKey) != null;
        } else if (specialUserCodeMaster instanceof RecordSet) {
            RecordSet recset = (RecordSet) specialUserCodeMaster;
            RowData primaryKey = recset.createNewRecord();
            applySpecialUserMapping(requestObject, primaryKey);
            userKey = primaryKey.getKey();
            isSpecialUser = recset.get(primaryKey) != null;
        } else {
            throw new BlockadeProcessException("Unsupported type of SpecialUserCodeMaster. type=" + specialUserCodeMaster.getClass());
        }
    }
    if (pathPatternMap == null) {
        initPathPatternMap(blockadeCodeMaster);
    }
    Map blockadeFilterMap = null;
    if (blockadeMapping != null) {
        Object requestObject = request.getAttribute(requestObjectAttributeName);
        if (requestObject == null) {
            throw new BlockadeProcessException("RequestObject is null.");
        }
        blockadeFilterMap = new HashMap();
        Iterator entries = blockadeMapping.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry entry = (Map.Entry) entries.next();
            try {
                blockadeFilterMap.put(entry.getValue(), propertyAccess.get(requestObject, (String) entry.getKey()));
            } catch (IllegalArgumentException e) {
                throw new BlockadeProcessException("BlockadeCodeMaster value '" + entry.getKey() + "' cannot acquire from a request.", e);
            } catch (NoSuchPropertyException e) {
                throw new BlockadeProcessException("BlockadeCodeMaster value '" + entry.getKey() + "' cannot acquire from a request.", e);
            } catch (InvocationTargetException e) {
                throw new BlockadeProcessException("BlockadeCodeMaster value '" + entry.getKey() + "' cannot acquire from a request.", e.getTargetException());
            }
        }
    }
    if (blockadeCodeMaster instanceof List) {
        List list = (List) blockadeCodeMaster;
        for (int i = 0, imax = list.size(); i < imax; i++) {
            Object blockade = list.get(i);
            if (blockadeFilterMap != null) {
                if (!isMatchBlockadeMapping(blockadeFilterMap, blockade)) {
                    continue;
                }
            }
            checkBlockade(reqPath, blockade, isSpecialUser, userKey);
        }
    } else if (blockadeCodeMaster instanceof RecordSet) {
        RecordSet recset = (RecordSet) blockadeCodeMaster;
        for (int i = 0, imax = recset.size(); i < imax; i++) {
            Object blockade = recset.get(i);
            if (blockadeFilterMap != null) {
                if (!isMatchBlockadeMapping(blockadeFilterMap, blockade)) {
                    continue;
                }
            }
            checkBlockade(reqPath, blockade, isSpecialUser, userKey);
        }
    } else {
        throw new BlockadeProcessException("Unsupported type of BlockadeCodeMaster. type=" + blockadeCodeMaster.getClass());
    }
    return chain.invokeNext(context);
}
Also used : HashMap(java.util.HashMap) InvocationTargetException(java.lang.reflect.InvocationTargetException) RowData(jp.ossc.nimbus.recset.RowData) RecordList(jp.ossc.nimbus.beans.dataset.RecordList) Iterator(java.util.Iterator) NoSuchPropertyException(jp.ossc.nimbus.beans.NoSuchPropertyException) Record(jp.ossc.nimbus.beans.dataset.Record) RecordList(jp.ossc.nimbus.beans.dataset.RecordList) List(java.util.List) RecordSet(jp.ossc.nimbus.recset.RecordSet) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with NoSuchPropertyException

use of jp.ossc.nimbus.beans.NoSuchPropertyException in project nimbus by nimbus-org.

the class BlockadeInterceptorService method checkBlockade.

private void checkBlockade(String reqPath, Object blockade, boolean isSpecialUser, String userKey) throws BlockadeException, BlockadeProcessException {
    int state = 0;
    try {
        Object stateObject = propertyAccess.get(blockade, statePropertyName);
        if (stateObject == null) {
            throw new BlockadeProcessException("BlockadeCodeMaster value '" + statePropertyName + "' is null from a record.");
        }
        if (stateObject instanceof Number) {
            state = ((Number) stateObject).intValue();
        } else if (stateObject instanceof String) {
            state = Integer.parseInt((String) stateObject);
        } else if (stateObject instanceof Boolean) {
            state = ((Boolean) stateObject).booleanValue() ? 1 : 0;
        }
    } catch (NumberFormatException e) {
        throw new BlockadeProcessException("BlockadeCodeMaster value '" + statePropertyName + "' cannot acquire from a record.", e);
    } catch (IllegalArgumentException e) {
        throw new BlockadeProcessException("BlockadeCodeMaster value '" + statePropertyName + "' cannot acquire from a record.", e);
    } catch (NoSuchPropertyException e) {
        throw new BlockadeProcessException("BlockadeCodeMaster value '" + statePropertyName + "' cannot acquire from a record.", e);
    } catch (InvocationTargetException e) {
        throw new BlockadeProcessException("BlockadeCodeMaster value '" + statePropertyName + "' cannot acquire from a record.", e.getTargetException());
    }
    if (state == stateOpen) {
        return;
    }
    String path = null;
    try {
        path = (String) propertyAccess.get(blockade, pathPropertyName);
    } catch (ClassCastException e) {
        throw new BlockadeProcessException("BlockadeCodeMaster value '" + pathPropertyName + "' cannot acquire from a record.", e);
    } catch (IllegalArgumentException e) {
        throw new BlockadeProcessException("BlockadeCodeMaster value '" + pathPropertyName + "' cannot acquire from a record.", e);
    } catch (NoSuchPropertyException e) {
        throw new BlockadeProcessException("BlockadeCodeMaster value '" + pathPropertyName + "' cannot acquire from a record.", e);
    } catch (InvocationTargetException e) {
        throw new BlockadeProcessException("BlockadeCodeMaster value '" + pathPropertyName + "' cannot acquire from a record.", e.getTargetException());
    }
    if (path == null) {
        throw new BlockadeProcessException("BlockadeCodeMaster value '" + pathPropertyName + "' is null from a record.");
    }
    boolean isMatch = false;
    if (reqPath.equals(path)) {
        isMatch = true;
    } else {
        Pattern pattern = (Pattern) pathPatternMap.get(path);
        if (pattern == null) {
            initPathPatternMap(pathPatternMap, path);
            pattern = (Pattern) pathPatternMap.get(path);
        }
        isMatch = pattern.matcher(reqPath).matches();
    }
    if (!isMatch) {
        return;
    }
    String message = null;
    try {
        message = (String) propertyAccess.get(blockade, messagePropertyName);
    } catch (ClassCastException e) {
        throw new BlockadeProcessException("BlockadeCodeMaster value '" + messagePropertyName + "' cannot acquire from a record.", e);
    } catch (IllegalArgumentException e) {
        throw new BlockadeProcessException("BlockadeCodeMaster value '" + messagePropertyName + "' cannot acquire from a record.", e);
    } catch (NoSuchPropertyException e) {
        throw new BlockadeProcessException("BlockadeCodeMaster value '" + messagePropertyName + "' cannot acquire from a record.", e);
    } catch (InvocationTargetException e) {
        throw new BlockadeProcessException("BlockadeCodeMaster value '" + messagePropertyName + "' cannot acquire from a record.", e.getTargetException());
    }
    if (state == stateTestAllClose || state == stateTestPartClose) {
        if (isSpecialUser) {
            return;
        }
        if (state == stateTestAllClose) {
            throw message == null ? new BlockadeAllCloseException("Blockade because of not special user. user=" + userKey) : new BlockadeAllCloseException(message);
        } else {
            throw message == null ? new BlockadePartCloseException("Blockade because of not special user. user=" + userKey) : new BlockadePartCloseException(message);
        }
    } else if (state == stateAllClose) {
        throw message == null ? new BlockadeAllCloseException("Blockade.") : new BlockadeAllCloseException(message);
    } else if (state == statePartClose) {
        throw message == null ? new BlockadePartCloseException("Blockade.") : new BlockadePartCloseException(message);
    }
    throw message == null ? new BlockadeAllCloseException("Blockade.") : new BlockadeAllCloseException(message);
}
Also used : Pattern(java.util.regex.Pattern) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchPropertyException(jp.ossc.nimbus.beans.NoSuchPropertyException)

Example 10 with NoSuchPropertyException

use of jp.ossc.nimbus.beans.NoSuchPropertyException in project nimbus by nimbus-org.

the class TraceLoggingInterceptorService method invoke.

/**
 * ログを出力して、次のインターセプタを呼び出す。<p>
 * サービスが開始されていない場合は、次のインターセプタを呼び出す。<br>
 *
 * @param context 呼び出しのコンテキスト情報
 * @param chain 次のインターセプタを呼び出すためのチェーン
 * @return 呼び出し結果の戻り値
 * @exception Throwable 呼び出し先で例外が発生した場合、またはこのインターセプタで任意の例外が発生した場合。但し、本来呼び出される処理がthrowしないRuntimeException以外の例外をthrowしても、呼び出し元には伝播されない。
 */
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
    if (getState() != STARTED || !isEnabled()) {
        return chain.invokeNext(context);
    }
    final long start = System.currentTimeMillis();
    StringBuilder buf = null;
    StringBuilder targetBuf = null;
    StringBuilder methodBuf = null;
    StringBuilder parameterBuf = null;
    String sequenceId = null;
    if (sequence != null) {
        sequenceId = sequence.increment();
        if (buf == null) {
            buf = new StringBuilder();
        }
        buf.append(sequenceId);
    }
    if (isOutputTarget || isOutputTargetOnResponse) {
        targetBuf = new StringBuilder();
        Object target = context.getTargetObject();
        if (outputTargetProperties != null && outputTargetProperties.length != 0) {
            targetBuf.append('[');
            for (int i = 0; i < outputTargetProperties.length; i++) {
                Object prop = null;
                try {
                    prop = propertyAccess.get(target, outputTargetProperties[i]);
                } catch (IllegalArgumentException e) {
                } catch (NoSuchPropertyException e) {
                } catch (InvocationTargetException e) {
                }
                printObject(targetBuf, prop);
                if (i != outputTargetProperties.length - 1) {
                    targetBuf.append(',');
                }
            }
            targetBuf.append(']');
        } else {
            printObject(targetBuf, target);
        }
        if (isOutputTarget) {
            if (buf == null) {
                buf = new StringBuilder();
            } else {
                buf.append(',');
            }
            buf.append(targetBuf);
        }
    }
    if (context instanceof MethodInvocationContext) {
        MethodInvocationContext methodContext = (MethodInvocationContext) context;
        if (isOutputMethod || isOutputMethodOnResponse) {
            methodBuf = new StringBuilder();
            Method method = methodContext.getTargetMethod();
            if (method != null) {
                MethodEditor editor = new MethodEditor();
                editor.setValue(method);
                methodBuf.append(editor.getAsText());
            } else {
                methodBuf.append("null");
            }
            if (isOutputMethod) {
                if (buf == null) {
                    buf = new StringBuilder();
                } else {
                    buf.append(',');
                }
                buf.append(methodBuf);
            }
        }
        if (isOutputParameter || isOutputParameterOnResponse) {
            parameterBuf = new StringBuilder();
            Object[] params = methodContext.getParameters();
            if (params != null) {
                parameterBuf.append('[');
                if (outputParameterProperties != null && outputParameterProperties.length != 0) {
                    for (int i = 0; i < outputParameterProperties.length; i++) {
                        Object prop = null;
                        try {
                            prop = propertyAccess.get(params, outputParameterProperties[i]);
                        } catch (IllegalArgumentException e) {
                        } catch (NoSuchPropertyException e) {
                        } catch (InvocationTargetException e) {
                        }
                        printObject(parameterBuf, prop);
                        if (i != outputParameterProperties.length - 1) {
                            parameterBuf.append(',');
                        }
                    }
                } else {
                    printObject(parameterBuf, params);
                }
                parameterBuf.append(']');
            } else {
                parameterBuf.append("null");
            }
            if (isOutputParameter) {
                if (buf == null) {
                    buf = new StringBuilder();
                } else {
                    buf.append(',');
                }
                buf.append(parameterBuf);
            }
        }
    }
    if (isOutputRequestLog && getLogger().isWrite(requestMessageId)) {
        if (isOutputCallStackTrace) {
            getLogger().write(requestMessageId, buf == null ? "" : buf.toString(), new Exception("Call stack"));
        } else {
            getLogger().write(requestMessageId, buf == null ? "" : buf.toString());
        }
    }
    if (buf != null) {
        buf.setLength(0);
    }
    Throwable throwable = null;
    Object ret = null;
    try {
        ret = chain.invokeNext(context);
        return ret;
    } catch (Throwable th) {
        throwable = th;
        throw th;
    } finally {
        final long end = System.currentTimeMillis();
        if (isOutputResponseLog && getLogger().isWrite(responseMessageId)) {
            if (buf == null) {
                buf = new StringBuilder();
            }
            if (sequenceId != null) {
                buf.append(sequenceId);
            }
            if (isOutputTargetOnResponse) {
                if (buf.length() != 0) {
                    buf.append(',');
                }
                buf.append(targetBuf);
            }
            if (isOutputMethodOnResponse) {
                if (buf.length() != 0) {
                    buf.append(',');
                }
                buf.append(methodBuf);
            }
            if (isOutputParameterOnResponse) {
                if (buf.length() != 0) {
                    buf.append(',');
                }
                buf.append(parameterBuf);
            }
            if (throwable == null) {
                if (isOutputReturn) {
                    if (buf.length() != 0) {
                        buf.append(',');
                    }
                    if (outputReturnProperties != null && outputReturnProperties.length != 0) {
                        buf.append('[');
                        for (int i = 0; i < outputReturnProperties.length; i++) {
                            Object prop = null;
                            try {
                                prop = propertyAccess.get(ret, outputReturnProperties[i]);
                            } catch (IllegalArgumentException e) {
                            } catch (NoSuchPropertyException e) {
                            } catch (InvocationTargetException e) {
                            }
                            printObject(buf, prop);
                            if (i != outputReturnProperties.length - 1) {
                                buf.append(',');
                            }
                        }
                        buf.append(']');
                    } else {
                        printObject(buf, ret);
                    }
                }
            }
            if (isOutputPerformance) {
                if (buf.length() != 0) {
                    buf.append(',');
                }
                buf.append(end - start);
            }
            if (throwable != null && isOutputThrowable) {
                getLogger().write(responseMessageId, buf.toString(), throwable);
            } else {
                getLogger().write(responseMessageId, buf.toString());
            }
        }
    }
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) MethodEditor(jp.ossc.nimbus.beans.MethodEditor) NoSuchPropertyException(jp.ossc.nimbus.beans.NoSuchPropertyException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchPropertyException(jp.ossc.nimbus.beans.NoSuchPropertyException)

Aggregations

NoSuchPropertyException (jp.ossc.nimbus.beans.NoSuchPropertyException)27 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 Map (java.util.Map)13 HashMap (java.util.HashMap)11 Iterator (java.util.Iterator)11 Property (jp.ossc.nimbus.beans.Property)8 RecordList (jp.ossc.nimbus.beans.dataset.RecordList)7 LinkedHashMap (java.util.LinkedHashMap)6 List (java.util.List)6 ArrayList (java.util.ArrayList)5 NestedProperty (jp.ossc.nimbus.beans.NestedProperty)5 SQLException (java.sql.SQLException)4 SimpleProperty (jp.ossc.nimbus.beans.SimpleProperty)4 DataSet (jp.ossc.nimbus.beans.dataset.DataSet)4 Record (jp.ossc.nimbus.beans.dataset.Record)4 ParameterMetaData (java.sql.ParameterMetaData)3 ResultSet (java.sql.ResultSet)3 ResultSetMetaData (java.sql.ResultSetMetaData)3 IndexedProperty (jp.ossc.nimbus.beans.IndexedProperty)3 PropertyEditor (java.beans.PropertyEditor)2