1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 *******************************************************************************/
22 package org.onap.dmaap.mr.client.impl;
24 import java.io.ByteArrayOutputStream;
25 import java.io.IOException;
26 import java.io.OutputStream;
27 import java.net.MalformedURLException;
29 import java.net.URISyntaxException;
30 import java.util.Collection;
31 import java.util.HashMap;
32 import java.util.LinkedList;
33 import java.util.List;
35 import java.util.Properties;
36 import java.util.concurrent.LinkedBlockingQueue;
37 import java.util.concurrent.ScheduledThreadPoolExecutor;
38 import java.util.concurrent.TimeUnit;
39 import java.util.zip.GZIPOutputStream;
41 import javax.ws.rs.core.MultivaluedMap;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
46 import org.apache.http.HttpException;
47 import org.apache.http.HttpStatus;
48 import org.json.JSONArray;
49 import org.json.JSONObject;
50 import org.json.JSONTokener;
52 import com.att.aft.dme2.api.DME2Client;
53 import com.att.aft.dme2.api.DME2Exception;
54 import org.onap.dmaap.mr.client.HostSelector;
55 import org.onap.dmaap.mr.client.MRBatchingPublisher;
56 import org.onap.dmaap.mr.client.response.MRPublisherResponse;
57 import org.onap.dmaap.mr.test.clients.ProtocolTypeConstants;
59 public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingPublisher {
60 private static final Logger logger = LoggerFactory.getLogger(MRSimplerBatchPublisher.class);
62 public static class Builder {
66 public Builder againstUrls(Collection<String> baseUrls) {
71 public Builder againstUrlsOrServiceName ( Collection<String> baseUrls, Collection<String> serviceName, String transportype )
74 fServiceName = serviceName;
75 fTransportype = transportype;
79 public Builder onTopic(String topic) {
84 public Builder batchTo(int maxBatchSize, long maxBatchAgeMs) {
85 fMaxBatchSize = maxBatchSize;
86 fMaxBatchAgeMs = maxBatchAgeMs;
90 public Builder compress(boolean compress) {
95 public Builder httpThreadTime(int threadOccuranceTime) {
96 this.threadOccuranceTime = threadOccuranceTime;
100 public Builder allowSelfSignedCertificates(boolean allowSelfSignedCerts) {
101 fAllowSelfSignedCerts = allowSelfSignedCerts;
105 public Builder withResponse(boolean withResponse) {
106 fWithResponse = withResponse;
110 public MRSimplerBatchPublisher build() {
111 if (!fWithResponse) {
113 return new MRSimplerBatchPublisher(fUrls, fTopic, fMaxBatchSize, fMaxBatchAgeMs, fCompress,
114 fAllowSelfSignedCerts, threadOccuranceTime);
115 } catch (MalformedURLException e) {
116 throw new IllegalArgumentException(e);
120 return new MRSimplerBatchPublisher(fUrls, fTopic, fMaxBatchSize, fMaxBatchAgeMs, fCompress,
121 fAllowSelfSignedCerts, fMaxBatchSize);
122 } catch (MalformedURLException e) {
123 throw new IllegalArgumentException(e);
129 private Collection<String> fUrls;
130 private Collection<String> fServiceName;
131 private String fTransportype;
132 private String fTopic;
133 private int fMaxBatchSize = 100;
134 private long fMaxBatchAgeMs = 1000;
135 private boolean fCompress = false;
136 private int threadOccuranceTime = 50;
137 private boolean fAllowSelfSignedCerts = false;
138 private boolean fWithResponse = false;
143 public int send(String partition, String msg) {
144 return send(new message(partition, msg));
148 public int send(String msg) {
149 return send(new message(null, msg));
153 public int send(message msg) {
154 final LinkedList<message> list = new LinkedList<>();
160 public synchronized int send(Collection<message> msgs) {
162 throw new IllegalStateException("The publisher was closed.");
165 for (message userMsg : msgs) {
166 fPending.add(new TimestampedMessage(userMsg));
168 return getPendingMessageCount();
172 public synchronized int getPendingMessageCount() {
173 return fPending.size();
177 public void close() {
179 final List<message> remains = close(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
180 if (remains.isEmpty()) {
181 getLog().warn("Closing publisher with {} messages unsent. Consider using MRBatchingPublisher.close( long timeout, TimeUnit timeoutUnits ) to recapture unsent messages on close.",
184 } catch (InterruptedException e) {
185 getLog().warn("Possible message loss. " + e.getMessage(), e);
186 Thread.currentThread().interrupt();
187 } catch (IOException e) {
188 getLog().warn("Possible message loss. " + e.getMessage(), e);
193 public List<message> close(long time, TimeUnit unit) throws IOException, InterruptedException {
194 synchronized (this) {
197 // stop the background sender
198 fExec.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
199 fExec.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
203 final long now = Clock.now();
204 final long waitInMs = TimeUnit.MILLISECONDS.convert(time, unit);
205 final long timeoutAtMs = now + waitInMs;
207 while (Clock.now() < timeoutAtMs && getPendingMessageCount() > 0) {
212 synchronized (this) {
213 final LinkedList<message> result = new LinkedList<>();
214 fPending.drainTo(result);
220 * Possibly send a batch to the MR server. This is called by the background
221 * thread and the close() method
225 private synchronized void send(boolean force) {
226 if ((force || shouldSendNow()) && !sendBatch()) {
227 getLog().warn("Send failed, " + fPending.size() + " message to send.");
229 // note the time for back-off
230 fDontSendUntilMs = sfWaitAfterError + Clock.now();
234 private synchronized boolean shouldSendNow() {
235 boolean shouldSend = false;
236 if (fPending.isEmpty()) {
237 final long nowMs = Clock.now();
239 shouldSend = (fPending.size() >= fMaxBatchSize);
241 final long sendAtMs = fPending.peek().timestamp + fMaxBatchAgeMs;
242 shouldSend = sendAtMs <= nowMs;
245 // however, wait after an error
246 shouldSend = shouldSend && nowMs >= fDontSendUntilMs;
252 * Method to parse published JSON Objects and Arrays
256 private JSONArray parseJSON() {
257 JSONArray jsonArray = new JSONArray();
258 for (TimestampedMessage m : fPending) {
259 JSONTokener jsonTokener = new JSONTokener(m.fMsg);
260 JSONObject jsonObject = null;
261 JSONArray tempjsonArray = null;
262 final char firstChar = jsonTokener.next();
264 if ('[' == firstChar) {
265 tempjsonArray = new JSONArray(jsonTokener);
266 if (null != tempjsonArray) {
267 for (int i = 0; i < tempjsonArray.length(); i++) {
268 jsonArray.put(tempjsonArray.getJSONObject(i));
272 jsonObject = new JSONObject(jsonTokener);
273 jsonArray.put(jsonObject);
280 private synchronized boolean sendBatch() {
281 // it's possible for this call to be made with an empty list. in this
282 // case, just return.
283 if (fPending.isEmpty()) {
287 final long nowMs = Clock.now();
289 if (this.fHostSelector != null) {
290 host = this.fHostSelector.selectBaseHost();
293 final String httpurl = MRConstants.makeUrl(host, fTopic, props.getProperty("Protocol"),
294 props.getProperty("partition"));
298 final ByteArrayOutputStream baseStream = new ByteArrayOutputStream();
299 OutputStream os = baseStream;
300 final String contentType = props.getProperty("contenttype");
301 if (contentType.equalsIgnoreCase("application/json")) {
302 JSONArray jsonArray = parseJSON();
303 os.write(jsonArray.toString().getBytes());
306 } else if (contentType.equalsIgnoreCase("text/plain")) {
307 for (TimestampedMessage m : fPending) {
308 os.write(m.fMsg.getBytes());
312 } else if (contentType.equalsIgnoreCase("application/cambria")
313 || (contentType.equalsIgnoreCase("application/cambria-zip"))) {
314 if (contentType.equalsIgnoreCase("application/cambria-zip")) {
315 os = new GZIPOutputStream(baseStream);
317 for (TimestampedMessage m : fPending) {
319 os.write(("" + m.fPartition.length()).getBytes());
321 os.write(("" + m.fMsg.length()).getBytes());
323 os.write(m.fPartition.getBytes());
324 os.write(m.fMsg.getBytes());
329 for (TimestampedMessage m : fPending) {
330 os.write(m.fMsg.getBytes());
336 final long startMs = Clock.now();
337 if (ProtocolTypeConstants.DME2.getValue().equalsIgnoreCase(protocolFlag)) {
343 .format("sending %d msgs to %s%s. Oldest: %d ms", fPending.size(), url, subContextPath,
344 nowMs - fPending.peek().timestamp));
345 sender.setPayload(os.toString());
346 String dmeResponse = sender.sendAndWait(5000L);
348 final String logLine = "MR reply ok (" + (Clock.now() - startMs) + " ms):" + dmeResponse;
349 getLog().info(logLine);
354 if (ProtocolTypeConstants.AUTH_KEY.getValue().equalsIgnoreCase(protocolFlag)) {
355 getLog().info("sending {} msgs to {}. Oldest: {} ms", fPending.size(), httpurl,
356 nowMs - fPending.peek().timestamp);
357 final JSONObject result =
358 postAuth(new PostAuthDataObject().setPath(httpurl).setData(baseStream.toByteArray())
359 .setContentType(contentType).setAuthKey(authKey).setAuthDate(authDate)
360 .setUsername(username).setPassword(password).setProtocolFlag(protocolFlag));
361 // Here we are checking for error response. If HTTP status
362 // code is not within the http success response code
363 // then we consider this as error and return false
364 if (result.getInt("status") < 200 || result.getInt("status") > 299) {
367 final String logLine = "MR reply ok (" + (Clock.now() - startMs) + " ms):" + result.toString();
368 getLog().info(logLine);
373 if (ProtocolTypeConstants.AAF_AUTH.getValue().equalsIgnoreCase(protocolFlag)) {
374 getLog().info("sending {} msgs to {}. Oldest: {} ms", fPending.size(), httpurl,
375 nowMs - fPending.peek().timestamp);
376 final JSONObject result = post(httpurl, baseStream.toByteArray(), contentType, username, password,
379 // Here we are checking for error response. If HTTP status
380 // code is not within the http success response code
381 // then we consider this as error and return false
382 if (result.getInt("status") < 200 || result.getInt("status") > 299) {
385 final String logLine = "MR reply ok (" + (Clock.now() - startMs) + " ms):" + result.toString();
386 getLog().info(logLine);
391 if (ProtocolTypeConstants.HTTPNOAUTH.getValue().equalsIgnoreCase(protocolFlag)) {
392 getLog().info("sending {} msgs to {}. Oldest: {} ms", fPending.size(), httpurl,
393 nowMs - fPending.peek().timestamp);
394 final JSONObject result = postNoAuth(httpurl, baseStream.toByteArray(), contentType);
396 // Here we are checking for error response. If HTTP status
397 // code is not within the http success response code
398 // then we consider this as error and return false
399 if (result.getInt("status") < 200 || result.getInt("status") > 299) {
402 final String logLine = "MR reply ok (" + (Clock.now() - startMs) + " ms):" + result.toString();
403 getLog().info(logLine);
407 } catch (Exception x) {
408 getLog().warn(x.getMessage(), x);
413 public synchronized MRPublisherResponse sendBatchWithResponse() {
414 // it's possible for this call to be made with an empty list. in this
415 // case, just return.
416 if (fPending.isEmpty()) {
417 pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_BAD_REQUEST));
418 pubResponse.setResponseMessage("No Messages to send");
422 final long nowMs = Clock.now();
424 host = this.fHostSelector.selectBaseHost();
426 final String httpurl = MRConstants.makeUrl(host, fTopic, props.getProperty("Protocol"),
427 props.getProperty("partition"));
428 OutputStream os = null;
431 final ByteArrayOutputStream baseStream = new ByteArrayOutputStream();
433 final String contentType = props.getProperty("contenttype");
434 if (contentType.equalsIgnoreCase("application/json")) {
435 JSONArray jsonArray = parseJSON();
436 os.write(jsonArray.toString().getBytes());
437 } else if (contentType.equalsIgnoreCase("text/plain")) {
438 for (TimestampedMessage m : fPending) {
439 os.write(m.fMsg.getBytes());
442 } else if (contentType.equalsIgnoreCase("application/cambria")
443 || (contentType.equalsIgnoreCase("application/cambria-zip"))) {
444 if (contentType.equalsIgnoreCase("application/cambria-zip")) {
445 os = new GZIPOutputStream(baseStream);
447 for (TimestampedMessage m : fPending) {
449 os.write(("" + m.fPartition.length()).getBytes());
451 os.write(("" + m.fMsg.length()).getBytes());
453 os.write(m.fPartition.getBytes());
454 os.write(m.fMsg.getBytes());
459 for (TimestampedMessage m : fPending) {
460 os.write(m.fMsg.getBytes());
465 final long startMs = Clock.now();
466 if (ProtocolTypeConstants.DME2.getValue().equalsIgnoreCase(protocolFlag)) {
472 getLog().info("sending {} msgs to {}{}. Oldest: {} ms", fPending.size(), url, subContextPath,
473 nowMs - fPending.peek().timestamp);
474 sender.setPayload(os.toString());
476 String dmeResponse = sender.sendAndWait(5000L);
478 pubResponse = createMRPublisherResponse(dmeResponse, pubResponse);
480 if (Integer.valueOf(pubResponse.getResponseCode()) < 200
481 || Integer.valueOf(pubResponse.getResponseCode()) > 299) {
485 final String logLine = String.valueOf((Clock.now() - startMs)) + dmeResponse.toString();
486 getLog().info(logLine);
489 } catch (DME2Exception x) {
490 getLog().warn(x.getMessage(), x);
491 pubResponse.setResponseCode(x.getErrorCode());
492 pubResponse.setResponseMessage(x.getErrorMessage());
493 } catch (URISyntaxException x) {
495 getLog().warn(x.getMessage(), x);
496 pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_BAD_REQUEST));
497 pubResponse.setResponseMessage(x.getMessage());
498 } catch (Exception x) {
500 pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR));
501 pubResponse.setResponseMessage(x.getMessage());
502 logger.error("exception: ", x);
509 if (ProtocolTypeConstants.AUTH_KEY.getValue().equalsIgnoreCase(protocolFlag)) {
510 getLog().info("sending {} msgs to {}. Oldest: {} ms", fPending.size(), httpurl,
511 nowMs - fPending.peek().timestamp);
512 final String result = postAuthwithResponse(httpurl, baseStream.toByteArray(), contentType, authKey,
513 authDate, username, password, protocolFlag);
514 // Here we are checking for error response. If HTTP status
515 // code is not within the http success response code
516 // then we consider this as error and return false
518 pubResponse = createMRPublisherResponse(result, pubResponse);
520 if (Integer.valueOf(pubResponse.getResponseCode()) < 200
521 || Integer.valueOf(pubResponse.getResponseCode()) > 299) {
526 final String logLine = "MR reply ok (" + (Clock.now() - startMs) + " ms):" + result.toString();
527 getLog().info(logLine);
532 if (ProtocolTypeConstants.AAF_AUTH.getValue().equalsIgnoreCase(protocolFlag)) {
533 getLog().info("sending {} msgs to {}. Oldest: {} ms", fPending.size(), httpurl,
534 nowMs - fPending.peek().timestamp);
535 final String result = postWithResponse(httpurl, baseStream.toByteArray(), contentType, username,
536 password, protocolFlag);
538 // Here we are checking for error response. If HTTP status
539 // code is not within the http success response code
540 // then we consider this as error and return false
541 pubResponse = createMRPublisherResponse(result, pubResponse);
543 if (Integer.valueOf(pubResponse.getResponseCode()) < 200
544 || Integer.valueOf(pubResponse.getResponseCode()) > 299) {
549 final String logLine = String.valueOf((Clock.now() - startMs));
550 getLog().info(logLine);
555 if (ProtocolTypeConstants.HTTPNOAUTH.getValue().equalsIgnoreCase(protocolFlag)) {
556 getLog().info("sending {} msgs to {}. Oldest: {} ms", fPending.size(), httpurl,
557 nowMs - fPending.peek().timestamp);
558 final String result = postNoAuthWithResponse(httpurl, baseStream.toByteArray(), contentType);
560 // Here we are checking for error response. If HTTP status
561 // code is not within the http success response code
562 // then we consider this as error and return false
563 pubResponse = createMRPublisherResponse(result, pubResponse);
565 if (Integer.valueOf(pubResponse.getResponseCode()) < 200
566 || Integer.valueOf(pubResponse.getResponseCode()) > 299) {
571 final String logLine = String.valueOf((Clock.now() - startMs));
572 getLog().info(logLine);
576 } catch (IllegalArgumentException | HttpException x) {
577 getLog().warn(x.getMessage(), x);
578 pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_BAD_REQUEST));
579 pubResponse.setResponseMessage(x.getMessage());
581 } catch (IOException x) {
582 getLog().warn(x.getMessage(), x);
583 pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR));
584 pubResponse.setResponseMessage(x.getMessage());
585 } catch (Exception x) {
586 getLog().warn(x.getMessage(), x);
588 pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR));
589 pubResponse.setResponseMessage(x.getMessage());
594 if (!fPending.isEmpty()) {
595 getLog().warn("Send failed, " + fPending.size() + " message to send.");
596 pubResponse.setPendingMsgs(fPending.size());
601 } catch (Exception x) {
602 getLog().warn(x.getMessage(), x);
603 pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR));
604 pubResponse.setResponseMessage("Error in closing Output Stream");
612 public MRPublisherResponse createMRPublisherResponse(String reply, MRPublisherResponse mrPubResponse) {
614 if (reply.isEmpty()) {
616 mrPubResponse.setResponseCode(String.valueOf(HttpStatus.SC_BAD_REQUEST));
617 mrPubResponse.setResponseMessage("Please verify the Producer properties");
618 } else if (reply.startsWith("{")) {
619 JSONObject jObject = new JSONObject(reply);
620 if (jObject.has("message") && jObject.has("status")) {
621 String message = jObject.getString("message");
622 if (null != message) {
623 mrPubResponse.setResponseMessage(message);
625 mrPubResponse.setResponseCode(Integer.toString(jObject.getInt("status")));
627 mrPubResponse.setResponseCode(String.valueOf(HttpStatus.SC_OK));
628 mrPubResponse.setResponseMessage(reply);
630 } else if (reply.startsWith("<")) {
631 String responseCode = getHTTPErrorResponseCode(reply);
632 if (responseCode.contains("403")) {
633 responseCode = "403";
635 mrPubResponse.setResponseCode(responseCode);
636 mrPubResponse.setResponseMessage(getHTTPErrorResponseMessage(reply));
639 return mrPubResponse;
642 private final String fTopic;
643 private final int fMaxBatchSize;
644 private final long fMaxBatchAgeMs;
645 private final boolean fCompress;
646 private int threadOccuranceTime;
647 private boolean fClosed;
648 private String username;
649 private String password;
653 private HostSelector fHostSelector = null;
655 private final LinkedBlockingQueue<TimestampedMessage> fPending;
656 private long fDontSendUntilMs;
657 private final ScheduledThreadPoolExecutor fExec;
659 private String latitude;
660 private String longitude;
661 private String version;
662 private String serviceName;
664 private String partner;
665 private String routeOffer;
666 private String subContextPath;
667 private String protocol;
668 private String methodType;
670 private String dmeuser;
671 private String dmepassword;
672 private String contentType;
673 private static final long sfWaitAfterError = 10000;
674 private HashMap<String, String> DMETimeOuts;
675 private DME2Client sender;
676 public String protocolFlag = ProtocolTypeConstants.DME2.getValue();
677 private String authKey;
678 private String authDate;
679 private String handlers;
680 private Properties props;
681 public static String routerFilePath;
682 protected static final Map<String, String> headers = new HashMap<String, String>();
683 public static MultivaluedMap<String, Object> headersMap;
685 private MRPublisherResponse pubResponse;
687 public MRPublisherResponse getPubResponse() {
691 public void setPubResponse(MRPublisherResponse pubResponse) {
692 this.pubResponse = pubResponse;
695 public static String getRouterFilePath() {
696 return routerFilePath;
699 public static void setRouterFilePath(String routerFilePath) {
700 MRSimplerBatchPublisher.routerFilePath = routerFilePath;
703 public Properties getProps() {
707 public void setProps(Properties props) {
711 public String getProtocolFlag() {
715 public void setProtocolFlag(String protocolFlag) {
716 this.protocolFlag = protocolFlag;
719 private void DME2Configue() throws Exception {
722 latitude = props.getProperty("Latitude");
723 longitude = props.getProperty("Longitude");
724 version = props.getProperty("Version");
725 serviceName = props.getProperty("ServiceName");
726 env = props.getProperty("Environment");
727 partner = props.getProperty("Partner");
728 routeOffer = props.getProperty("routeOffer");
729 subContextPath = props.getProperty("SubContextPath") + fTopic;
731 protocol = props.getProperty("Protocol");
732 methodType = props.getProperty("MethodType");
733 dmeuser = props.getProperty("username");
734 dmepassword = props.getProperty("password");
735 contentType = props.getProperty("contenttype");
736 handlers = props.getProperty("sessionstickinessrequired");
737 routerFilePath = props.getProperty("DME2preferredRouterFilePath");
740 * Changes to DME2Client url to use Partner for auto failover
741 * between data centers When Partner value is not provided use the
742 * routeOffer value for auto failover within a cluster
745 String partitionKey = props.getProperty("partition");
747 if (partner != null && !partner.isEmpty()) {
748 url = protocol + "://" + serviceName + "?version=" + version + "&envContext=" + env + "&partner="
750 if (partitionKey != null && !partitionKey.equalsIgnoreCase("")) {
751 url = url + "&partitionKey=" + partitionKey;
753 } else if (routeOffer != null && !routeOffer.isEmpty()) {
754 url = protocol + "://" + serviceName + "?version=" + version + "&envContext=" + env + "&routeoffer="
756 if (partitionKey != null && !partitionKey.equalsIgnoreCase("")) {
757 url = url + "&partitionKey=" + partitionKey;
761 DMETimeOuts = new HashMap<String, String>();
762 DMETimeOuts.put("AFT_DME2_EP_READ_TIMEOUT_MS", props.getProperty("AFT_DME2_EP_READ_TIMEOUT_MS"));
763 DMETimeOuts.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", props.getProperty("AFT_DME2_ROUNDTRIP_TIMEOUT_MS"));
764 DMETimeOuts.put("AFT_DME2_EP_CONN_TIMEOUT", props.getProperty("AFT_DME2_EP_CONN_TIMEOUT"));
765 DMETimeOuts.put("Content-Type", contentType);
766 System.setProperty("AFT_LATITUDE", latitude);
767 System.setProperty("AFT_LONGITUDE", longitude);
768 System.setProperty("AFT_ENVIRONMENT", props.getProperty("AFT_ENVIRONMENT"));
769 // System.setProperty("DME2.DEBUG", "true");
772 // System.setProperty("AFT_DME2_CLIENT_SSL_INCLUDE_PROTOCOLS",
774 System.setProperty("AFT_DME2_CLIENT_SSL_INCLUDE_PROTOCOLS", "TLSv1.1,TLSv1.2");
775 System.setProperty("AFT_DME2_CLIENT_IGNORE_SSL_CONFIG", "false");
776 System.setProperty("AFT_DME2_CLIENT_KEYSTORE_PASSWORD", "changeit");
780 sender = new DME2Client(new URI(url), 5000L);
782 sender.setAllowAllHttpReturnCodes(true);
783 sender.setMethod(methodType);
784 sender.setSubContext(subContextPath);
785 sender.setCredentials(dmeuser, dmepassword);
786 sender.setHeaders(DMETimeOuts);
787 if (handlers != null &&handlers.equalsIgnoreCase("yes")) {
788 sender.addHeader("AFT_DME2_EXCHANGE_REQUEST_HANDLERS",
789 props.getProperty("AFT_DME2_EXCHANGE_REQUEST_HANDLERS"));
790 sender.addHeader("AFT_DME2_EXCHANGE_REPLY_HANDLERS",
791 props.getProperty("AFT_DME2_EXCHANGE_REPLY_HANDLERS"));
792 sender.addHeader("AFT_DME2_REQ_TRACE_ON", props.getProperty("AFT_DME2_REQ_TRACE_ON"));
794 sender.addHeader("AFT_DME2_EXCHANGE_REPLY_HANDLERS", "com.att.nsa.mr.dme.client.HeaderReplyHandler");
796 } catch (DME2Exception x) {
797 getLog().warn(x.getMessage(), x);
798 throw new DME2Exception(x.getErrorCode(), x.getErrorMessage());
799 } catch (URISyntaxException x) {
801 getLog().warn(x.getMessage(), x);
802 throw new URISyntaxException(url, x.getMessage());
803 } catch (Exception x) {
805 getLog().warn(x.getMessage(), x);
806 throw new IllegalArgumentException(x.getMessage());
810 private MRSimplerBatchPublisher(Collection<String> hosts, String topic, int maxBatchSize, long maxBatchAgeMs,
811 boolean compress) throws MalformedURLException {
814 if (topic == null || topic.length() < 1) {
815 throw new IllegalArgumentException("A topic must be provided.");
818 fHostSelector = new HostSelector(hosts, null);
821 fMaxBatchSize = maxBatchSize;
822 fMaxBatchAgeMs = maxBatchAgeMs;
823 fCompress = compress;
825 fPending = new LinkedBlockingQueue<>();
826 fDontSendUntilMs = 0;
827 fExec = new ScheduledThreadPoolExecutor(1);
828 pubResponse = new MRPublisherResponse();
832 private MRSimplerBatchPublisher(Collection<String> hosts, String topic, int maxBatchSize, long maxBatchAgeMs,
833 boolean compress, boolean allowSelfSignedCerts, int httpThreadOccurnace) throws MalformedURLException {
836 if (topic == null || topic.length() < 1) {
837 throw new IllegalArgumentException("A topic must be provided.");
840 fHostSelector = new HostSelector(hosts, null);
843 fMaxBatchSize = maxBatchSize;
844 fMaxBatchAgeMs = maxBatchAgeMs;
845 fCompress = compress;
846 threadOccuranceTime = httpThreadOccurnace;
847 fPending = new LinkedBlockingQueue<>();
848 fDontSendUntilMs = 0;
849 fExec = new ScheduledThreadPoolExecutor(1);
850 fExec.scheduleAtFixedRate(new Runnable() {
855 }, 100, threadOccuranceTime, TimeUnit.MILLISECONDS);
856 pubResponse = new MRPublisherResponse();
859 private static class TimestampedMessage extends message {
860 public TimestampedMessage(message m) {
862 timestamp = Clock.now();
865 public final long timestamp;
868 public String getUsername() {
872 public void setUsername(String username) {
873 this.username = username;
876 public String getPassword() {
880 public void setPassword(String password) {
881 this.password = password;
884 public String getHost() {
888 public void setHost(String host) {
892 public String getContentType() {
896 public void setContentType(String contentType) {
897 this.contentType = contentType;
900 public String getAuthKey() {
904 public void setAuthKey(String authKey) {
905 this.authKey = authKey;
908 public String getAuthDate() {
912 public void setAuthDate(String authDate) {
913 this.authDate = authDate;