use of org.jocean.http.rosa.impl.RequestChanger in project jocean-http by isdom.
the class HeaderParamPreprocessor method call.
@Override
public RequestChanger call(final Object signalBean) {
if (null == signalBean) {
return null;
}
final Field[] headerFields = ReflectUtils.getAnnotationFieldsOf(signalBean.getClass(), HeaderParam.class);
if (headerFields.length > 0) {
return new RequestChanger() {
@Override
public void call(final HttpRequest request) {
for (Field field : headerFields) {
try {
final Object value = field.get(signalBean);
if (null != value) {
final String headername = field.getAnnotation(HeaderParam.class).value();
request.headers().set(headername, value);
}
} catch (Exception e) {
LOG.warn("exception when get value from field:[{}], detail:{}", field, ExceptionUtils.exception2detail(e));
}
}
}
@Override
public int ordinal() {
return 100;
}
};
} else {
return null;
}
}
use of org.jocean.http.rosa.impl.RequestChanger in project jocean-http by isdom.
the class QueryParamPreprocessor method call.
@Override
public RequestChanger call(final Object signalBean) {
if (null == signalBean) {
return null;
}
final Field[] queryFields = ReflectUtils.getAnnotationFieldsOf(signalBean.getClass(), QueryParam.class);
if (queryFields.length > 0) {
return new RequestChanger() {
@Override
public void call(final HttpRequest request) {
// only GET method will assemble query parameters
// or the QueryParam field explicit annotated HttpMethod via AnnotationWrapper
// assemble query parameters
final boolean isGetMethod = request.method().equals(HttpMethod.GET);
final QueryStringEncoder encoder = new QueryStringEncoder(request.uri());
for (Field field : queryFields) {
if (isGetMethod || Nettys.isFieldAnnotatedOfHttpMethod(field, request.method())) {
try {
final Object value = field.get(signalBean);
if (null != value) {
final String paramkey = field.getAnnotation(QueryParam.class).value();
encoder.addParam(paramkey, String.valueOf(value));
}
} catch (Exception e) {
LOG.warn("exception when get field({})'s value, detail:{}", field, ExceptionUtils.exception2detail(e));
}
}
}
request.setUri(encoder.toString());
}
@Override
public int ordinal() {
return 100;
}
};
} else {
return null;
}
}
Aggregations