vendredi 27 mars 2015

How do I retrieve a file using Java from an Amazon AWS server that I set up using Glassfish and the REST protocol?

I set up an Amazon AWS Linux server instance (EC2) that contains some audio files that I would like to retrieve using a REST protocol web service within my Java code. The problem I am having is that the URL for my getAudio function is incorrect for some reason. Here is my code for the getAudio function:



@Path("/get/{fileName}") // http://ift.tt/1NkFlhJ}
@GET
@Produces("application/wav")
public Response getAudio(@PathParam("fileName") String fileName) {
ResponseBuilder response = null;
StringBuilder builder = new StringBuilder();
builder.append(AUDIO_PATH).append(fileName).append(".wav");

File file = new File(builder.toString());
response = Response.ok(file);
response.header("Content-Disposition", "attachment; filename=" + fileName + ".wav")
.header("Access-Control-Allow-Origin", "*");

return response.build();
}


AUDIO_PATH is a final String variable that contains the associated path to the created audio files in the Linux instance.


Now in regards to Glassfish, this is an application server that lets me deploy the web service which consists of this function as well as a few other working functions.


So basically my problem is this: when I run a URL using Glassish which I know is put in correctly, there is a 404 error which says that the URL is not found. I have created a security exception in my Amazon Management console that allows for HTTP protocols so that shouldn't be an issue.


Also a side note, but I'm running my program with Glassfish from my IntelliJ IDE which also contains a createAudio function with the path: @Path("/create/{fileName}/{text}") This function works totally fine, creating audio based on what the text was that was input, but for some reason I just can't download the audio from the instance. Any help would be appreciated.





Aucun commentaire:

Enregistrer un commentaire