confluence

Can't get Promise to work in Confluence Data Center


How to fix bug? I get ClassNotFound in atlassian-confluence.log file:

import com.atlassian.httpclient.api.HttpClient;
import com.atlassian.httpclient.api.Request;
import com.atlassian.util.concurrent.Promise;
import com.atlassian.httpclient.api.Response;
import com.atlassian.httpclient.api.ResponsePromise;

private Promise<Response> sendPusherEvent(String channel, String event, String message) {
    long timestamp = System.currentTimeMillis() / 1000;
    String body = "{\"name\":\"" + event + "\", \"channel\":\"" + channel + "\", \"data\":\"" + message + "\"}";
    String signature = generateSignature(body, timestamp);

    String url = "https://" + cluster + ".pusher.com/apps/" + appId + "/events"
            + "?auth_key=" + key + "&auth_timestamp=" + timestamp + "&auth_version=1.0&auth_signature=" + signature;

    // Create and execute request correctly
    ResponsePromise requestBuilder = httpClient.newRequest(url, "application/json", body).post();

    // FIX: Convert ResponsePromise to Promise<Response>
    return requestBuilder;
}

I just want to use Pusher but I can't use it's official Java API in Confluence 9, because Atlassian is made 3rd APIs to not work.


Solution

  • Problem is now solved with Atlassian own Event API:

     import com.atlassian.event.api.EventPublisher;
        
     public class UserTypingServlet extends HttpServlet {
        private final EventPublisher eventPublisher;
    
        @Inject
        public UserTypingServlet(ActiveObjects activeObjects, @ComponentImport HttpClient httpClient, 
            @ComponentImport EventPublisher eventPublisher) {
            this.activeObjects = activeObjects;
            this.httpClient = httpClient;
            this.eventPublisher = eventPublisher;
        }
    
        // Fire Confluence Event
        eventPublisher.publish(new UserTypingEvent(this, username, isTyping, "atlassian_" + channel + "_chat"));