org.glassfish.jersey.client.HttpUrlConnectorProvider Java Examples

The following examples show how to use org.glassfish.jersey.client.HttpUrlConnectorProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 8 votes vote down vote up
/**
 * Build the Client used to make HTTP requests.
 * @param debugging Debug setting
 * @return Client
 */
protected Client buildHttpClient(boolean debugging) {
  final ClientConfig clientConfig = new ClientConfig();
  clientConfig.register(MultiPartFeature.class);
  clientConfig.register(json);
  clientConfig.register(JacksonFeature.class);
  clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
  // turn off compliance validation to be able to send payloads with DELETE calls
  clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
  if (debugging) {
    clientConfig.register(new LoggingFeature(java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), java.util.logging.Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, 1024*50 /* Log payloads up to 50K */));
    clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
    // Set logger to ALL
    java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME).setLevel(java.util.logging.Level.ALL);
  } else {
    // suppress warnings for payloads with DELETE calls:
    java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE);
  }
  performAdditionalClientConfiguration(clientConfig);
  ClientBuilder clientBuilder = ClientBuilder.newBuilder();
  customizeClientBuilder(clientBuilder);
  clientBuilder = clientBuilder.withConfig(clientConfig);
  return clientBuilder.build();
}
 
Example #2
Source File: JerseyJaxRsClientFactory.java    From vespa with Apache License 2.0 6 votes vote down vote up
public JerseyJaxRsClientFactory(SSLContext sslContext, HostnameVerifier hostnameVerifier, String userAgent) {
    /*
     * Configure client with some workarounds for HTTP/JAX-RS/Jersey issues. See:
     *   https://jersey.java.net/apidocs/latest/jersey/org/glassfish/jersey/client/ClientProperties.html#SUPPRESS_HTTP_COMPLIANCE_VALIDATION
     *   https://jersey.java.net/apidocs/latest/jersey/org/glassfish/jersey/client/HttpUrlConnectorProvider.html#SET_METHOD_WORKAROUND
     */
    ClientBuilder builder = ClientBuilder.newBuilder()
                                         .property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true) // Allow empty PUT. TODO: Fix API.
                                         .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) // Allow e.g. PATCH method.
                                         .property(ClientProperties.FOLLOW_REDIRECTS, true);
    if (sslContext != null) {
        builder.sslContext(sslContext);
    }
    if (hostnameVerifier != null) {
        builder.hostnameVerifier(hostnameVerifier);
    }
    if (userAgent != null) {
        builder.register((ClientRequestFilter) context -> context.getHeaders().put(HttpHeaders.USER_AGENT, Collections.singletonList(userAgent)));
    }
    this.client = builder.build();
}
 
Example #3
Source File: ParaClient.java    From para with Apache License 2.0 6 votes vote down vote up
/**
 * Default constructor.
 * @param accessKey app access key
 * @param secretKey app secret key
 */
public ParaClient(String accessKey, String secretKey) {
	this.accessKey = accessKey;
	this.secretKey = secretKey;
	if (StringUtils.length(secretKey) < 6) {
		logger.warn("Secret key appears to be invalid. Make sure you call 'signIn()' first.");
	}
	this.throwExceptionOnHTTPError = false;
	ObjectMapper mapper = ParaObjectUtils.getJsonMapper();
	mapper.setSerializationInclusion(JsonInclude.Include.USE_DEFAULTS);
	ClientConfig clientConfig = new ClientConfig();
	clientConfig.register(GenericExceptionMapper.class);
	clientConfig.register(new JacksonJsonProvider(mapper));
	clientConfig.connectorProvider(new HttpUrlConnectorProvider().useSetMethodWorkaround());
	SSLContext sslContext = SslConfigurator.newInstance().createSSLContext();
	apiClient = ClientBuilder.newBuilder().
			sslContext(sslContext).
			withConfig(clientConfig).build();
}
 
