How to consume a multipart form-date method with void method

0
How to consume a multipart / form-data method of a webservice done in java, by ajax or jquery?

Below I leave the method as follows:

JAVA:

@POST
    @Path("/aprovarCompra")
    @Consumes("multipart/form-data")
    public void aprovarCompra(@FormParam("nrCompra") Long nrCompra,
            @FormParam("usuario") String usuario) {
//aqui faco as validacoes conecto ao banco e aprovo a compra
}

The front end is in nodeJS (which I know almost nothing about, and the company has chosen to do this)

The code I have on the front end is as follows:

$('#aprovar').click(function(){
 $.ajax({
    type: "POST",
    url:"10.0.2.15:7001/ws/resources/Compra/aprovarCompra",
    contentType: "application/x-www-form-urlencoded", 
    data:'nrCompra=12345&usuario=usuarioMaster', 
    success: function (data) {
        alert(data);
    },
    error:function (){
        alert("error ao aprovar a Compra: "+nrCompra);
    }
});
});
    
asked by anonymous 16.01.2017 / 15:01

1 answer

0

I do not quite understand the problem, but I do not think I can read the WebService input parameters.

First, change the contentType of the Ajax call to:

contentType: "multipart/form-data"

What can be analyzed later is to check the service call and "debug" the server-side request.

I hope I have helped.

    
16.01.2017 / 19:22