11 Replies Latest reply on Sep 14, 2006 11:45 AM by Chua Khoon Yong

    Interface from C app to Seam?

    Chua Khoon Yong Novice

      dear all,

      Need advice here.

      I'm using Jboss 4.0.4GA + Seam 1.0.1GA + Portal 2.40GA + facelets + myfaces.

      Currently i have an external C application that need to send a event or message to the java beans implemented using Seam. How to do it easily?

      Some thoughts:

      1. Send a HTTP post from the C application, and received by a servlet at Jboss and somehow triggerred up to the beans?

      2. Construct a HTTP post similar to "seam remoting" for javascript and let the remoting servlet handle it?

      3. Use web service?

      4. Use JMS?

      I'm not so good in Jboss and J2EE, so please help to advise.
      Thank you very much.

        • 1. Re: Interface from C app to Seam?
          Raja Master

          1. Web Services maybe a good way to do this, you dont have to use Seam for that, but just generally have an endpoint that can receive your WS calls and act on it. Why do you have to use Seam for this?

          2. Use JMX. If you have an JMX enabled bean, you could use the twiddle script (look up in jboss-4.0.x/bin/twiddle.sh) to invoke an mbean (get/set attribute, call methods etc) but that would be one more technology to learn :(

          • 2. Re: Interface from C app to Seam?
            Chua Khoon Yong Novice

            Thanks Raja for the advice. I'm building a web app using seam + portal + facelets, so i wanted the C app to interface with the java beans written in seam.

            Sorry, i'm a newbie so some of the terms may be incorrectly used.
            Cheers.

            • 3. Re: Interface from C app to Seam?
              Shane Bryzak Master

              Remoting was built for exactly this scenario, and even though we only provide a Javascript implementation of the remoting client, there is nothing stopping anyone from building a C (or whatever) client that integrates with the remoting servlet. It uses a simple XML-based structure for its protocol, and does all the work of setting up the Seam request (creating contexts, resuming conversations, etc) for you.

              If you implement your remote methods then test them first using Javascript, you can turn on debug mode to see the contents of the request and response packets. It should then be a pretty simple exercise to re-create the same request structure in C.

              • 4. Re: Interface from C app to Seam?
                Jim Hazen Expert

                Not to knock the work done by the remoting team, but is there a reason a custom protocol was chosen vs a Seam RemotingEndpoint that would handle remoting via some version of SOAP?

                I would have a thought the benefits of a standard transport protocol would outweigh the down side. Since obviously they did not, what are the benefits of this approach?

                • 5. Re: Interface from C app to Seam?
                  Shane Bryzak Master

                   

                  "CptnKirk" wrote:
                  Not to knock the work done by the remoting team, but is there a reason a custom protocol was chosen vs a Seam RemotingEndpoint that would handle remoting via some version of SOAP?

                  I would have a thought the benefits of a standard transport protocol would outweigh the down side. Since obviously they did not, what are the benefits of this approach?


                  SOAP was too heavy-weight for my taste; instead I chose to implement the remoting protocol based loosely on the XML-RPC spec, with some minor changes to how object references were handled and the inclusion of a request context to carry additional stuff like the conversation ID. The intent was to make the protocol as lightweight and simple as possible to both keep network traffic minimal and to make it easy to implement remoting clients in other languages (ActionScript, etc).

                  As a side note, there is a more comprehensive web services strategy in the works for Seam which will enable calling Seam components via SOAP.

                  • 6. Re: Interface from C app to Seam?
                    Jim Hazen Expert

                    What I figured. Thanks. Any plans to publish a protocol spec?

                    • 7. Re: Interface from C app to Seam?
                      Shane Bryzak Master

                       

                      "CptnKirk" wrote:
                      What I figured. Thanks. Any plans to publish a protocol spec?


                      I was actually thinking just the other day that it would be a good idea to document this stuff, so yeah it's on my list of things to do now :)

                      • 8. Re: Interface from C app to Seam?
                        Chua Khoon Yong Novice

                        dear all,

                        I end up using seam remoting method. The following is an example of what i did.
                        Cheers.


                        java -cp . Reverse http://localhost:8080/seam-helloworld/seam/remoting/execute "<call component=\"helloAction\" method=\"sayHello\" id=\"0\">hjhj"


                        Reverse class:
                        ==========

                        import java.io.*;
                        import java.net.*;

                        public class Reverse {
                        public static void main(String[] args) throws Exception {

                        if (args.length != 2) {
                        System.err.println("Usage: java Reverse " +
                        "http://<location of your servlet/script>" +
                        " string_to_reverse");
                        System.exit(1);
                        }

                        String stringToReverse = args[1];

                        URL url = new URL(args[0]);
                        URLConnection connection = url.openConnection();
                        connection.setDoOutput(true);
                        connection.setRequestProperty("Content-Type","text/xml");
                        connection.setDoInput(true);

                        OutputStreamWriter out = new OutputStreamWriter(
                        connection.getOutputStream());
                        out.write(stringToReverse);
                        out.close();

                        BufferedReader in = new BufferedReader(
                        new InputStreamReader(
                        connection.getInputStream()));

                        String decodedString;

                        while ((decodedString = in.readLine()) != null) {
                        System.out.println(decodedString);
                        }
                        in.close();
                        }
                        }

                        • 9. Re: Interface from C app to Seam?
                          Chua Khoon Yong Novice

                          some text was cut off in the reply. If you need do combine them without any carriage return. You can also see this similar trace when you run the remoting seam example.


                          java -cp . Reverse http://localhost:8080/seam-helloworld/seam/remoting/execute
                          "
                          <call component=\"helloAction\" method=\"sayHello\"
                          id=\"0\">hjhj
                          "

                          • 10. Re: Interface from C app to Seam?
                            Chua Khoon Yong Novice

                            i guess the text is still cutoff, if anybody need them, please capture the trace from running remoting example. Cheers.

                            • 11. Re: Interface from C app to Seam?
                              Chua Khoon Yong Novice

                              sorry for the multiple posts, the input arg is as follows. please add the \ escape character before the " character inside the quotes. Cheers.

                              java -cp . Reverse http://localhost:8080/seam-helloworld/seam/remoting/execute "hjhj"