Can't get Promise to work in Confluence Data Center - Stack Overflow

admin2025-04-16  5

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/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.

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.

Share Improve this question edited Feb 2 at 15:45 marc_s 756k184 gold badges1.4k silver badges1.5k bronze badges asked Feb 2 at 12:18 Matti KiviharjuMatti Kiviharju 4594 gold badges8 silver badges21 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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"));
转载请注明原文地址:http://anycun.com/QandA/1744801548a87811.html