NIFI-1342 Added default User-Agent in PostHttp

This closes #1021
This commit is contained in:
Pierre Villard 2016-09-14 17:59:17 +02:00 committed by Oleg Zhurakousky
parent 8a28395e9f
commit c1ad913598
2 changed files with 9 additions and 0 deletions

View File

@ -82,6 +82,7 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpCoreContext;
import org.apache.http.util.EntityUtils;
import org.apache.http.util.VersionInfo;
import org.apache.nifi.annotation.behavior.InputRequirement;
import org.apache.nifi.annotation.behavior.InputRequirement.Requirement;
import org.apache.nifi.annotation.behavior.SupportsBatching;
@ -194,6 +195,7 @@ public class PostHTTP extends AbstractProcessor {
.description("What to report as the User Agent when we connect to the remote server")
.required(false)
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
.defaultValue(VersionInfo.getUserAgent("Apache-HttpClient", "org.apache.http.client", HttpClientBuilder.class))
.build();
public static final PropertyDescriptor COMPRESSION_LEVEL = new PropertyDescriptor.Builder()
.name("Compression Level")

View File

@ -434,4 +434,11 @@ public class TestPostHTTP {
Assert.assertEquals(suppliedMimeType, lastPostHeaders.get(PostHTTP.CONTENT_TYPE_HEADER));
Assert.assertEquals("4700",lastPostHeaders.get("Content-Length"));
}
@Test
public void testDefaultUserAgent() throws Exception {
setup(null);
Assert.assertTrue(runner.getProcessContext().getProperty(PostHTTP.USER_AGENT).getValue().startsWith("Apache-HttpClient"));
}
}