vendredi 29 mai 2015

Send and Receive a complete file via cURL and Java

i'm trying to send a local file "test.properties" via curl to a server which is also running on my localhost. The test.properties file is basically just a txt-file and looks like this

#
#Tue May 12 16:17:01 CEST 2015
hostname=localhost
Resource_namespace=http\://localhost/resource/
url=localhost
Local_namespace=http\://localhost/

My cURL command looks like this:

curl -i -X POST --data-binary ssh.properties localhost:8080/sshService/PhysicalNodeAdapter-1/config

And my Java-Method on the recieving server looks like this:

  @POST
  @Path("/{adapterName}/config")
  @Consumes("*/*")
  @Produces("text/html")
  public Response updateConfig(@PathParam("adapterName") String     
  adapterName, String configInput) {
   AbstractAdapter adapter = getAdapterInstance(adapterName);
    Log.fatal("CONFIG", configInput);
   try {
    adapter.updateConfig(adapterName,configInput);
    return Response.status(Response.Status.OK.getStatusCode()).build();
} catch (ProcessingException e) {
    processProcessingRequestException(e);
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
return Response.status(Response.Status.CONFLICT.getStatusCode()).build();
}

I just need a curl command that sends one file via http to an server. The server takes the file and saves it 1:1 on the hard-disk

But i really don't get it. Tried different commands and different "@Consumes" but didn't work out...

Edit: I forgot to say i don't want it URL-Encoded. It should be in the Body of the POST-package

Aucun commentaire:

Enregistrer un commentaire