I开发者_运维问答 want to write a RESTful web service for client to upload data. The data format is JSON
But I don't know much about it,can you give some sample code in JAVA? include the code of service and client that could demonstrate me the whole process of data uploading.
A good place to start is the Jackson Tutorials. Then look at either Jersey's JSON Support or RESTeasy's JSON Support depending on which framework you happen to be using. Data uploading is a open-ended topic since there are a number of different ways that it can be accomplished. If you POST JSON directly to the service then you can use JAXRS annotations like:
@Path("/myservice")
public class MyService {
@POST @Consumes("application/mytype+json")
public Response processPostRequest (JsonBeanType postData) {
...
}
}
The processPostRequest
method will be invoked whenever a client POSTs data that includes the Content-Type: application/mytype+json
HTTP header to the /myservice
resource.
Another way to upload data is to send it using an HTML form. There are a bunch of examples of processing HTML forms in Java. The SO question How can I handle multipart form data post requests in my Java servlet should start you off in the right direction.
精彩评论