ClientConfig cc = new DefaultClientConfig();
if(Config.getStringProperty("TRUSTSTORE_PATH") != null && !Config.getStringProperty("TRUSTSTORE_PATH").trim().equals("")) {
cc.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(tFactory.getHostnameVerifier(), tFactory.getSSLContext()));
}
Client client = Client.create(cc);
//Updating audit table
currentStatusHistory = pubAuditAPI.getPublishAuditStatus(config.getId()).getStatusPojo();
currentStatusHistory.setPublishStart(new Date());
pubAuditAPI.updatePublishAuditStatus(config.getId(), PublishAuditStatus.Status.SENDING_TO_ENDPOINTS, currentStatusHistory);
//Increment numTries
currentStatusHistory.addNumTries();
// boolean hasError = false;
int errorCounter = 0;
for (Environment environment : environments) {
List<PublishingEndPoint> endpoints = APILocator.getPublisherEndPointAPI().findSendingEndPointsByEnvironment(environment.getId());
boolean failedEnvironment = false;
if(!environment.getPushToAll()) {
Collections.shuffle(endpoints);
if(!endpoints.isEmpty())
endpoints = endpoints.subList(0, 1);
}
for (PublishingEndPoint endpoint : endpoints) {
EndpointDetail detail = new EndpointDetail();
try {
FormDataMultiPart form = new FormDataMultiPart();
form.field("AUTH_TOKEN",
retriveKeyString(
PublicEncryptionFactory.decryptString(endpoint.getAuthKey().toString())));
form.field("GROUP_ID", UtilMethods.isSet(endpoint.getGroupId()) ? endpoint.getGroupId() : endpoint.getId());
Bundle b=APILocator.getBundleAPI().getBundleById(config.getId());
form.field("BUNDLE_NAME", b.getName());
form.field("ENDPOINT_ID", endpoint.getId());
form.bodyPart(new FileDataBodyPart("bundle", bundle, MediaType.MULTIPART_FORM_DATA_TYPE));
//Sending bundle to endpoint
WebResource resource = client.resource(endpoint.toURL()+"/api/bundlePublisher/publish");
ClientResponse response =
resource.type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);