@@ -177,7 +177,12 @@ private class EventDispatcher implements Runnable {
177
177
@ Override
178
178
public void run () {
179
179
try {
180
- HttpGet request = generateRequest (logEvent );
180
+ HttpRequestBase request ;
181
+ if (logEvent .getRequestMethod () == LogEvent .RequestMethod .GET ) {
182
+ request = generateGetRequest (logEvent );
183
+ } else {
184
+ request = generatePostRequest (logEvent );
185
+ }
181
186
httpClient .execute (request , EVENT_RESPONSE_HANDLER );
182
187
} catch (IOException e ) {
183
188
logger .error ("event dispatch failed" , e );
@@ -189,7 +194,7 @@ public void run() {
189
194
/**
190
195
* Helper method that generates the event request for the given {@link LogEvent}.
191
196
*/
192
- private HttpGet generateRequest (LogEvent event ) throws URISyntaxException {
197
+ private HttpGet generateGetRequest (LogEvent event ) throws URISyntaxException {
193
198
194
199
URIBuilder builder = new URIBuilder (event .getEndpointUrl ());
195
200
for (Map .Entry <String , String > param : event .getRequestParams ().entrySet ()) {
@@ -198,23 +203,30 @@ private HttpGet generateRequest(LogEvent event) throws URISyntaxException {
198
203
199
204
return new HttpGet (builder .build ());
200
205
}
201
- }
202
-
203
- /**
204
- * Handler for the event request that returns nothing (i.e., Void)
205
- */
206
- private static final class ProjectConfigResponseHandler implements ResponseHandler <Void > {
207
206
208
- @ Override
209
- public @ CheckForNull Void handleResponse (HttpResponse response ) throws IOException {
210
- int status = response .getStatusLine ().getStatusCode ();
211
- if (status >= 200 && status < 300 ) {
212
- // read the response, so we can close the connection
213
- response .getEntity ();
214
- return null ;
215
- } else {
216
- throw new ClientProtocolException ("unexpected response from event endpoint, status: " + status );
217
- }
207
+ private HttpPost generatePostRequest (LogEvent event ) throws UnsupportedEncodingException {
208
+ HttpPost post = new HttpPost (event .getEndpointUrl ());
209
+ post .setEntity (new StringEntity (event .getBody ()));
210
+ post .addHeader ("Content-Type" , "application/json" );
211
+ return post ;
218
212
}
219
213
}
220
- }
214
+
215
+ /**
216
+ * Handler for the event request that returns nothing (i.e., Void)
217
+ */
218
+ private static final class ProjectConfigResponseHandler implements ResponseHandler <Void > {
219
+
220
+ @ Override
221
+ public @ CheckForNull Void handleResponse (HttpResponse response ) throws IOException {
222
+ int status = response .getStatusLine ().getStatusCode ();
223
+ if (status >= 200 && status < 300 ) {
224
+ // read the response, so we can close the connection
225
+ response .getEntity ();
226
+ return null ;
227
+ } else {
228
+ throw new ClientProtocolException ("unexpected response from event endpoint, status: " + status );
229
+ }
230
+ }
231
+ }
232
+ }
0 commit comments