List of usage examples for org.springframework.http HttpMethod toString
public String toString()
From source file:com.github.wnameless.spring.bulkapi.BulkApiValidator.java
/** * Checks if any request path with certain method is bulkable or not. * //from w w w. ja v a2s . c om * @param path * a request bulk path * @param method * a request bulk method * @return true if request path and method is bulkable, false otherwise */ public boolean validatePath(String path, HttpMethod method) { RoutingPath rp = pathRes.findByRequestPathAndMethod(path, RequestMethod.valueOf(method.toString())); if (rp == null) return false; Annotation bulkable = findBulkableAnno(rp); if (bulkable != null) { if (isAutoApply(bulkable) || isAcceptBulk(rp)) return true; } return false; }
From source file:de.zib.gndms.gndmc.utils.HTTPGetter.java
public int get(final HttpMethod method, String url, final HttpHeaders headers) throws NoSuchAlgorithmException, KeyManagementException { logger.debug(method.toString() + " URL " + url); EnhancedResponseExtractor responseExtractor = get(method, url, new RequestCallback() { @Override/*from w w w . j av a2 s. c o m*/ public void doWithRequest(ClientHttpRequest request) throws IOException { // add headers if (headers != null) request.getHeaders().putAll(headers); } }); int statusCode = responseExtractor.getStatusCode(); int redirectionCounter = 0; // redirect as long as needed while (300 <= statusCode && statusCode < 400) { final List<String> cookies = DefaultResponseExtractor.getCookies(responseExtractor.getHeaders()); final String location = DefaultResponseExtractor.getLocation(responseExtractor.getHeaders()); logger.debug("Redirection " + ++redirectionCounter); logger.trace("Redirecting to " + location + " with cookies " + cookies.toString()); responseExtractor = get(method, location, new RequestCallback() { @Override public void doWithRequest(ClientHttpRequest request) throws IOException { for (String c : cookies) request.getHeaders().add("Cookie", c.split(";", 2)[0]); // add headers if (headers != null) request.getHeaders().putAll(headers); } }); statusCode = responseExtractor.getStatusCode(); } logger.debug("HTTP " + method.toString() + " Status Code " + statusCode + " after " + redirectionCounter + " redirections"); return statusCode; }
From source file:io.restassured.module.mockmvc.internal.MockMvcRequestSenderImpl.java
private void logRequestIfApplicable(HttpMethod method, String uri, String originalPath, Object[] unnamedPathParams) { if (requestLoggingFilter == null) { return;/*from w w w . ja v a 2 s. c o m*/ } final RequestSpecificationImpl reqSpec = new RequestSpecificationImpl("http://localhost", RestAssured.UNDEFINED_PORT, "", new NoAuthScheme(), Collections.<Filter>emptyList(), null, true, ConfigConverter.convertToRestAssuredConfig(config), logRepository, null); reqSpec.setMethod(method.toString()); reqSpec.path(uri); reqSpec.buildUnnamedPathParameterTuples(unnamedPathParams); if (params != null) { new ParamLogger(params) { protected void logParam(String paramName, Object paramValue) { reqSpec.param(paramName, paramValue); } }.logParams(); } if (queryParams != null) { new ParamLogger(queryParams) { protected void logParam(String paramName, Object paramValue) { reqSpec.queryParam(paramName, paramValue); } }.logParams(); } if (formParams != null) { new ParamLogger(formParams) { protected void logParam(String paramName, Object paramValue) { reqSpec.formParam(paramName, paramValue); } }.logParams(); } if (headers != null) { for (Header header : headers) { reqSpec.header(header); } } if (cookies != null) { for (Cookie cookie : cookies) { reqSpec.cookie(cookie); } } if (requestBody != null) { if (requestBody instanceof byte[]) { reqSpec.body((byte[]) requestBody); } else if (requestBody instanceof File) { String contentType = findContentType(); String charset = null; if (StringUtils.isNotBlank(contentType)) { charset = CharsetExtractor.getCharsetFromContentType(contentType); } if (charset == null) { charset = Charset.defaultCharset().toString(); } String string = fileToString((File) requestBody, charset); reqSpec.body(string); } else { reqSpec.body(requestBody); } } if (multiParts != null) { for (MockMvcMultiPart multiPart : multiParts) { reqSpec.multiPart( new MultiPartSpecBuilder(multiPart.getContent()).controlName(multiPart.getControlName()) .fileName(multiPart.getFileName()).mimeType(multiPart.getMimeType()).build()); } } String uriPath = PathSupport.getPath(uri); String originalUriPath = PathSupport.getPath(originalPath); requestLoggingFilter.filter(reqSpec, null, new FilterContextImpl(uri, originalUriPath, uriPath, uri, uri, new Object[0], method.toString(), null, Collections.<Filter>emptyList().iterator(), new HashMap<String, Object>())); }
From source file:com.jayway.restassured.module.mockmvc.internal.MockMvcRequestSenderImpl.java
private void logRequestIfApplicable(HttpMethod method, String uri, String originalPath, Object[] unnamedPathParams) { if (requestLoggingFilter == null) { return;/*from ww w. j a v a 2s. co m*/ } final RequestSpecificationImpl reqSpec = new RequestSpecificationImpl("http://localhost", RestAssured.UNDEFINED_PORT, "", new NoAuthScheme(), Collections.<Filter>emptyList(), null, true, convertToRestAssuredConfig(config), logRepository, null); reqSpec.setMethod(method.toString()); reqSpec.path(uri); reqSpec.buildUnnamedPathParameterTuples(unnamedPathParams); if (params != null) { new ParamLogger(params) { protected void logParam(String paramName, Object paramValue) { reqSpec.param(paramName, paramValue); } }.logParams(); } if (queryParams != null) { new ParamLogger(queryParams) { protected void logParam(String paramName, Object paramValue) { reqSpec.queryParam(paramName, paramValue); } }.logParams(); } if (formParams != null) { new ParamLogger(formParams) { protected void logParam(String paramName, Object paramValue) { reqSpec.formParam(paramName, paramValue); } }.logParams(); } if (headers != null) { for (Header header : headers) { reqSpec.header(header); } } if (cookies != null) { for (Cookie cookie : cookies) { reqSpec.cookie(cookie); } } if (requestBody != null) { if (requestBody instanceof byte[]) { reqSpec.body((byte[]) requestBody); } else if (requestBody instanceof File) { String contentType = findContentType(); String charset = null; if (StringUtils.isNotBlank(contentType)) { charset = CharsetExtractor.getCharsetFromContentType(contentType); } if (charset == null) { charset = Charset.defaultCharset().toString(); } String string = fileToString((File) requestBody, charset); reqSpec.body(string); } else { reqSpec.body(requestBody); } } if (multiParts != null) { for (MockMvcMultiPart multiPart : multiParts) { reqSpec.multiPart( new MultiPartSpecBuilder(multiPart.getContent()).controlName(multiPart.getControlName()) .fileName(multiPart.getFileName()).mimeType(multiPart.getMimeType()).build()); } } String uriPath = PathSupport.getPath(uri); String originalUriPath = PathSupport.getPath(originalPath); requestLoggingFilter.filter(reqSpec, null, new FilterContextImpl(uri, originalUriPath, uriPath, uri, uri, new Object[0], Method.valueOf(method.toString()), null, Collections.<Filter>emptyList().iterator(), new HashMap<String, Object>())); }
From source file:org.codehaus.groovy.grails.web.mapping.DefaultUrlMappingsHolder.java
@Override public UrlMappingInfo[] matchAll(String uri, HttpMethod httpMethod) { return matchAll(uri, httpMethod.toString(), UrlMapping.ANY_VERSION); }
From source file:org.codehaus.groovy.grails.web.mapping.DefaultUrlMappingsHolder.java
@Override public UrlMappingInfo[] matchAll(String uri, HttpMethod httpMethod, String version) { return matchAll(uri, httpMethod.toString(), version); }
From source file:org.encuestame.oauth1.support.OAuth1Utils.java
/** * * @param targetUrl// ww w. ja v a 2s.c om * @param parameters * @param additionalParameters * @param method * @return */ private static String buildBaseString(String targetUrl, Map<String, String> parameters, Map<String, String> additionalParameters, HttpMethod method) { Map<String, String> allParameters = new HashMap<String, String>(parameters); allParameters.putAll(additionalParameters); String baseString = method.toString() + "&" + encode(targetUrl) + "&"; List<String> keys = new ArrayList<String>(allParameters.keySet()); Collections.sort(keys); String separator = ""; for (String key : keys) { String parameterValue = allParameters.get(key); baseString += encode(separator + key + "=" + encode(parameterValue)); separator = "&"; } return baseString; }
From source file:org.grails.web.mapping.RegexUrlMapping.java
public RegexUrlMapping(RegexUrlMapping regexUrlMapping, HttpMethod httpMethod) { this(regexUrlMapping.urlData, regexUrlMapping.controllerName, regexUrlMapping.actionName, regexUrlMapping.namespace, regexUrlMapping.pluginName, regexUrlMapping.viewName, httpMethod.toString(), regexUrlMapping.version, regexUrlMapping.constraints, regexUrlMapping.grailsApplication); }
From source file:org.springframework.social.oauth1.SigningUtils.java
private static String buildBaseString(String targetUrl, Map<String, String> parameters, Map<String, String> additionalParameters, HttpMethod method) { Map<String, String> allParameters = new HashMap<String, String>(parameters); allParameters.putAll(additionalParameters); String baseString = method.toString() + "&" + encode(targetUrl) + "&"; List<String> keys = new ArrayList<String>(allParameters.keySet()); Collections.sort(keys);// ww w . j a v a 2 s . com String separator = ""; for (String key : keys) { String parameterValue = allParameters.get(key); baseString += encode(separator + key + "=" + encode(parameterValue)); separator = "&"; } return baseString; }