@Test public void testCreateHttpRequest() throws IOException { String payload = "{ \"result\" : \"SUCCESS\" }"; String baseUrl = "http: String url = "api/v2"; String verb = "POST"; HttpRequestMsg httpMsg = new HttpRequestMsg(); httpMsg.addHeader("Authorization", "key"); httpMsg.setPayload(payload); httpMsg.setVerb(verb); httpMsg.setUrl(url); HttpRequest request = httpMsg.createHttpRequest(getHttpRequestFactory(), baseUrl); assertEquals(baseUrl + "/" + url, request.getUrl().toString()); assertEquals("key", request.getHeaders().getAuthorization()); assertEquals(verb, request.getRequestMethod()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); request.getContent().writeTo(outputStream); assertEquals(payload, outputStream.toString(StandardCharsets.UTF_8.toString())); }
public HttpRequest createHttpRequest(HttpRequestFactory requestFactory, String baseUrl) throws IOException { HttpContent requestContent = new EmptyContent(); if (payload != null) { ByteArrayInputStream payloadStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8)); requestContent = new InputStreamContent("application/json", payloadStream); } HttpHeaders httpHeaders = new HttpHeaders(); for (Map.Entry<String, String> header : headers.entrySet()) { String headerName = header.getKey(); Object headerValue = header.getValue(); FieldInfo fieldInfo = httpHeaders.getClassInfo().getFieldInfo(headerName); if (fieldInfo != null) { headerValue = Collections.singletonList(headerValue); } httpHeaders.set(headerName, headerValue); } GenericUrl fullUrl = new GenericUrl(baseUrl + "/" + this.url); HttpRequest request = requestFactory.buildRequest(verb, fullUrl, requestContent); request.setHeaders(httpHeaders); request.setThrowExceptionOnExecuteError(false); return request; }
HttpRequestMsg { public HttpRequest createHttpRequest(HttpRequestFactory requestFactory, String baseUrl) throws IOException { HttpContent requestContent = new EmptyContent(); if (payload != null) { ByteArrayInputStream payloadStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8)); requestContent = new InputStreamContent("application/json", payloadStream); } HttpHeaders httpHeaders = new HttpHeaders(); for (Map.Entry<String, String> header : headers.entrySet()) { String headerName = header.getKey(); Object headerValue = header.getValue(); FieldInfo fieldInfo = httpHeaders.getClassInfo().getFieldInfo(headerName); if (fieldInfo != null) { headerValue = Collections.singletonList(headerValue); } httpHeaders.set(headerName, headerValue); } GenericUrl fullUrl = new GenericUrl(baseUrl + "/" + this.url); HttpRequest request = requestFactory.buildRequest(verb, fullUrl, requestContent); request.setHeaders(httpHeaders); request.setThrowExceptionOnExecuteError(false); return request; } }
HttpRequestMsg { public HttpRequest createHttpRequest(HttpRequestFactory requestFactory, String baseUrl) throws IOException { HttpContent requestContent = new EmptyContent(); if (payload != null) { ByteArrayInputStream payloadStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8)); requestContent = new InputStreamContent("application/json", payloadStream); } HttpHeaders httpHeaders = new HttpHeaders(); for (Map.Entry<String, String> header : headers.entrySet()) { String headerName = header.getKey(); Object headerValue = header.getValue(); FieldInfo fieldInfo = httpHeaders.getClassInfo().getFieldInfo(headerName); if (fieldInfo != null) { headerValue = Collections.singletonList(headerValue); } httpHeaders.set(headerName, headerValue); } GenericUrl fullUrl = new GenericUrl(baseUrl + "/" + this.url); HttpRequest request = requestFactory.buildRequest(verb, fullUrl, requestContent); request.setHeaders(httpHeaders); request.setThrowExceptionOnExecuteError(false); return request; }  }
HttpRequestMsg { public HttpRequest createHttpRequest(HttpRequestFactory requestFactory, String baseUrl) throws IOException { HttpContent requestContent = new EmptyContent(); if (payload != null) { ByteArrayInputStream payloadStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8)); requestContent = new InputStreamContent("application/json", payloadStream); } HttpHeaders httpHeaders = new HttpHeaders(); for (Map.Entry<String, String> header : headers.entrySet()) { String headerName = header.getKey(); Object headerValue = header.getValue(); FieldInfo fieldInfo = httpHeaders.getClassInfo().getFieldInfo(headerName); if (fieldInfo != null) { headerValue = Collections.singletonList(headerValue); } httpHeaders.set(headerName, headerValue); } GenericUrl fullUrl = new GenericUrl(baseUrl + "/" + this.url); HttpRequest request = requestFactory.buildRequest(verb, fullUrl, requestContent); request.setHeaders(httpHeaders); request.setThrowExceptionOnExecuteError(false); return request; }  String getVerb(); void setVerb(String verb); String getUrl(); void setUrl(String url); String getPayload(); void setPayload(String payload); Map<String, String> getHeaders(); void setHeaders(Map<String, String> headers); void addHeader(String headerName, String headerValue); HttpRequest createHttpRequest(HttpRequestFactory requestFactory, String baseUrl); HttpResponse getResponse(); void setResponse(HttpResponse response); }
HttpRequestMsg { public HttpRequest createHttpRequest(HttpRequestFactory requestFactory, String baseUrl) throws IOException { HttpContent requestContent = new EmptyContent(); if (payload != null) { ByteArrayInputStream payloadStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8)); requestContent = new InputStreamContent("application/json", payloadStream); } HttpHeaders httpHeaders = new HttpHeaders(); for (Map.Entry<String, String> header : headers.entrySet()) { String headerName = header.getKey(); Object headerValue = header.getValue(); FieldInfo fieldInfo = httpHeaders.getClassInfo().getFieldInfo(headerName); if (fieldInfo != null) { headerValue = Collections.singletonList(headerValue); } httpHeaders.set(headerName, headerValue); } GenericUrl fullUrl = new GenericUrl(baseUrl + "/" + this.url); HttpRequest request = requestFactory.buildRequest(verb, fullUrl, requestContent); request.setHeaders(httpHeaders); request.setThrowExceptionOnExecuteError(false); return request; }  String getVerb(); void setVerb(String verb); String getUrl(); void setUrl(String url); String getPayload(); void setPayload(String payload); Map<String, String> getHeaders(); void setHeaders(Map<String, String> headers); void addHeader(String headerName, String headerValue); HttpRequest createHttpRequest(HttpRequestFactory requestFactory, String baseUrl); HttpResponse getResponse(); void setResponse(HttpResponse response);  }