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

Unhandled exception when retrieving already built incompatible payload #1600

Closed
chamil321 opened this issue Jul 2, 2021 · 1 comment · Fixed by ballerina-platform/module-ballerina-http#513
Labels
module/http Team/PCM Protocol connector packages related issues Type/Bug

Comments

@chamil321
Copy link
Contributor

chamil321 commented Jul 2, 2021

Description:
Execptions thrown from https://github.com/ballerina-platform/module-ballerina-http/blob/d5e06bea9b722923ac033491fffa711f70b28f7e/http-native/src/main/java/org/ballerinalang/net/http/nativeimpl/ExternHttpDataSourceBuilder.java#L92 are catched and processed with NULL balFuture

Steps to reproduce:

import ballerina/http;

service / on new http:Listener(8090) {
    resource function get stats/[string country]() returns json | error {
        http:Client diseaseEndpoint = check new ("http://api.worldbank.org/v2");
        string  path = string `/country/${country}/indicator/SP.POP.TOTL`;
        http:Response resp = check diseaseEndpoint -> get(path);
        return resp.getJsonPayload();
    }
}
error: java.lang.NullPointerException
        at ballerina.http.1_1_0-alpha8:externGetJson(http_commons.bal:340)
           ballerina.http.1_1_0-alpha8.Response:getJsonPayload(http_response.bal:205)
           chamil.covid19Package.0_1_0.$anonType$_0:$get$stats$*(main.bal:29)

Client

GET http://localhost:8090/stats/LK

Affected Versions:
beta1

OS, DB, other environment details and versions:

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

@chamil321 chamil321 added Type/Bug Priority/Blocker module/http Team/PCM Protocol connector packages related issues labels Jul 2, 2021
@chamil321 chamil321 added this to the Swan Lake Beta2 milestone Jul 2, 2021
@chamil321
Copy link
Contributor Author

chamil321 commented Jul 4, 2021

Observed this error with caching client. Caching client build the payload with as blob first. The program retrieves the payload as json. But the payload type is xml. The thrown error by the json parser is caught but processed with null balfuture.

Can be reproduced with

service / on inResponseCachedPayloadListener {
    resource function get checkJson() returns json|error {
        http:Client diseaseEndpoint = check new ("http://localhost:" + inResponseCachedPayloadTestBEPort.toString());
        http:Response resp = check diseaseEndpoint -> get("/getXml");
        byte[] b = check resp.getBinaryPayload(); // represents cache behaviour
        return resp.getJsonPayload();
    }
}

service / on inResponseCachedPayloadBEListener {
    resource function get getXml(http:Caller caller) {
        http:Response response = new;
        xml xmlStr = xml `<name>Ballerina</name>`;
        response.setXmlPayload(xmlStr);
        error? result = caller->respond(response);
    }
}

or

service / on inResponseCachedPayloadListener {
    resource function get checkJson() returns json|error {
        http:Client diseaseEndpoint = check new ("http://localhost:" + inResponseCachedPayloadTestBEPort.toString());
        http:Response resp = check diseaseEndpoint -> get("/getXml");
        return resp.getJsonPayload();
    }
}

service / on inResponseCachedPayloadBEListener {
    resource function get getXml(http:Caller caller) {
        http:Response response = new;
        xml xmlStr = xml `<name>Ballerina</name>`;
        response.setXmlPayload(xmlStr);
        // enables cache behaviour
        response.setHeader("Cache-Control", "public, max-age=14400");
        response.setHeader("etag", "W/\"25f-VB/B7cwRxpkTFPnufB0QcTCzHUE\"");
        error? result = caller->respond(response);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/http Team/PCM Protocol connector packages related issues Type/Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant