0

I want to pass data from one application (Spring MVC) to another application written with ZK Framework using POST request. One of the parameters of the post method will be a file. Let's call it id.

So, what I do have now is Composer with the following code:

public class PictureComposer extends SelectorComposer<Component> {

    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp);
        Execution e = Executions.getCurrent();

        System.out.println("post param: " + Executions.getCurrent().getParameterMap().get("id"));

        HttpServletRequest request = (HttpServletRequest) e.getNativeRequest();
        String idd = request.getParameter("id");
        System.out.println("id: " + idd);
    }
}

And, when I try to make a POST request to this composer, Executions.getCurrent().getParameterMap().get("id") seems to return null.

Same thing with the second approach (using HttpServletRequest).

On the other hand, I get some value for id, when I use GET request and pass this value as a parameter in the URL. But, unfortunately, I cannot pass my file in the URL.

So, the main question is how I can retrieve the variable from the POST request?

UPD: (for now I try to retrieve a plain string parameter, just as simplified example) My POST request looks like this:

POST /zssessentials/picture.zul HTTP/1.1
Host: localhost:8080
Cache-Control: no-cache

----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="id"

wooooow
----WebKitFormBoundaryE19zNvXGzXaLvS5C
ivan.mylyanyk
  • 2,051
  • 4
  • 30
  • 37
  • How are you sending the file to this URL? Are you trying with multipart mime type? – zaerymoghaddam Oct 28 '14 at 10:37
  • @zaerymoghaddam I've updated the question and added the content of POST request. Please, take a look. – ivan.mylyanyk Oct 28 '14 at 10:40
  • There is a [similar question](http://stackoverflow.com/questions/20553493/zk-zul-get-value-from-input-form-data) having problems with executions and POST. – Narmer Oct 28 '14 at 10:43

2 Answers2

0

In order to retrieve an uploaded file, you should set enctype property of your <form> element to multipart/form-data, as below:

<form method="POST" action="your/zk/address" enctype="multipart/form-data" >
    ...
</form>

Then you can use the getPart method of HttpServletRequest class to access the uploaded file. So your code should be changed to something like this:

Part filePart = request.getPart("id");
InputStream filecontent = filePart.getInputStream();
zaerymoghaddam
  • 3,037
  • 1
  • 27
  • 33
0

I've figured out.

The reason was that the servlet didn't parse the multipart requests on its own. I had been sending requests with this line in the header (even if it was plain string or integer values):

Content-type: multipart/form-data

and that was the reason.

So, I was expected to use the third-party library in the PictureComposer class.

In my case Streaming API from Apache came in handy.

Also, this StackOverflow answer helped me a lot in resolving my problem.

Community
  • 1
  • 1
ivan.mylyanyk
  • 2,051
  • 4
  • 30
  • 37