Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Content-Type Headers are returned #1147

Closed
ahassany opened this issue Jun 18, 2013 · 2 comments
Closed

Multiple Content-Type Headers are returned #1147

ahassany opened this issue Jun 18, 2013 · 2 comments

Comments

@ahassany
Copy link

I'm trying to hava async HTTP call within a suspended GET request. In this code I dynamically set resumeOnBroadcast based on the client's HTTP request header. However, I found out in the HTTP response two "Content-Type: application/json" are returned. Is that a bug? (I'm using 1.1.0.RC4)

This is a code snippet of what I'm trying to do

@GET
@Produces(MediaType.APPLICATION_JSON)
public SuspendResponse<String> subscribe(@Context HttpHeaders headers) {

    // Check if the client want to keep the connection open for HTTP
    // streaming
    boolean resumeOnBroadcast = false;

    if (headers.getRequestHeader("Connection") != null
            && headers.getRequestHeader("Connection")
                    .contains("keep-alive")) {
        resumeOnBroadcast = false;
    } else {
        resumeOnBroadcast = true;
    }

    return new SuspendResponse.SuspendResponseBuilder<String>()
            .broadcaster(topic).resumeOnBroadcast(resumeOnBroadcast)
            .outputComments(true)
            .addListener(new WebSocketEventListener() {

                public void onBroadcast(AtmosphereResourceEvent arg0) {

                }

                public void onDisconnect(AtmosphereResourceEvent arg0) {

                }

                public void onPreSuspend(AtmosphereResourceEvent arg0) {

                }

                public void onResume(AtmosphereResourceEvent arg0) {

                }

                public void onSuspend(AtmosphereResourceEvent arg0) {
                    // Enabling this line only will create the same problem
                    // topic.broadcast("{\"message\": \"broadcasted message\"}");
                    AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
                    try {
                        Future<Response> f = asyncHttpClient.prepareGet(
                                "http://www.ning.com/").execute();
                        f.get();
                        topic.broadcast("{\"message\": \"broadcasted message\"}");

                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } catch (ExecutionException e) {
                        e.printStackTrace();
                    }
                    asyncHttpClient.close();
                }

                public void onThrowable(AtmosphereResourceEvent arg0) {

                }

                public void onClose(WebSocketEvent arg0) {

                }

                public void onConnect(WebSocketEvent arg0) {

                }

                public void onControl(WebSocketEvent arg0) {

                }

                public void onDisconnect(WebSocketEvent arg0) {

                }

                public void onHandshake(WebSocketEvent arg0) {

                }

                public void onMessage(WebSocketEvent arg0) {

                }
            }).build();

}

And here how I tested it using cURL:

curl -H "Connection: close" -v -N -XGET "http://localhost:8080/pubsub/topic1"
* About to connect() to localhost port 8080 (#0)
*   Trying ::1... connected
* Connected to localhost (::1) port 8080 (#0)
> GET /pubsub/topic1 HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8x zlib/1.2.5
> Host: localhost:8080
> Accept: */*
> Connection: close
>
< HTTP/1.1 200 OK
< X-Atmosphere-tracking-id: f2f78148-49ae-4b08-8a9d-22aee3797eee
< Expires: -1
< Cache-Control: no-store, no-cache, must-revalidate
< Pragma: no-cache
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Credentials: true
< Content-Type: application/json
< Content-Type: application/json
< Connection: close
< Server: Jetty(8.1.11.v20130520)
<
{"message": "broadcasted message"}* Closing connection #0
@jfarcand
Copy link
Member

Is that causing an issue? It has been like that for awhile when Jersey is used.

@jfarcand
Copy link
Member

Closing as will not fix. Please re-open in case it is causing issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants