简体   繁体   中英

Streaming a JSON document to a Rest web service with java

I've seen examples where you can use a http://docs.oracle.com/javaee/6/api/javax/ws/rs/core/StreamingOutput.html from a Rest api so that the restful respones can be a Json stream. This makes it so you can start processing JSON tokens as they come in instead of waiting until the whole thing is there.

Now i'm interested in the other way.

The flow:

  1. The client opens a stream to a Rest api endpoint.
  2. The client starts sending data through the stream.
  3. The server while reading the stream can start working on the data before client is fully done sending it.

Does such a feature exist?

The only idea I have come up with is to have the client stream to a local file then send the server a URL to that file to stream from.

maybe you can use java.nio(or Socket) to create a server and clients.

client read data and send the data(json?string?) to server one by one(or any other definite quantity)

when the data received by server then server start to process it. and client continue to read remaining data and continue to send it to server.

here are some example: https://examples.javacodegeeks.com/core-java/nio/java-nio-socket-example/

my english is poor. Is this what you want to know? i wish it can help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM