use of org.springframework.web.bind.annotation.RequestMethod in project commons by terran4j.
the class Request method exe.
public Response exe() throws HttpException {
// 获取实际的 URL。
String actualURL = getActualURL();
HttpRequest request = new HttpRequest(actualURL);
// 获取实际的入参。
final Map<String, String> actualParams = getActualParams();
request.setParam(actualParams);
RequestMethod method = RequestMethod.GET;
String methodName = action.getMethod();
if (StringUtils.hasText(methodName)) {
method = RequestMethod.valueOf(methodName);
if (method == null) {
String msg = String.format("http method[%s] not supported in action: %s", methodName, action.getId());
throw new UnsupportedOperationException(msg);
}
}
request.setMethod(method);
Map<String, String> actualHeaders = getActualHeaders();
request.setHeaders(actualHeaders);
List<HttpClientListener> listeners = action.getHttpClient().getListeners();
for (HttpClientListener listener : listeners) {
listener.beforeExecute(request);
}
String response = request.execute();
for (HttpClientListener listener : listeners) {
response = listener.afterExecute(request, response);
}
JsonElement result;
try {
result = parser.parse(response);
} catch (JsonSyntaxException e) {
// 不是 json 串,就按普通的字符串来处理。
result = new JsonPrimitive(response);
}
List<Write> writes = action.getWrites();
if (writes != null && writes.size() > 0) {
JsonObject resultObject = null;
if (result.isJsonObject()) {
resultObject = result.getAsJsonObject();
}
context.push(new JsonValueSource(resultObject));
for (Write write : writes) {
write.doWrite(session, context);
}
context.pop();
}
return new Response(result, session);
}
use of org.springframework.web.bind.annotation.RequestMethod in project spring-framework by spring-projects.
the class RequestMappingHandlerMapping method initCorsConfiguration.
@Override
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) {
HandlerMethod handlerMethod = createHandlerMethod(handler, method);
Class<?> beanType = handlerMethod.getBeanType();
CrossOrigin typeAnnotation = AnnotatedElementUtils.findMergedAnnotation(beanType, CrossOrigin.class);
CrossOrigin methodAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, CrossOrigin.class);
if (typeAnnotation == null && methodAnnotation == null) {
return null;
}
CorsConfiguration config = new CorsConfiguration();
updateCorsConfig(config, typeAnnotation);
updateCorsConfig(config, methodAnnotation);
if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
config.addAllowedMethod(allowedMethod.name());
}
}
return config.applyPermitDefaultValues();
}
use of org.springframework.web.bind.annotation.RequestMethod in project spring-framework by spring-projects.
the class RequestMappingHandlerMapping method initCorsConfiguration.
@Override
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) {
HandlerMethod handlerMethod = createHandlerMethod(handler, method);
Class<?> beanType = handlerMethod.getBeanType();
CrossOrigin typeAnnotation = AnnotatedElementUtils.findMergedAnnotation(beanType, CrossOrigin.class);
CrossOrigin methodAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, CrossOrigin.class);
if (typeAnnotation == null && methodAnnotation == null) {
return null;
}
CorsConfiguration config = new CorsConfiguration();
updateCorsConfig(config, typeAnnotation);
updateCorsConfig(config, methodAnnotation);
if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
config.addAllowedMethod(allowedMethod.name());
}
}
return config.applyPermitDefaultValues();
}
use of org.springframework.web.bind.annotation.RequestMethod in project spring-framework by spring-projects.
the class RequestMappingHandlerMappingTests method assertComposedAnnotationMapping.
private RequestMappingInfo assertComposedAnnotationMapping(String methodName, String path, RequestMethod requestMethod) throws Exception {
Class<?> clazz = ComposedAnnotationController.class;
Method method = ClassUtils.getMethod(clazz, methodName, (Class<?>[]) null);
RequestMappingInfo info = this.handlerMapping.getMappingForMethod(method, clazz);
assertThat(info).isNotNull();
Set<PathPattern> paths = info.getPatternsCondition().getPatterns();
assertThat(paths.size()).isEqualTo(1);
assertThat(paths.iterator().next().getPatternString()).isEqualTo(path);
Set<RequestMethod> methods = info.getMethodsCondition().getMethods();
assertThat(methods.size()).isEqualTo(1);
assertThat(methods.iterator().next()).isEqualTo(requestMethod);
return info;
}
use of org.springframework.web.bind.annotation.RequestMethod in project disconf by knightliao.
the class RoleResourceMgrImpl method checkUserPermission.
/**
* @param pattern
* @param method
*
* @return
*/
@Override
public boolean checkUserPermission(String pattern, RequestMethod method) {
// 获取用户角色
Visitor visitor = ThreadContext.getSessionVisitor();
if (visitor == null) {
return false;
}
String urlPattarn = pattern;
if (!urlPattarn.endsWith(RoleResourceConstant.URL_SPLITOR)) {
urlPattarn += RoleResourceConstant.URL_SPLITOR;
}
Integer roleId = visitor.getRoleId();
Map<String, Map<RequestMethod, List<Integer>>> roleResMap = getAllAsMap();
Map<RequestMethod, List<Integer>> methodMap = roleResMap.get(urlPattarn);
if (methodMap == null) {
return false;
}
List<Integer> roleIdList = methodMap.get(method);
if (roleIdList == null) {
return false;
}
if (!roleIdList.contains(roleId)) {
return false;
}
return true;
}
Aggregations