package org.camunda.bpm.extension.cloud.broadcaster;

import org.camunda.bpm.engine.delegate.DelegateTask;
import org.camunda.bpm.engine.impl.util.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;

/**
 * Client for transmitting task events to the task event service.
 */
@Component
public class EventServiceClient {

  public static final Logger LOGGER = LoggerFactory.getLogger(EventServiceClient.class);

  @Value(value = "${server.port}")
  private int port;


  /**
   * Event type.
   */
  public static enum EventType {
    CREATED, COMPLETED, DELETED
  }

  @Value(value = "${eventServiceBaseUrl}")
  private String baseUrl;

  @Value(value = "${eureka.instance.hostname}")
  private String hostname;


  /**
   * Sends the task event to the event service.
   *
   * @param task
   *          task delegate.
   * @param eventType
   *          event type.
   * @param formKey
   *          form key of the task.
   */
  public void broadcastEvent(final DelegateTask task, final EventType eventType, final String formKey) {
    final String url = baseUrl + "/task";
    final String engineUrl = String.format("http://%s:%d", hostname, port);
    BroadcastEventCommand command = new BroadcastEventCommand(url, fromTask(task, eventType, formKey, hostname));

    LOGGER.info("sending {}",command);
    final String result = command.execute();

    LOGGER.info("Result: {}", result);
  }

  /**
   * Creates a JSON representation of the task.
   *
   * @param task
   *          task delegate
   * @return HTTP entity to be sent to the event service.
   */
  public static HttpEntity<String> fromTask(final DelegateTask task, final EventType eventType, final String formKey, final String engineId) {
    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);

    return new HttpEntity<String>(new JSONObject() //
        .put("taskDefinitionKey", task.getTaskDefinitionKey()) //
        .put("taskId", task.getId()) //
        .put("formKey", formKey) //
        .put("engineId", engineId) //
        .put("eventType", eventType.name()) //
        .toString(), headers);
  }

}

@@ -915,28 +915,27 @@
  %22$%7B
-eureka.instance.host
+spring.application.
 name
@@ -955,21 +955,20 @@
  String 
-hostn
+appN
 ame;%0A%0A%0A 
@@ -1328,16 +1328,17 @@
 /task%22;%0A
+%0A
     fina
@@ -1343,78 +1343,8 @@
 nal 
-String engineUrl = String.format(%22http://%25s:%25d%22, hostname, port);%0A    
 Broa
@@ -1441,13 +1441,12 @@
 ey, 
-hostn
+appN
 ame)

Use correct ID for eureka