Search in sources :

Example 1 with Type

use of com.twinsoft.convertigo.beans.core.UrlMappingParameter.Type in project convertigo by convertigo.

the class AbstractRestOperation method addParameter.

@Override
protected void addParameter(UrlMappingParameter parameter) throws EngineException {
    List<UrlMappingParameter> l = getParameterList();
    if (hasBodyParameter) {
        Type type = parameter.getType();
        if (type != Type.Path && type != Type.Header) {
            if (type == Type.Body) {
                throw new EngineException("The REST operation already contains a 'body' parameter");
            } else {
                if (!isChangeTo || (isChangeTo && l.size() != 1)) {
                    throw new EngineException("The REST operation contains a 'body' parameter. You can only add 'header' parameters");
                }
            }
        }
    } else if (parameter.getType() == Type.Body) {
        for (UrlMappingParameter param : l) {
            Type type = param.getType();
            if (type == Type.Query || type == Type.Form) {
                if (!isChangeTo || (isChangeTo && l.size() != 1)) {
                    throw new EngineException("The REST operation contains a '" + type + "' parameter. You can not add a 'body' parameter");
                }
            }
        }
    }
    super.addParameter(parameter);
    if (!hasBodyParameter && parameter.getType() == Type.Body) {
        hasBodyParameter = true;
    }
}
Also used : DataType(com.twinsoft.convertigo.beans.core.UrlMappingParameter.DataType) HttpMethodType(com.twinsoft.convertigo.engine.enums.HttpMethodType) Type(com.twinsoft.convertigo.beans.core.UrlMappingParameter.Type) MimeType(com.twinsoft.convertigo.engine.enums.MimeType) UrlMappingParameter(com.twinsoft.convertigo.beans.core.UrlMappingParameter) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 2 with Type

use of com.twinsoft.convertigo.beans.core.UrlMappingParameter.Type in project convertigo by convertigo.

the class AbstractRestOperation method canAddParameter.

@Override
protected boolean canAddParameter(UrlMappingParameter parameter) {
    Type type = parameter.getType();
    String method = getMethod();
    if (method.equalsIgnoreCase(HttpMethodType.GET.name()) || method.equalsIgnoreCase(HttpMethodType.HEAD.name()) || method.equalsIgnoreCase(HttpMethodType.DELETE.name())) {
        if (type != Type.Path && type != Type.Query && type != Type.Header) {
            return false;
        }
    }
    return true;
}
Also used : DataType(com.twinsoft.convertigo.beans.core.UrlMappingParameter.DataType) HttpMethodType(com.twinsoft.convertigo.engine.enums.HttpMethodType) Type(com.twinsoft.convertigo.beans.core.UrlMappingParameter.Type) MimeType(com.twinsoft.convertigo.engine.enums.MimeType)

Aggregations

DataType (com.twinsoft.convertigo.beans.core.UrlMappingParameter.DataType)2 Type (com.twinsoft.convertigo.beans.core.UrlMappingParameter.Type)2 HttpMethodType (com.twinsoft.convertigo.engine.enums.HttpMethodType)2 MimeType (com.twinsoft.convertigo.engine.enums.MimeType)2 UrlMappingParameter (com.twinsoft.convertigo.beans.core.UrlMappingParameter)1 EngineException (com.twinsoft.convertigo.engine.EngineException)1