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;
43 @SuppressWarnings(
"unused")
44 public class JHttpQuery<T> implements Serializable {
46 private HttpMethod method;
47 private HttpHeaders headers;
49 private Class responseBodyType;
50 private Map<String, String> queryParams;
75 return method(HttpMethod.GET);
87 return method(HttpMethod.POST);
99 return method(HttpMethod.PUT);
111 return method(HttpMethod.PATCH);
123 return method(HttpMethod.DELETE);
135 return method(HttpMethod.TRACE);
147 return method(HttpMethod.HEAD);
159 return method(HttpMethod.OPTIONS);
176 this.headers = headers;
195 this.headers.putAll(headers);
212 headers.put(key, values);
229 headers.put(key, newArrayList(value));
248 cookies.entrySet().forEach(entry -> this.headers.add(
"Cookie", entry.getKey() +
"=" + entry.getValue()));
265 this.headers.add(
"Cookie", name +
"=" + value);
299 this.responseBodyType = responseBodyType;
318 this.queryParams = queryParams;
332 if (queryParams == null)
333 this.queryParams =
new HashMap<>();
334 this.queryParams.
put(paramName, paramValue);
348 this.path = StringUtils.startsWith(path,
"/") ? path :
"/" + path;
362 String path = StringUtils.join(paths,
"/");
377 String path = String.format(formatString, args);
390 return responseBodyType;
405 private void initHeadersIfNull() {
406 if (this.headers == null)
407 this.headers =
new HttpHeaders();
412 return "JHttpQuery{" +
414 ", headers=" + headers +
416 ", responseBodyType=" + responseBodyType +
417 ", queryParams=" + queryParams +
418 ", path='" + path +
'\'' +
424 if (
this == o)
return true;
425 if (o == null || getClass() != o.getClass())
return false;
427 JHttpQuery<?> httpQuery = (JHttpQuery<?>) o;
429 if (method != httpQuery.method)
return false;
430 if (headers != null ? !headers.equals(httpQuery.headers) : httpQuery.headers != null)
return false;
431 if (body != null ? !body.equals(httpQuery.body) : httpQuery.body != null)
return false;
432 if (responseBodyType != null ? !responseBodyType.equals(httpQuery.responseBodyType) : httpQuery.responseBodyType != null)
434 if (queryParams != null ? !queryParams.equals(httpQuery.queryParams) : httpQuery.queryParams != null)
return false;
435 return path != null ? path.equals(httpQuery.path) : httpQuery.path == null;
441 int result = method.hashCode();
442 result = 31 * result + (headers != null ? headers.hashCode() : 0);
443 result = 31 * result + (body != null ? body.hashCode() : 0);
444 result = 31 * result + (responseBodyType != null ? responseBodyType.hashCode() : 0);
445 result = 31 * result + (queryParams != null ? queryParams.hashCode() : 0);
446 result = 31 * result + (path != null ? path.hashCode() : 0);