0

is it possible to integrate ZEST with ZK normal MVC especially with GenericForwarComposer?

asked 2011-06-24 03:03:43 +0800

blacksensei gravatar image blacksensei
234 2

Hello Everyone!!

I've posted about a topic here related to have an integration with GenericForwardController with RESTful url for passing parameters.Unfortunately i didn't get any good feedback from the community :( .

I've found something that is built on/for ZK that supports RESTful address called ZEST . My only issue here is that when reading the documentation i didn't get the impression that it's can be used with the GFC at all.

So here i am again asking you to assist me with that part of my project.

thank you for reading and for your contributions

delete flag offensive retag edit

6 Replies

Sort by » oldest newest

answered 2011-06-24 04:07:59 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

hi blacksensei,
ZEST is designed to work seamlessly with ZK MVC (GFC way). You can refer to ZEST FAQ to get clear understanding of it especially the last question about difference in ZEST MVC and ZK MVC. Hope that helps.

link publish delete flag offensive edit

answered 2011-06-24 10:22:13 +0800

blacksensei gravatar image blacksensei
234 2

OK thanks for responding.In this case , can yo show me quickly a way(example/link) to access the parameters the GFC?

thanks again

link publish delete flag offensive edit

answered 2011-06-24 10:41:42 +0800

blacksensei gravatar image blacksensei
234 2

Hello Again!!

there is something that caught my attention on this page .on that page the example the give about a restful url is not restful

the request contains a parameter, index=5 (such as http://foo.com/foo?index=5), then setIndex(5) will be invoked. Thus, you could retrieve the value directly from the action, such as int getIndex().

In my knowledge or at least i was expecting something like

http://foo.com/foo/index/5

or http://foo.com/5/foo/index

where in zest.xml i can define the pattern of the url say:

http://foo.com/foo/{action}/{id}

more or less something like that.

Maybe i'm not getting it well. is that the case?

link publish delete flag offensive edit

answered 2011-10-17 12:01:50 +0800

blacksensei gravatar image blacksensei
234 2

Helloooo!!!
Any one here?

link publish delete flag offensive edit

answered 2011-12-17 16:01:00 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-12-17 21:47:30 +0800

Push!

I miss java sample codes in the documentation for calling a RestUrl and get back a result directly without calling a view from an action ? Is this possible or am i on the false way and must use 'normal' web services.

docu

...
If the action generates the output directly to the response, you could specify the type as done, then ZEST won't handle it further but returning the response directly....

Can somebody help me with codes.

Thanks
Stephan

link publish delete flag offensive edit

answered 2011-12-21 21:05:21 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-12-22 08:32:58 +0800

OK. Solved.

The documentation is a bit small about that. So Frank goes through the codes of zest and found a second execution method where an ActionContext is overhanded.
Here are the sample codes that gives back directly a string in the respone without calling a zul/jsp/htm/... file. In our case we want back a list of key-value pairs.

best
Stephan feat. Frank

zest.xml

<?xml version="1.0" encoding="UTF-8"?>
<zest>
	<action path="/hello" class="org.opentruuls.base.rest.MyZestAction"
		method="execute3">
		<result name="success" type="done" ></result>
	</action>
</zest>

MyZestAction.java on server

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import org.zkoss.zest.ActionContext;

public class MyZestAction {

	/**
	 * EN: Gets the response from the ActionContext and gives back directly a
	 * string.<br>
	 * DE: Holt den Response aus dem ActionContext und gibt ein String zurueck.<br>
	 * 
	 * @param ac
	 * @return String
	 * @throws IOException
	 */
	public String execute2(ActionContext ac) throws IOException {

		HttpServletResponse response = ac.getServletResponse();
		ServletOutputStream os = response.getOutputStream();
		os.print("Hallo");

		// de: Niemals das Flush vergessen, sonst ist die Ausgabe unvollständig
		// en: Never forget to flush the output to clear buffers
		os.flush();

		return "success";
	}

	/**
	 * EN: Gets the response from the ActionContext and gives back directly a
	 * string as properties.<br>
	 * DE: Holt den Response aus dem ActionContext und gibt ein String als
	 * Properties zurueck.<br>
	 * 
	 * @param ac
	 * @return String as Properties (Key-Value pairs).
	 * @throws IOException
	 */
	public String execute3(ActionContext ac) throws IOException {

		HttpServletResponse response = ac.getServletResponse();
		ServletOutputStream os = response.getOutputStream();

		// write a property file with the needed data
		Properties p = new Properties();
		p.setProperty("Servername", "TomcatInstance_2");
		p.setProperty("Sessions", "134");
		p.store(os, "");

		// de: Niemals das Flush vergessen, sonst ist die Ausgabe unvollstaendig
		// en: Never forget to flush the output to clear buffers
		os.flush();

		return "success";
	}
}

client code for testing

   . . .
				final String urlString = "http://localhost:8082/opentruuls/hello";

				try {
					final URL url = new URL(urlString);
					final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
					// inform the connection that we will send output and accept input
					conn.setDoInput(true);
					conn.setDoOutput(true);

					System.out.println("responseCode: " + conn.getResponseCode());

					final InputStream inStream = conn.getInputStream();

					try {
						Properties p = new Properties();
						p.load(inStream);

						System.out.println("count of key-value pairs: " + p.size());
						String s = (String) p.get("Servername");
						System.out.println("Value of Key 'Servername': " + s);
						String s1 = (String) p.get("Number of sessions");
						System.out.println("Value of Key 'Number of sessions': " + s1);

					} catch (final NumberFormatException e) {
						throw new RuntimeException(e);
					} finally {
						inStream.close();
					}
				} catch (FileNotFoundException ex) {
					System.err.println("Failed to open stream to URL: " + ex);
				} catch (final IOException e) {
					throw new RuntimeException(e);
				}

console output

. . .
2011-12-21 21:59:45,126 INFO   [ContainerBackgroundProcessor[StandardEngine]] ContextLoader M - Root WebApplicationContext: initialization completed in 11173 ms
...
responseCode: 200
count of key-value pairs: 2
Value of Key 'Servername': TomcatInstance_2
Value of Key 'Number of sessions': 134

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-06-24 03:03:43 +0800

Seen: 426 times

Last updated: Dec 21 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More