Example #4
Source File: TestRestServicePushSource.java    From datacollector with Apache License 2.0 6 votes vote down vote up
private void testEmptyPayloadRequest(String method, String httpServerUrl, List<Record> requestRecords) {
  Response response = ClientBuilder.newClient()
      .property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true)
      .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true)
      .target(httpServerUrl)
      .request()
      .header(Constants.X_SDC_APPLICATION_ID_HEADER, "id")
      .method(method);

  Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getStatus());
  String responseBody = response.readEntity(String.class);

  Assert.assertEquals(1, requestRecords.size());
  Record.Header emptyPayloadRecordHeader = requestRecords.get(0).getHeader();
  Assert.assertEquals(
      "true",
      emptyPayloadRecordHeader.getAttribute(RestServiceReceiver.EMPTY_PAYLOAD_RECORD_HEADER_ATTR_NAME)
  );
  Assert.assertEquals(method, emptyPayloadRecordHeader.getAttribute(RestServiceReceiver.METHOD_HEADER));


  // check custom HTTP Response header
  Assert.assertNotNull(response.getHeaders().getFirst("test"));
  Assert.assertEquals("value", response.getHeaders().getFirst("test"));
}
 
Example #5
Source File: DockerRegistry.java    From carnotzet with Apache License 2.0 6 votes vote down vote up
private WebTarget getRegistryWebTarget(ImageRef imageRef) {
	if (!webTargets.containsKey(imageRef.getRegistryUrl())) {

		ObjectMapper mapper = new ObjectMapper();
		mapper.registerModule(new JavaTimeModule());

		ClientConfig clientCOnfig = new ClientConfig();
		clientCOnfig.connectorProvider(new HttpUrlConnectorProvider());

		// TODO : This client doesn't handle mandatory Oauth2 Bearer token imposed by some registries implementations (ie : docker hub)
		Client client = ClientBuilder.newClient(clientCOnfig)
				.register(new JacksonJaxbJsonProvider(mapper, new Annotations[] {Annotations.JACKSON}))
				.register(JacksonFeature.class);
		String auth = config.getAuthFor(imageRef.getRegistryName());
		if (auth != null) {
			String[] credentials = new String(Base64.getDecoder().decode(auth), StandardCharsets.UTF_8).split(":");
			client.register(HttpAuthenticationFeature.basicBuilder().credentials(credentials[0], credentials[1]));
		}
		WebTarget webTarget = client.target(imageRef.getRegistryUrl());
		webTargets.put(imageRef.getRegistryUrl(), webTarget);
	}
	return webTargets.get(imageRef.getRegistryUrl());
}
 
Example #6
Source File: ApiClient.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Build the Client used to make HTTP requests.
 * @param debugging Debug setting
 * @return Client
 */
protected Client buildHttpClient(boolean debugging) {
  final ClientConfig clientConfig = new ClientConfig();
  clientConfig.register(MultiPartFeature.class);
  clientConfig.register(json);
  clientConfig.register(JacksonFeature.class);
    clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
    if(debugging) {
        clientConfig.register(new LoggingFeature(java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), java.util.logging.Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, 1024 * 50 /* Log payloads up to 50K */));
        clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
        // Set logger to ALL
        java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME).setLevel(java.util.logging.Level.ALL);
    }
    performAdditionalClientConfiguration(clientConfig);
  return ClientBuilder.newClient(clientConfig);
}
 
Example #7
Source File: ApiClient.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Build the Client used to make HTTP requests.
 * @param debugging Debug setting
 * @return Client
 */
protected Client buildHttpClient(boolean debugging) {
  final ClientConfig clientConfig = new ClientConfig();
  clientConfig.register(MultiPartFeature.class);
  clientConfig.register(json);
  clientConfig.register(JacksonFeature.class);
  clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
  if (debugging) {
    clientConfig.register(new LoggingFeature(java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), java.util.logging.Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, 1024*50 /* Log payloads up to 50K */));
    clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
    // Set logger to ALL
    java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME).setLevel(java.util.logging.Level.ALL);
  }
  performAdditionalClientConfiguration(clientConfig);
  return ClientBuilder.newClient(clientConfig);
}
 
Example #8
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
/**
 * Build the Client used to make HTTP requests.
 * @param debugging Debug setting
 * @return Client
 */
protected Client buildHttpClient(boolean debugging) {
  final ClientConfig clientConfig = new ClientConfig();
  clientConfig.register(MultiPartFeature.class);
  clientConfig.register(json);
  clientConfig.register(JacksonFeature.class);
  clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
  // turn off compliance validation to be able to send payloads with DELETE calls
  clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
  if (debugging) {
    clientConfig.register(new LoggingFeature(java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), java.util.logging.Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, 1024*50 /* Log payloads up to 50K */));
    clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
    // Set logger to ALL
    java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME).setLevel(java.util.logging.Level.ALL);
  } else {
    // suppress warnings for payloads with DELETE calls:
    java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE);
  }
  performAdditionalClientConfiguration(clientConfig);
  ClientBuilder clientBuilder = ClientBuilder.newBuilder();
  customizeClientBuilder(clientBuilder);
  clientBuilder = clientBuilder.withConfig(clientConfig);
  return clientBuilder.build();
}
 
