Ballerina echoservice example throws an error

303 Views Asked by At

I've just installed Ballerina version 0.8.0 on Windows. Following the tutorial I tried the echoservice example. Launching the command from the \ballerina-0.8.0\samples\echoService folder

ballerina run service echoService.bal

I received this response

error in ballerina program: value
     at echo(echoService.bal:6)
     at echo(echoService.bal:3)

where the line 6 is

resource echo (message m) {

The example helloworldservice runs propertly.

What's wrong?

Thanks in advance

Gianni

UPDATED 2017-02-26: This is the code I'm executing from ballerina-0.8.0/samples/echoService folder. I'm running it from Git Bash, but it's the same from Command Prompt.

import ballerina.net.http;
@http:BasePath ("/echo")
service echo {

    @http:POST
    resource echo (message m) {
        http:convertToResponse(m);
        reply m;

    }

}

I launch this command

../../bin/ballerina.bat run service echoService.bal

The console shows the same error.

I'm calling the service using Fiddler...

POST http://localhost:9090/echo HTTP/1.1
User-Agent: Fiddler
Host: localhost:9090
Content-Length: 3

sss

...and I receive this response

HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Content-Length: 33
Content-Type: text/plain

error in ballerina program: value
4

There are 4 best solutions below

0
On BEST ANSWER

This is because you are trying to invoke HTTP POST method without Content-Type. Can you check setting "Content-Type" header to "application/json"

0
On

You should post your entire program. I was able to successfully get it to run as shown on the ballerinalang.org home page.

2
On

This is the echo sample which worked for me.

import ballerina.net.http;
@http:BasePath("/echo")
service echo {
    @http:POST
    resource echo(message m) {
        http:convertToResponse(m);
        reply m;    
    }
}

You can run it by

ballerina run service path/to/echo.bal

from the bin directory, or can do the same via ballerina composer as well.

0
On

I could reproduce this issue. I used Advanced REST client app in Chrome. I could resolve the error when I set the Content-Type header as follows.

Content-Type: application/x-www-form-urlencoded