0

I'm writing an app with http Akka and i want to POST json file, with csv inside and parse it. When I use enitityToString() I get string in single line instead of string with /n.

My http server:

 public static void createHttpServer(ApplicationRouter applicationRouter) {
        ActorSystem actorSystem = ApplicationProperties.actorSystem;
        Http http = Http.get(actorSystem);
        ActorMaterializer actorMaterializer = ActorMaterializer.create(actorSystem);

        Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = applicationRouter
                .createRoute()
                .flow(actorSystem, actorMaterializer);

        http.bindAndHandle(routeFlow, ConnectHttp.toHost(ApplicationProperties.httpHost,
                Integer.parseInt(ApplicationProperties.httpPort)), actorMaterializer);
    }

createRoute function:

public Route createRoute() {
        return route(
                post(() -> route(
                        panelDataUpload()
                )),
                get(() -> route(
                        path("health-check", this::healthCheck)
                ))
        );
    }

panelDataUpload function:

private Route panelDataUpload() {
        return path(PathMatchers
                        .segment("panel")
                        .slash("data"), () -> parameterList
                        (parameters -> entity(entityToString(), this::processRequestData))
        );
    }

And when I display String in processRequestData I get single line string without "/n" or something.

File I'm sending:

{
"table": "panelTest",
"panel-data": "header1,header2,header3
va0,va1,va2
v10,v11,v12
v20,v21,v22"
}

With curl:

curl -d @"import.txt" -H "Content-Type: application/json" -X POST http://localhost:8777/panel/data

Is there any way to get end of line marks from entity? What am i doing wrong?

staticint
  • 62
  • 5
  • Is `entityToString()` a method you've written? If so, what code is in it? What does the content look like before it's called? What happens if you add a new string for each line *id est*, change `"panel-data"` to an array of lines (`["header1,header2,header3","va0,va1,va2", ...]`) instead of trying to preserve line breaks? – Agi Hammerthief Aug 19 '19 at 14:34
  • Please include the code for `processRequestData`. The bug could be in there. – Robin Green Aug 19 '19 at 16:57
  • Possible duplicate of [Multiline strings in JSON](https://stackoverflow.com/questions/2392766/multiline-strings-in-json) – Robin Green Aug 19 '19 at 16:58

1 Answers1

0

The problem was with curl, -d flag skips newlines, --data-binary flag makes it works perfect. Thanks

staticint
  • 62
  • 5