Skip to content

Commit 17c45dc

Browse files
committed
Removed dependecy on proofpoint client
1 parent f5021bf commit 17c45dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+349
-304
lines changed

pom.xml

+1-29
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.kairosdb</groupId>
77
<artifactId>client</artifactId>
8-
<version>3.0.0</version>
8+
<version>3.0.1</version>
99
<packaging>jar</packaging>
1010

1111

@@ -75,34 +75,6 @@
7575
<artifactId>jsr305</artifactId>
7676
<version>2.0.0</version>
7777
</dependency>
78-
<dependency>
79-
<groupId>com.proofpoint.platform</groupId>
80-
<artifactId>http-client</artifactId>
81-
<version>1.80</version>
82-
<exclusions>
83-
<exclusion>
84-
<groupId>org.slf4j</groupId>
85-
<artifactId>slf4j-jdk14</artifactId>
86-
</exclusion>
87-
<exclusion>
88-
<groupId>com.google.code.findbugs</groupId>
89-
<artifactId>annotations</artifactId>
90-
</exclusion>
91-
<exclusion>
92-
<groupId>org.eclipse.jetty</groupId>
93-
<artifactId>jetty-client</artifactId>
94-
</exclusion>
95-
<exclusion>
96-
<groupId>org.eclipse.jetty</groupId>
97-
<artifactId>jetty-http</artifactId>
98-
</exclusion>
99-
<exclusion>
100-
<groupId>org.apache.bval</groupId>
101-
<artifactId>bval-jsr</artifactId>
102-
</exclusion>
103-
</exclusions>
104-
</dependency>
105-
10678
<dependency>
10779
<groupId>org.apache.bval</groupId>
10880
<artifactId>bval-jsr303</artifactId>

src/main/java/org/kairosdb/client/Client.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.kairosdb.client;
22

3-
import com.proofpoint.http.client.UnexpectedResponseException;
3+
import org.kairosdb.client.response.UnexpectedResponseException;
44
import org.kairosdb.client.builder.*;
55
import org.kairosdb.client.response.JsonResponseHandler;
66
import org.kairosdb.client.response.QueryResponse;

src/main/java/org/kairosdb/client/DataPointTypeRegistry.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.util.HashMap;
44
import java.util.Map;
55

6-
import static com.google.common.base.Preconditions.checkArgument;
6+
import static org.kairosdb.client.util.Preconditions.checkArgument;
77

