public InterceptorDescriptor parseObject()

in wilma-application/modules/wilma-stub-configuration-parser/src/main/java/com/epam/wilma/stubconfig/json/parser/InterceptorDescriptorJsonParser.java [56:90]


    public InterceptorDescriptor parseObject(final JSONObject interceptorObject, final JSONObject root) {
        InterceptorDescriptor interceptorDescriptor;
        String name = interceptorObject.getString("name");
        String clazz = interceptorObject.getString("class");
        //check for dummy problem of not giving class attribute, or giving 'class' to the end of the class name
        if (clazz == null) {
            throw new DescriptorValidationFailedException("Validation of stub descriptor failed - Class name is missing.");
        }
        if (clazz.toLowerCase().endsWith(".class")) {
            throw new DescriptorValidationFailedException("Validation of stub descriptor failed - Class name '" + clazz
                    + "' should not contain 'class' at its end.");
        }
        ParameterList params = parameterListParser.parseObject(interceptorObject, root);
        RequestInterceptor requestInterceptor = null;
        ResponseInterceptor responseInterceptor = null;
        try {
            requestInterceptor = requestInterceptorInitializer.getExternalClassObject(clazz);
        } catch (InterfaceValidationFailedException e) {
            // don't worry
            LOGGER.debug("No Request interceptor in class:" + clazz, e);
        }
        try {
            responseInterceptor = responseInterceptorInitializer.getExternalClassObject(clazz);
        } catch (InterfaceValidationFailedException e) {
            //don't worry
            LOGGER.debug("No Response interceptor in class:" + clazz, e);
        }
        if (requestInterceptor == null && responseInterceptor == null) {
            throw new DescriptorValidationFailedException("Validation of stub descriptor failed - Class '" + clazz
                    + "' does not implement any of the necessary interfaces.");
        }
        interceptorDescriptor = new InterceptorDescriptor(name, requestInterceptor, responseInterceptor, params);

        return interceptorDescriptor;
    }