use of com.dtflys.forest.filter.Filter in project forest by dromara.
the class XMLBodyLifeCycle method onParameterInitialized.
@Override
public void onParameterInitialized(ForestMethod method, MappingParameter parameter, XMLBody annotation) {
super.onParameterInitialized(method, parameter, annotation);
MetaRequest metaRequest = method.getMetaRequest();
String methodName = methodName(method);
if (metaRequest == null) {
throw new ForestRuntimeException("[Forest] method '" + methodName + "' has not bind a Forest request annotation. Hence the annotation @XMLBody cannot be bind on a parameter in this method.");
}
String contentType = metaRequest.getContentType();
if (StringUtils.isNotEmpty(contentType) && !ContentType.APPLICATION_XML.equals(contentType) && contentType.indexOf("$") < 0) {
throw new ForestRuntimeException("[Forest] the Content-Type of request binding on method '" + methodName + "' has already been set value '" + contentType + "', not 'application/xml'. Hence the annotation @XMLBody cannot be bind on a parameter in this method.");
}
boolean hasDataFileAnn = false;
for (Parameter param : method.getMethod().getParameters()) {
Annotation dataFileAnn = param.getAnnotation(DataFile.class);
if (dataFileAnn != null) {
hasDataFileAnn = true;
break;
}
}
Filter filter = method.getConfiguration().newFilterInstance("xml");
parameter.addFilter(filter);
if (StringUtils.isBlank(contentType) && !hasDataFileAnn) {
metaRequest.setContentType(ContentType.APPLICATION_XML);
}
if (metaRequest.getBodyType() == null) {
metaRequest.setBodyType(ForestDataType.XML);
}
}
use of com.dtflys.forest.filter.Filter in project forest by dromara.
the class MappingFilterInvoke method render.
@Override
public Object render(Object[] args) {
ForestConfiguration configuration = variableScope.getConfiguration();
Filter filter = configuration.newFilterInstance(right.getName());
List<MappingExpr> exprList = getArgList();
Object[] invokeArgs = new Object[exprList.size()];
for (int i = 0; i < exprList.size(); i++) {
MappingExpr expr = exprList.get(i);
Object renderedArg = expr.render(args);
invokeArgs[i] = renderedArg;
}
if (invokeArgs.length > 0) {
return filter.doFilter(configuration, invokeArgs[0]);
}
return null;
}
use of com.dtflys.forest.filter.Filter in project forest by dromara.
the class ForestMethod method processParameterFilter.
/**
* 处理参数的过滤器
* @param parameter 方法参数-字符串模板解析对象,{@link MappingParameter}类实例
* @param filterName 过滤器名称
*/
public void processParameterFilter(MappingParameter parameter, String filterName) {
if (StringUtils.isNotEmpty(filterName)) {
String[] filterNameArray = filterName.split(",");
for (String name : filterNameArray) {
Filter filter = configuration.newFilterInstance(name);
parameter.addFilter(filter);
}
}
}
Aggregations