On 07/11/2012 04:30 AM, Sergey Beryozkin wrote:
Hi
On 11/07/12 07:00, ramesh wrote:
These are the annotations I use in my interface
@Path("/for")
@Produces("application/json")
@Consumes("application/json")
public interface CustomerService {
@POST
@Produces("application/json")
@Consumes("application/json")
@CrossOriginResourceSharing(
allowAllOrigins = true,
allowHeaders = {
"content-type:application/json"
},
exposeHeaders = {
"content-type:application/json"
}
)
Response addMember(Customer customer);
My POST request from Javascript client is getting preflighted and
Http-Method turns to OPTIONS and Content-Type to blank.
What are the right configurations to avoid preflight and make a
successful POST with content-type: application/json
How you capture the request from the browser ? I'd like to see what it
actually POSTs
thanks, Sergey
Appreciate any help
regards
Ramesh
Hi Sergey,
This is a simple XmlHttpRequest with Google Closure.
var data = { "Customer":{"id":"9" , "city":"Sau Paulo",
"country":"Brazil" , "email":"[email protected]"}};
var xhr = new goog.net.XhrIo();
xhr.setWithCredentials(true);
xhr.headers.set('Content-Type','application/jsonrequest');
xhr.send('http://localhost:8181/cxf/hi/for','POST',
goog.json.serialize(data),xhr.headers);
I also used Firefox extension RESTClient and it does POST to the server
perfectly.
Not sure if you wanted to see the client request or how it handles request.
this is from the implementation :
public Response addCustomer(Customer customer){
String rId = customer.getId();
String cCity = customer.getCity();
String cCount = customer.getCountry();
String cEmail = customer.getEmail();
reqDAO.insertMulti(rId, cCity, cCount, cEmail);
return Response.ok(customer).build();
}
regards,
Ramesh