Source:
<code>public void testSetHeader() throws Exception { int port = AvailablePortFinder.getNextAvailable(1025); HttpHeaderServer server = new HttpHeaderServer(port); <START> server.start(); <END> RuntimeEngine runtimeEngine = RemoteRuntimeEngineFactory.newRestBuilder() .addPassword("user").addUserName("pass") .addDeploymentId("deploymentId") .addUrl(new URL("http://localhost:" + port + "/" )) .build(); ProcessInstance procInst = runtimeEngine.getKieSession().startProcess("test"); assertNotNull( "Test server is not working..", procInst ); assertTrue( "No header, so no event types should be in the returned process instance!", procInst.getEventTypes() == null || procInst.getEventTypes().length == 0 ); String headerValueOne = String.valueOf(random.nextLong()); String headerValueTwo = String.valueOf(random.nextLong()); runtimeEngine = RemoteRuntimeEngineFactory.newRestBuilder() .addPassword("user").addUserName("pass") .addDeploymentId("deploymentId") .addUrl(new URL("http://localhost:" + port + "/" )) .addHeader(NOT_SENT_HEADER_NAME, String.valueOf(random.nextLong())) .clearHeaderFields() .addHeader(TEST_HEADER_NAME, headerValueOne) .addHeader(ANOTHER_TEST_HEADER_NAME, headerValueTwo) .build(); procInst = runtimeEngine.getKieSession().startProcess("test"); assertNotNull( "Test server is not working..", procInst ); assertEquals( "Number of event types (corresponds to test headers in request)", 2, procInst.getEventTypes().length ); for( String headerValue : procInst.getEventTypes() ) { assertTrue( "Unexpected header value: " + headerValue, headerValue.equals(headerValueOne) || headerValue.equals(headerValueTwo)); } }</code><technical_language>code in a @Before method. And, more importantly, server.stop()</technical_language>

Target:
public void testSetHeader() throws Exception { RuntimeEngine runtimeEngine = RemoteRuntimeEngineFactory.newRestBuilder() .addPassword("user").addUserName("pass") .addDeploymentId("deploymentId") .addUrl(new URL("http://localhost:" + port + "/" )) .build(); ProcessInstance procInst = runtimeEngine.getKieSession().startProcess("test"); assertNotNull( "Test server is not working..", procInst ); assertTrue( "No header, so no event types should be in the returned process instance!", procInst.getEventTypes() == null || procInst.getEventTypes().length == 0 ); String headerValueOne = String.valueOf(random.nextLong()); String headerValueTwo = String.valueOf(random.nextLong()); runtimeEngine = RemoteRuntimeEngineFactory.newRestBuilder() .addPassword("user").addUserName("pass") .addDeploymentId("deploymentId") .addUrl(new URL("http://localhost:" + port + "/" )) .addHeader(NOT_SENT_HEADER_NAME, String.valueOf(random.nextLong())) .clearHeaderFields() .addHeader(TEST_HEADER_NAME, headerValueOne) .addHeader(ANOTHER_TEST_HEADER_NAME, headerValueTwo) .build(); procInst = runtimeEngine.getKieSession().startProcess("test"); assertNotNull( "Test server is not working..", procInst ); assertEquals( "Number of event types (corresponds to test headers in request)", 2, procInst.getEventTypes().length ); for( String headerValue : procInst.getEventTypes() ) { assertTrue( "Unexpected header value: " + headerValue, headerValue.equals(headerValueOne) || headerValue.equals(headerValueTwo)); } }