1

So I'm trying to integrate wami-recorder into my webapp. The webapp currently is built using the Struts2 framework.

There is an example on StackOverflow here on how to integrate wami-recorder into a php site. How would I achieve similar functionality using Struts2? It seems like wami tries to POST the file to a certain URL. How do I get Struts2 to receive such a file? Or is there a better way to go about this?

EDIT: MMk so, I used Dave's wording to search google and found this. Right now, my action's execute method looks like

HttpServletRequest request = ServletActionContext.getRequest();
InputStream body = null;

try {
    body = request.getInputStream();
    OutputStream outputStream = new FileOutputStream("/home/test.mp3");
    IOUtils.copy(body, outputStream);
    outputStream.close();
} catch (IOException e) {
    e.printStackTrace();
}

return SUCCESS;'

However, when I use wami to POST

Wami.startRecording("http://localhost:8080/addRecording/test.wav");

I get the following in chrome developer tools:

Request URL:http://localhost:8080/addRecording/test.wav
Request Method:POST
Status Code:404 Not Found

Is there something wrong with the configuration of my action class? Or am I misusing wami?

Community
  • 1
  • 1
pgorsira
  • 202
  • 3
  • 12
  • By following the guide on [uploading files in Struts 2](http://struts.apache.org/release/2.2.x/docs/file-upload.html)? – Dave Newton Jun 12 '13 at 20:23
  • Forgive me Dave as I am a rookie still. It appears that all of the examples on that page use the s:file tag. I don't see anywhere that tag could fit in this workflow. My (possibly wrong) understanding is that wami-recorder pushes the raw POST data of the file to a URL. How would I accept this raw data as an action parameter? – pgorsira Jun 12 '13 at 23:07
  • Also you are a struts celebrity I see your name everywhere – pgorsira Jun 12 '13 at 23:07
  • 1
    The upload process itself doesn't care where the data is coming from, as long as it's a normal HTTP multipart request, and the S2 action properties match the form data's file name. As long as there's no paparazzi I'm okay with the celebrity part, but it seems like I should get in to more clubs. – Dave Newton Jun 12 '13 at 23:09
  • Haha, unfortunate that it doesn't work that way. Btw, I edited my post based on your response. – pgorsira Jun 12 '13 at 23:53
  • You'll need to add the action configuration. Without knowing what this api is actually sending to the server it'll be impossible to help any further. It kind of looks like you'd want to use one of the matching dispatchers to capture the filename, but it depends entirely on how the api is sending its data. – Dave Newton Jun 13 '13 at 01:40

1 Answers1

0

Turns out with the updated code the file is actually being stored. Getting a 404 for other reasons. In any case, my question is answered.

pgorsira
  • 202
  • 3
  • 12