1 package com.griddynamics.jagger.invoker.v2;
3 import org.apache.commons.lang.StringUtils;
4 import org.springframework.http.HttpHeaders;
5 import org.springframework.http.HttpMethod;
7 import java.io.Serializable;
8 import java.util.HashMap;
12 import static com.google.common.collect.Lists.newArrayList;
45 @SuppressWarnings(
"unused")
46 public class JHttpQuery<T> implements Serializable {
48 private HttpMethod method;
49 private HttpHeaders headers;
51 private Class responseBodyType;
52 private Map<String, String> queryParams;
77 return method(HttpMethod.GET);
89 return method(HttpMethod.POST);
101 return method(HttpMethod.PUT);
113 return method(HttpMethod.PATCH);
125 return method(HttpMethod.DELETE);
137 return method(HttpMethod.TRACE);
149 return method(HttpMethod.HEAD);
161 return method(HttpMethod.OPTIONS);
178 this.headers = headers;
197 this.headers.putAll(headers);
214 headers.put(key, values);
231 headers.put(key, newArrayList(value));
250 cookies.entrySet().forEach(entry -> this.headers.add(
"Cookie", entry.getKey() +
"=" + entry.getValue()));
267 this.headers.add(
"Cookie", name +
"=" + value);
301 this.responseBodyType = responseBodyType;
320 this.queryParams = queryParams;
334 if (queryParams == null)
335 this.queryParams =
new HashMap<>();
336 this.queryParams.
put(paramName, paramValue);
350 this.path = StringUtils.startsWith(path,
"/") ? path :
"/" + path;
364 String path = StringUtils.join(paths,
"/");
379 String path = String.format(formatString, args);
392 return responseBodyType;
407 private void initHeadersIfNull() {
408 if (this.headers == null)
409 this.headers =
new HttpHeaders();
414 return "JHttpQuery{" +
416 ", headers=" + headers +
418 ", responseBodyType=" + responseBodyType +
419 ", queryParams=" + queryParams +
420 ", path='" + path +
'\'' +
426 if (
this == o)
return true;
427 if (o == null || getClass() != o.getClass())
return false;
429 JHttpQuery<?> httpQuery = (JHttpQuery<?>) o;
431 if (method != httpQuery.method)
return false;
432 if (headers != null ? !headers.equals(httpQuery.headers) : httpQuery.headers != null)
return false;
433 if (body != null ? !body.equals(httpQuery.body) : httpQuery.body != null)
return false;
434 if (responseBodyType != null ? !responseBodyType.equals(httpQuery.responseBodyType) : httpQuery.responseBodyType != null)
436 if (queryParams != null ? !queryParams.equals(httpQuery.queryParams) : httpQuery.queryParams != null)
return false;
437 return path != null ? path.equals(httpQuery.path) : httpQuery.path == null;
443 int result = method.hashCode();
444 result = 31 * result + (headers != null ? headers.hashCode() : 0);
445 result = 31 * result + (body != null ? body.hashCode() : 0);
446 result = 31 * result + (responseBodyType != null ? responseBodyType.hashCode() : 0);
447 result = 31 * result + (queryParams != null ? queryParams.hashCode() : 0);
448 result = 31 * result + (path != null ? path.hashCode() : 0);