Upload data through restful service - rest

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.

Related

Does Syncfusion Dashboard web data source support POST http methods?

Does Syncfusion Dashboard web data source support POST http methods?
If yes, so how set it up?
Thanks!
HTTP Post requests additional data from client to server in the message body, where message body will be like JSON, XML, TEXT etc. This may result in the creation of a new resource or the updates of existing resources or both. In contrast, HTTP Get requests include all required data in the URL. So we support HTTP Get method since POST method is not valid use case.
Regards,
Umapathy S.

Restygwt download byte[]

I have only an array of byte on the client side.
Another server send me JSON
{
report - byte[]
}
I am looking for ways to save byte [] in browser
Send them to server or I can download from client side.
I can not find any solution at all.
So my question "Is it possible to save with restygwt byte [] an how???"
It is not possible to save the file directly from Resty.
https://github.com/resty-gwt/resty-gwt/issues/341
The most common workarounds to download files using AJAX are not using AJAX at all.
You can simply change the URL (using window.location) or (using javascript) create or;
create a form (using JS) and post that form.
In my projects, I simple create a URL to my REST endpoint attaching any query parameters needed and use it as the href to a link.
For instance, if your RestyGwt endpoint points to /entity/1/bytes
just do
new Anchor("Download", "/entity/1/bytes");
your endpoint must produce a downloadable file type say:
#Produces("text/txt")

Get non file body from multipart/form-data using AWS API Gateway and Lambda

I am trying to get the form data from a multipart/form-data POST to my ASW Lambda web service via API Gateway.
The HTTP POST has Content-Type "multipart/form-data" and body that is URL encoded. File data is also sent in this post (hence the multipart, I guess).
The web service needs to integrate with a thirdparty service, so changing the format of the POST isn't really an option.
I have seen this thread talking about converting the URL encoded data to JSON object for use in Lambda, but this doesn't do the trick.
I have also tried setting the Integration Request -> Mapping Templates for content type multipart/form-data to Input passthrough. This didn't help either.
I did come across another question about uploading a file using multipart/form-data, but since I'm not interested in the file, just the body, that answer didn't help.
Below find screenshot (sorry) of the captured post via runscope.
If the goal is to use Lambda, you'll need to pass valid JSON to the function. Currently there isn't a way to JSON-ify data inside Api Gateway that comes in as non-JSON data.
Our short term fix (on our backlog) is to provide a variable in the mapping templates to grab the raw input of the request. That way you could do a simple JSON conversion using a template like:
{
"body" : "$input.body"
}
or something like that.
Check out the mapping template reference for more info: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
Edit 4/7 - feature has been released as $input.body

CXF Restful web service with generic payload

Is there a way in CXF to implement a Restful webservice which will accept different xml requests using one Web service method?
e.g. Can one create a Restful endpoint to accept this type of XML through one web service method?
<Data>
<Book>BN1</Book>
</Data>
& this too using same web service method?
<Data>
<Disk>DN1</Disk>
</Data>
I think this post: Apache CXF: Consume XML POST payload... shows a good example of how to declare a CXF REST service as receiving POST XML data.
For your example of handling different XML content, instead of 'Bean' in the above you'd have an #XmlRootElement that's the Data, with a child that's a #XmlAnyElement.
Ok so I am using this for generic XML.
public interface Callback {
#POST
#Path("/submit")
#Consumes("text/xml")
#Produces("application/xml")
public Response submit(String incomingXML);
}
Basically I am getting whole xml as a string in my method body, As CXF is not parsing it, it can remain generic.

Backbone Request Payload

Hi,
I am a newbie to Backbone, My Rest Server Components Accept Only XML Requests, can Anybody show an example how do i send a xml to a rest api put request.
Backbone uses JSON by default, so to use XML you need to overwrite Backbone.sync. Take a look at this answer: How to override Backbone.sync?