question

newuser-5a7be815-d728-4572-82cf-d655a704b3ca avatar image

How to properly create a request header for a downchannel stream using OkHttp in Android

/* The user is signed in */
Log.d( "accessToken", "authorizeResult.toString(): " + authorizeResult.toString());
Log.d("accessToken", "accessToken: " + accessToken);

// OkHttpClient: establish a downchannel stream
OkHttpClient httpClient = new OkHttpClient();
OkHttpClient downChannelClient = httpClient.newBuilder() //httpClient Variable? Declare at beginning
        .connectTimeout(10, TimeUnit.SECONDS)
        .writeTimeout(10, TimeUnit.SECONDS)
        .readTimeout(30, TimeUnit.SECONDS)//.connectionPool(connectionPool)
        .build();

// OKHttp header creation.
final Request request = new Request.Builder()
        .url("https://alexa.na.gateway.devices.a2z.com")//endpoint url
        .get()
        .addHeader("method", "GET")
        .addHeader("scheme", "https")
        .addHeader("path", "/" + AVS_API_VERSION + "/directives")
        .addHeader("authorization", "Bearer " + accessToken)
        // A boundary term is required in the header of each event sent to AVS
        .addHeader("content-type", "multipart/form-data; boundary=" + BOUNDARY_TERM)
        .build();

Log.d("Request_header", request.toString());

Call currentCall = downChannelClient.newCall(request);

Response response = null;
try {
    response = currentCall.execute();
}
catch (IOException e) {
    Log.d("Response error", e.getMessage());
}

if (response != null && response.body() != null) {
    Log.d("Response_success", String.valueOf(response.isSuccessful()));
    Log.d("Response_str", response.toString());
}

We tried to follow the instructions here to establish a downchannel stream using a GET request: https://developer.amazon.com/en-US/docs/alexa/alexa-voice-service/manage-http2-connection.html#Maintaining%20an%20HTTP/2%20Connection

D/Request_header: Request{method=GET, url=https://alexa.na.gateway.devices.a2z.com/, headers=[method:GET, path:/v20160207/directives, authorization:Bearer <access_token_censored>, content-type:multipart/form-data; boundary=------------------------qM9tn4VZyj]}
D/Response_success: false
D/Response_str: Response{protocol=h2, code=404, message=, url=https://alexa.na.gateway.devices.a2z.com/}

But we keep getting a 404 code and a false response success. We're not sure whether or not our request is set up correctly.

Thanks

alexa voice serviceandroidresponsejavarequest
1596162533502.png (83.7 KiB)
1596162575679.png (15.8 KiB)
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

KirkC@Amazon avatar image
KirkC@Amazon answered

Hi. It looks like the following AVS SDK documentation might be of some assistance:
https://github.com/alexa/avs-device-sdk/blob/master/ACL/src/Transport/DownchannelHandler.cpp#L49

If more detailed guidance is needed though, I'd recommend reaching out to our AVS SDK team directly by using the "Issues" tab of the "avs-device-sdk" repository on GitHub:
https://github.com/alexa/avs-device-sdk/issues

10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.