Example #9
Source File: VespaJerseyJaxRsClientFactory.java    From vespa with Apache License 2.0 5 votes vote down vote up
public VespaJerseyJaxRsClientFactory(String userAgent) {
    this.client = clientBuilder.newBuilder()
            .property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true) // Allow empty PUT
            .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) // Allow e.g. PATCH method.
            .property(ClientProperties.FOLLOW_REDIRECTS, true)
            .register((ClientRequestFilter) context -> context.getHeaders().put(HttpHeaders.USER_AGENT, List.of(userAgent)))
            .build();
}
 
Example #10
Source File: JerseyHttpClient.java    From karate with MIT License 5 votes vote down vote up
@Override
public HttpResponse makeHttpRequest(Entity entity, ScenarioContext context) {
    String method = request.getMethod();
    if ("PATCH".equals(method)) { // http://danofhisword.com/dev/2015/09/04/Jersey-Client-Http-Patch.html
        builder.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
    }
    Response resp;
    if (entity != null) {
        resp = builder.method(method, entity);
    } else {
        resp = builder.method(method);
    }
    HttpRequest actualRequest = context.getPrevRequest();
    HttpResponse response = new HttpResponse(actualRequest.getStartTime(), actualRequest.getEndTime());
    byte[] bytes = resp.readEntity(byte[].class);        
    response.setUri(getRequestUri());
    response.setBody(bytes);
    response.setStatus(resp.getStatus());
    for (NewCookie c : resp.getCookies().values()) {
        com.intuit.karate.http.Cookie cookie = new com.intuit.karate.http.Cookie(c.getName(), c.getValue());
        cookie.put(DOMAIN, c.getDomain());
        cookie.put(PATH, c.getPath());
        if (c.getExpiry() != null) {
            cookie.put(EXPIRES, c.getExpiry().getTime() + "");
        }
        cookie.put(SECURE, c.isSecure() + "");
        cookie.put(HTTP_ONLY, c.isHttpOnly() + "");
        cookie.put(MAX_AGE, c.getMaxAge() + "");
        response.addCookie(cookie);
    }
    for (Entry<String, List<Object>> entry : resp.getHeaders().entrySet()) {
        response.putHeader(entry.getKey(), entry.getValue());
    }
    return response;
}
 
Example #11
Source File: JerseySpringTest.java    From gravitee-management-rest-api with Apache License 2.0 5 votes vote down vote up
@Autowired
public void setApplicationContext(final ApplicationContext context)
{
    _jerseyTest = new JerseyTest()
    {
        
        @Override
        protected Application configure()
        {
            // Find first available port.
            forceSet(TestProperties.CONTAINER_PORT, "0");

            ResourceConfig application = new GraviteeManagementApplication(authenticationProviderManager);

            application.property("contextConfig", context);
            decorate(application);

            return application;
        }

        @Override
        protected void configureClient(ClientConfig config) {
            super.configureClient(config);

            config.register(ObjectMapperResolver.class);
            config.register(MultiPartFeature.class);
            config.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);

        }
    };
}
 
Example #12
Source File: HttpClientCommon.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private void buildNewAuthenticatedClient(
    List<Stage.ConfigIssue> issues,
    boolean throwExceptions
) {
  if (!throwExceptions && issues == null) {
    throw new IllegalArgumentException("issues list must be non-null if not throwing exceptions");
  }
  client = clientBuilder.build();
  client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
}
 
Example #13
Source File: TestRestServicePushSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private void testPayloadRequest(
    String method,
    String httpServerUrl,
    List<Record> requestRecords
) {
  Response response = ClientBuilder.newClient()
      .property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true)
      .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true)
      .target(httpServerUrl)
      .request()
      .header(Constants.X_SDC_APPLICATION_ID_HEADER, "id")
      .method(method, Entity.json("{\"f1\": \"abc\", \"f2\": \"xyz\"}"));

  // Test Request Records
  Assert.assertEquals(1, requestRecords.size());
  Record.Header payloadRecord = requestRecords.get(0).getHeader();
  Assert.assertEquals(method, payloadRecord.getAttribute(RestServiceReceiver.METHOD_HEADER));
  Assert.assertNull(payloadRecord.getAttribute(RestServiceReceiver.EMPTY_PAYLOAD_RECORD_HEADER_ATTR_NAME));
  Assert.assertEquals("abc", requestRecords.get(0).get("/f1").getValue());
  Assert.assertEquals("xyz", requestRecords.get(0).get("/f2").getValue());

  // Test Response from REST Service
  Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getStatus());
  ResponseEnvelope responseBody = response.readEntity(ResponseEnvelope.class);
  Assert.assertNotNull(responseBody);
  Assert.assertEquals(200, responseBody.getHttpStatusCode());
  Assert.assertNotNull(responseBody.getData());
  Assert.assertEquals(1, responseBody.getData().size());
  Assert.assertNotNull(responseBody.getError());
  Assert.assertEquals(0, responseBody.getError().size());
  Assert.assertNull(responseBody.getErrorMessage());
}
 
Example #14
Source File: TestRestServicePushSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private void testErrorResponse(
    String httpServerUrl,
    List<Record> requestRecords
) {
  Response response = ClientBuilder.newClient()
      .property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true)
      .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true)
      .target(httpServerUrl)
      .request()
      .header(Constants.X_SDC_APPLICATION_ID_HEADER, "id")
      .method(
          "POST",
          Entity.json("{\"f1\": \"abc\", \"f2\": \"xyz\", \"sendToError\": \"Sample Error message\"}")
      );

  // Test Request Records
  Assert.assertEquals(1, requestRecords.size());
  Record.Header payloadRecord = requestRecords.get(0).getHeader();
  Assert.assertEquals("POST", payloadRecord.getAttribute(RestServiceReceiver.METHOD_HEADER));
  Assert.assertNull(payloadRecord.getAttribute(RestServiceReceiver.EMPTY_PAYLOAD_RECORD_HEADER_ATTR_NAME));
  Assert.assertEquals("abc", requestRecords.get(0).get("/f1").getValue());
  Assert.assertEquals("xyz", requestRecords.get(0).get("/f2").getValue());

  // Test Response from REST Service
  Assert.assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, response.getStatus());
  ResponseEnvelope responseBody = response.readEntity(ResponseEnvelope.class);
  Assert.assertNotNull(responseBody);
  Assert.assertEquals(500, responseBody.getHttpStatusCode());
  Assert.assertNotNull(responseBody.getData());
  Assert.assertEquals(0, responseBody.getData().size());
  Assert.assertNotNull(responseBody.getError());
  Assert.assertEquals(1, responseBody.getError().size());
  Assert.assertNotNull(responseBody.getErrorMessage());
}
 
Example #15
Source File: TestRestServicePushSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private void testMultiStatusResponse(
    String httpServerUrl,
    List<Record> requestRecords
) {
  Response response = ClientBuilder.newClient()
      .property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true)
      .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true)
      .target(httpServerUrl)
      .request()
      .header(Constants.X_SDC_APPLICATION_ID_HEADER, "id")
      .method(
          "POST",
          Entity.json("{\"f1\": \"abc\", \"f2\": \"xyz\"}\n{\"f1\": \"abc\", \"f2\": \"xyz\", \"sendToError\": \"Sample Error message\"}")
      );

  // Test Request Records
  Assert.assertEquals(2, requestRecords.size());
  Record.Header payloadRecord = requestRecords.get(0).getHeader();
  Assert.assertEquals("POST", payloadRecord.getAttribute(RestServiceReceiver.METHOD_HEADER));
  Assert.assertNull(payloadRecord.getAttribute(RestServiceReceiver.EMPTY_PAYLOAD_RECORD_HEADER_ATTR_NAME));
  Assert.assertEquals("abc", requestRecords.get(0).get("/f1").getValue());
  Assert.assertEquals("xyz", requestRecords.get(0).get("/f2").getValue());

  // Test Response from REST Service
  Assert.assertEquals(207, response.getStatus());
  ResponseEnvelope responseBody = response.readEntity(ResponseEnvelope.class);
  Assert.assertNotNull(responseBody);
  Assert.assertEquals(207, responseBody.getHttpStatusCode());
  Assert.assertNotNull(responseBody.getData());
  Assert.assertEquals(1, responseBody.getData().size());
  Assert.assertNotNull(responseBody.getError());
  Assert.assertEquals(1, responseBody.getError().size());
  Assert.assertNotNull(responseBody.getErrorMessage());
}
 