88
public class DataPointTypeRegistry
99
{

src/main/java/org/kairosdb/client/HttpClient.java

+35-162
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,13 @@
1515
*/
1616
package org.kairosdb.client;
1717

18-
import com.google.common.collect.ImmutableListMultimap;
19-
import com.google.common.collect.ListMultimap;
2018
import com.google.common.reflect.TypeToken;
21-
import com.proofpoint.http.client.BodySource;
22-
import com.proofpoint.http.client.HeaderName;
23-
import com.proofpoint.http.client.Request;
24-
import com.proofpoint.http.client.Response;
25-
import org.apache.http.Header;
26-
import org.apache.http.HttpEntity;
2719
import org.apache.http.HttpResponse;
2820
import org.apache.http.client.entity.EntityBuilder;
2921
import org.apache.http.client.methods.HttpDelete;
3022
import org.apache.http.client.methods.HttpGet;
3123
import org.apache.http.client.methods.HttpPost;
3224
import org.apache.http.client.methods.HttpUriRequest;
33-
import org.apache.http.entity.ContentType;
3425
import org.apache.http.impl.client.CloseableHttpClient;
3526
import org.apache.http.impl.client.HttpClientBuilder;
3627
import org.apache.http.impl.client.StandardHttpRequestRetryHandler;
@@ -39,24 +30,24 @@
3930
import org.kairosdb.client.response.JsonResponseHandler;
4031
import org.kairosdb.client.response.QueryResponse;
4132
import org.kairosdb.client.response.QueryTagResponse;
42-
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
33+
import org.kairosdb.client.response.ResponseHelper;
4334

4435
import java.io.IOException;
45-
import java.io.InputStream;
4636
import java.lang.reflect.Type;
37+
import java.net.ConnectException;
4738
import java.net.MalformedURLException;
4839
import java.net.URI;
4940
import java.net.URISyntaxException;
5041
import java.net.URL;
5142
import java.util.List;
5243
import java.util.Map;
5344

54-
import static com.proofpoint.http.client.ResponseHandlerUtils.propagate;
45+
import static java.util.Objects.requireNonNull;
5546
import static org.apache.http.HttpHeaders.*;
5647
import static org.apache.http.entity.ContentType.APPLICATION_JSON;
5748
import static org.apache.http.entity.ContentType.TEXT_PLAIN;
49+
import static org.kairosdb.client.util.Exceptions.propagate;
5850
import static org.kairosdb.client.util.Preconditions.checkNotNullOrEmpty;
59-
import static org.weakref.jmx.internal.guava.base.Preconditions.checkNotNull;
6051

6152
/**
6253
* HTTP implementation of a client.
@@ -105,7 +96,7 @@ public HttpClient(String url) throws MalformedURLException
10596
public HttpClient(HttpClientBuilder builder, String url) throws MalformedURLException
10697
{
10798
checkNotNullOrEmpty(url, "url cannot be null");
108-
checkNotNull(builder, "builder must not be null");
99+
requireNonNull(builder, "builder must not be null");
109100
this.url = url;
110101
new URL(url); // validate url
111102
client = builder.build();
@@ -115,7 +106,7 @@ public HttpClient(HttpClientBuilder builder, String url) throws MalformedURLExce
115106
public HttpClient(CloseableHttpClient client, String url) throws MalformedURLException
116107
{
117108
checkNotNullOrEmpty(url, "url cannot be null");
118-
checkNotNull(client, "client must not be null");
109+
requireNonNull(client, "client must not be null");
119110
this.url = url;
120111
new URL(url); // validate url
121112
this.client = client;
@@ -125,7 +116,7 @@ public HttpClient(CloseableHttpClient client, String url) throws MalformedURLExc
125116
public void registerCustomDataType(String groupType, Class dataPointClass)
126117
{
127118
checkNotNullOrEmpty(groupType, "groupType may not be null or empty");
128-
checkNotNull(dataPointClass, "dataPointClass may not be null");
119+
requireNonNull(dataPointClass, "dataPointClass may not be null");
129120
typeRegistry.registerCustomDataType(groupType, dataPointClass);
130121
}
131122

@@ -196,17 +187,17 @@ public int getStatusCheck()
196187
return queryData(PATH_CHECK, new JsonResponseHandler<Integer>()
197188
{
198189
@Override
199-
public Integer handleException(Request request, Exception e) throws RuntimeException
190+
public Integer handleException(HttpUriRequest request, Exception exception) throws RuntimeException
200191
{
201-
throw propagate(request, e);
192+
throw propagate(request, exception);
202193
}
203194

204195
@Override
205-
public Integer handle(Request request, Response response) throws RuntimeException
196+
public Integer handle(HttpUriRequest request, ResponseHelper response) throws RuntimeException
206197
{
207198
return response.getStatusCode();
208199
}
209-
}, ImmutableListMultimap.of());
200+
});
210201
}
211202

212203
@SuppressWarnings("unchecked")
@@ -274,40 +265,43 @@ private <T> T postData(String path, String json, JsonResponseHandler<T> response
274265

275266
private <T> T postData(String path, String json, JsonResponseHandler<T> responseHandler, boolean compressed)
276267
{
277-
Request request;
268+
HttpPost post = new HttpPost(createURI(path));
269+
270+
EntityBuilder entityBuilder = EntityBuilder.create()
271+
.setContentType(APPLICATION_JSON)
272+
.setText(json);
273+
278274
if (compressed)
279275
{
280-
request = new Request(createURI(path), "POST",
281-
ImmutableListMultimap.of(CONTENT_ENCODING, GZIP),
282-
new StringBodySource(json, TEXT_PLAIN, true));
276+
entityBuilder.gzipCompress();
277+
post.addHeader(CONTENT_ENCODING, GZIP);
283278
}
284279
else
285280
{
286-
request = new Request(createURI(path), "POST",
287-
ImmutableListMultimap.of(CONTENT_TYPE, APPLICATION_JSON.toString()),
288-
new StringBodySource(json, APPLICATION_JSON));
281+
post.addHeader(CONTENT_TYPE, APPLICATION_JSON.toString());
289282
}
290-
return execute(request, responseHandler);
291-
}
283+
post.setEntity(entityBuilder.build());
292284

293-
private <T> T queryData(String path, JsonResponseHandler<T> responseHandler)
294-
{
295-
return this.queryData(path, responseHandler, ImmutableListMultimap.of(ACCEPT, APPLICATION_JSON.toString(), ACCEPT_ENCODING, "gzip"));
285+
return execute(post, responseHandler);
296286
}
297287

298288
@SuppressWarnings("unchecked")
299-
private <T> T queryData(String path, JsonResponseHandler<T> responseHandler, ImmutableListMultimap headers)
289+
private <T> T queryData(String path, JsonResponseHandler<T> responseHandler)
300290
{
301-
Request request = new Request(createURI(path), "GET", headers, null);
302-
return execute(request, responseHandler);
291+
HttpGet get = new HttpGet(createURI(path));
292+
get.addHeader(ACCEPT, APPLICATION_JSON.toString());
293+
get.addHeader(ACCEPT_ENCODING, "gzip");
294+
295+
return execute(get, responseHandler);
303296
}
304297

305298
@SuppressWarnings("UnusedReturnValue")
306299
private <T> T delete(String path, JsonResponseHandler<T> responseHandler)
307300
{
308-
Request request = new Request(createURI(path), "DELETE",
309-
ImmutableListMultimap.of(ACCEPT, APPLICATION_JSON.toString()), null);
310-
return execute(request, responseHandler);
301+
HttpDelete delete = new HttpDelete(createURI(path));
302+
delete.addHeader(ACCEPT, APPLICATION_JSON.toString());
303+
304+
return execute(delete, responseHandler);
311305
}
312306

313307
private URI createURI(String path)
@@ -322,12 +316,12 @@ private URI createURI(String path)
322316
}
323317
}
324318

325-
private <T> T execute(Request request, JsonResponseHandler<T> responseHandler)
319+
private <T> T execute(HttpUriRequest request, JsonResponseHandler<T> responseHandler)
326320
{
327321
try
328322
{
329-
HttpResponse response = client.execute(convertToApacheRequest(request));
330-
return responseHandler.handle(request, new ApacheResponse(response));
323+
HttpResponse response = client.execute(request);
324+
return responseHandler.handle(request, new ResponseHelper(response));
331325
}
332326
catch (IOException e)
333327
{
@@ -341,127 +335,6 @@ public void close() throws IOException
341335
client.close();
342336
}
343337

344-
private static class ApacheResponse implements Response
345-
{
346-
private final HttpResponse response;
347-
348-
ApacheResponse(HttpResponse response)
349-
{
350-
this.response = response;
351-
}
352-
353-
@Override
354-
public int getStatusCode()
355-
{
356-
return response.getStatusLine().getStatusCode();
357-
}
358-
359-
@Override
360-
public String getStatusMessage()
361-
{
362-
return response.getStatusLine().getReasonPhrase();
363-
}
364-
365-
@Override
366-
public ListMultimap<HeaderName, String> getHeaders()
367-
{
368-
ImmutableListMultimap.Builder<HeaderName, String> builder = ImmutableListMultimap.builder();
369-
for (Header header : response.getAllHeaders())
370-
{
371-
builder.put(HeaderName.of(header.getName()), header.getValue());
372-
}
373-
return builder.build();
374-
}
375-
376-
@Override
377-
public long getBytesRead()
378-
{
379-
throw new NotImplementedException();
380-
}
381-
382-
@Override
383-
public InputStream getInputStream() throws IOException
384-
{
385-
if (response.getEntity() != null)
386-
return response.getEntity().getContent();
387-
return null;
388-
}
389-
}
390-
391-
private HttpUriRequest convertToApacheRequest(Request request)
392-
{
393-
HttpUriRequest apacheRequest;
394-
switch (request.getMethod())
395-
{
396-
case "POST":
397-
apacheRequest = new HttpPost(request.getUri());
398-
if (request.getBodySource() instanceof StringBodySource)
399-
{
400-
((HttpPost) apacheRequest).setEntity(((StringBodySource) request.getBodySource()).toHttpEntity());
401-
}
402-
else
403-
{
404-
throw new IllegalArgumentException("Request has unsupported BodySource type " + request.getBodySource().getClass().getName());
405-
}
406-
break;
407-
case "GET":
408-
apacheRequest = new HttpGet(request.getUri());
409-
break;
410-
case "DELETE":
411-
apacheRequest = new HttpDelete(request.getUri());
412-
break;
413-
default:
414-
throw new IllegalArgumentException("Request method is invalid must be one of POST, GET, or DELETE");
415-
}
416-
417-
for (Map.Entry<String, String> header : request.getHeaders().entries())
418-
{
419-
apacheRequest.addHeader(header.getKey(), header.getValue());
420-
}
421-
422-
return apacheRequest;
423-
}
424-
425-
private class StringBodySource implements BodySource
426-
{
427-
private final String body;
428-
private final ContentType contentType;
429-
private final boolean compressed;
430-
431-
StringBodySource(String body, ContentType contentType)
432-
{
433-
this.body = body;
434-
this.contentType = contentType;
435-
this.compressed = false;
436-
}
437-
438-
StringBodySource(String body, ContentType contentType, boolean compressed)
439-
{
440-
this.body = body;
441-
this.contentType = contentType;
442-
this.compressed = compressed;
443-
}
444-
445-
@Override
446-
public long getLength()
447-
{
448-
return body.length();
449-
}
450-
451-
HttpEntity toHttpEntity()
452-
{
453-
EntityBuilder builder = EntityBuilder.create()
454-
.setContentType(contentType)
455-
.setText(body);
456-
457-
if (compressed)
458-
{
459-
builder.gzipCompress();
460-
}
461-
462-
return builder.build();
463-
}
464-
}
465338

466339
@SuppressWarnings("unused")
467340
private class Results

0 commit comments

Comments
 (0)