Example #16
Source File: ClientSupport.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
private JerseyClientBuilder clientBuilder() {
    return new JerseyClientBuilder()
            .register(new JacksonFeature(support.getEnvironment().getObjectMapper()))
            .property(ClientProperties.CONNECT_TIMEOUT, 1000)
            .property(ClientProperties.READ_TIMEOUT, 5000)
            .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
}
 
Example #17
Source File: BaseTrellisHttpResourceTest.java    From trellis with Apache License 2.0 4 votes vote down vote up
@Override
protected void configureClient(final ClientConfig config) {
    config.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
}
 
Example #18
Source File: AbstractWebDAVTest.java    From trellis with Apache License 2.0 4 votes vote down vote up
@Override
protected void configureClient(final ClientConfig config) {
    config.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
}
 
Example #19
Source File: HttpPatchTest.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Override
protected void configureClient(final ClientConfig config) {
    config.getConfiguration().property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
}
 
Example #20
Source File: JsonApiResponseFilterTestBase.java    From crnk-framework with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setup() {
    ClientConfig config = new ClientConfig();
    config.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
    httpClient = ClientBuilder.newClient(config);
}
 
Example #21
Source File: TestRestServicePushSource.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@Test
public void testSendingRawResponse() throws Exception {
  HttpSourceConfigs httpConfigs = new HttpSourceConfigs();
  httpConfigs.appIds = ImmutableList.of(new CredentialValueBean("id"));
  httpConfigs.port = NetworkUtils.getRandomPort();
  httpConfigs.maxConcurrentRequests = 1;
  httpConfigs.tlsConfigBean.tlsEnabled = false;

  ResponseConfigBean responseConfigBean = new ResponseConfigBean();
  responseConfigBean.sendRawResponse = true;
  responseConfigBean.dataFormat = DataFormat.JSON;
  responseConfigBean.dataGeneratorFormatConfig = new DataGeneratorFormatConfig();

  RestServicePushSource source = new RestServicePushSource(
      httpConfigs,
      1,
      DataFormat.JSON,
      new DataParserFormatConfig(),
      responseConfigBean
  );

  final PushSourceRunner runner = new PushSourceRunner
      .Builder(HttpServerDPushSource.class, source)
      .addOutputLane("a")
      .build();
  runner.runInit();

  String httpServerUrl = "http://localhost:" + httpConfigs.getPort();

  try {
    final List<Record> records = new ArrayList<>();
    runner.runProduce(Collections.emptyMap(), 1, output -> {
      List<Record> outputRecords = output.getRecords().get("a");

      records.clear();
      records.addAll(outputRecords);

      runner.getSourceResponseSink().getResponseRecords().clear();
      records.forEach(record -> {
        Map<String, Field> rootField = new LinkedHashMap<>();
        rootField.put("text", Field.create("It's 80 degrees right now."));

        List<Field> attachmentsField = new ArrayList<>();
        Map<String, Field> attachmentField = new LinkedHashMap<>();
        attachmentField.put("text", Field.create("Partly cloudy today and tomorrow"));
        attachmentsField.add(Field.create(attachmentField));
        rootField.put("attachments", Field.create(attachmentsField));

        record.set(Field.create(rootField));
        Record.Header header = record.getHeader();
        header.setAttribute(RestServiceReceiver.STATUS_CODE_RECORD_HEADER_ATTR_NAME, "200");
        runner.getSourceResponseSink().addResponse(record);
      });
    });

    // wait for the HTTP server up and running
    RestServiceReceiverServer httpServer = (RestServiceReceiverServer) Whitebox.getInternalState(
        source,
        "server"
    );
    await().atMost(Duration.TEN_SECONDS).until(TestHttpServerPushSource.isServerRunning(httpServer));


    Response response = ClientBuilder.newClient()
        .property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true)
        .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true)
        .target(httpServerUrl)
        .request()
        .header(Constants.X_SDC_APPLICATION_ID_HEADER, "id")
        .get();

    // Test Raw Response without envelope from REST Service
    Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getStatus());
    Map<String, Object> responseBody = response.readEntity(Map.class);
    Assert.assertNotNull(responseBody);
    Assert.assertTrue(responseBody.containsKey("text"));
    Assert.assertEquals(responseBody.get("text"), "It's 80 degrees right now.");
    Assert.assertTrue(responseBody.containsKey("attachments"));
    runner.setStop();
  } catch (Exception e) {
    Assert.fail(e.getMessage());
  } finally {
    runner.runDestroy();
  }
}