Ofbiz service call from GWT RPC

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Ofbiz service call from GWT RPC

Gintare Ragaisiene
Hello,

   I'm working on tintegration GWT into ofbiz. GWT compiled js files is
placed into ofbiz "images" component in order ftl access them:

gwt_test.ftl

  <script type="text/javascript" language="javascript"
src="/images/gwttest1/gwttest1.nocache.js"></script>
  <table align="center">
      <tr>
        <td colspan="2" style="font-weight:bold;">Please enter your
name:</td>
      </tr>
      <tr>
        <td id="nameFieldContainer"></td>
        <td id="sendButtonContainer"></td>
      </tr>
    </table>

   Then I access GWT RPC from javascript. For this I corrected "images"
component war, because javascrip searches for servlet with path
"/gwttest1/greet" :

framework/images/webapp/images/war.xml :

<web-app>
  <display-name>Open For Business - demostore images</display-name>
  <description>Demo Store Images for the Open For Business
Project</description>

  <servlet>
    <servlet-name>greetServlet</servlet-name>

<servlet-class>org.ginsoftware.server.GreetingServiceImpl</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>greetServlet</servlet-name>
    <url-pattern>/gwttest1/greet</url-pattern>
  </servlet-mapping>

  <session-config>
    <session-timeout>1</session-timeout>
  </session-config>

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>main.jsp</welcome-file>
  </welcome-file-list>

</web-app>



    And I implemented servlet it self GreetingServiceImpl.java and classes
is put into images/WEB-INF :

   public class GreetingServiceImpl extends RemoteServiceServlet implements
GreetingService {

       public String greetServer(String input) {

            //Haw to call ofbiz service ?

            String serverInfo = getServletContext().getServerInfo();
            String userAgent =
getThreadLocalRequest().getHeader("User-Agent");

            return "Hello, " + input + "!<br><br>I am running " + serverInfo
+ ".<br><br>It looks like you are using:<br>" + userAgent;

       }
    }


    Until now everything works fine and my question is how do I call ofbiz
service from greetServer() method ? I've tried obtain LocalServiceDispacher
in variuos ways, but no luck at all.

Or is there somebody who already did that integration in more convenient way
that me ?


Thanks,
Gintare
Reply | Threaded
Open this post in threaded view
|

Re: Ofbiz service call from GWT RPC

Ashish Vijaywargiya
I would suggest you to go with a xml-rpc way.
Explore XmlRpcTests.java & XmlRpcClient.java files.

You can export services to external world by setting service definition
export attribute to true.
Take a look at the service definition "testScv" for more details.

OFBiz has XML-Rpc client and server inbuilt in it.
So you can see the output generated by XmlRpcTests.java file by following
command on console.

java -jar ofbiz.jar -test

Check block : "Running OFBiz Automated Tests" in the below document.
http://docs.ofbiz.org/display/OFBTECH/Apache+OFBiz+Technical+Production+Setup+Guide

--
Ashish

On Mon, Jul 20, 2009 at 12:41 PM, Gintare Ragaisiene <
[hidden email]> wrote:

> Hello,
>
>   I'm working on tintegration GWT into ofbiz. GWT compiled js files is
> placed into ofbiz "images" component in order ftl access them:
>
> gwt_test.ftl
>
>  <script type="text/javascript" language="javascript"
> src="/images/gwttest1/gwttest1.nocache.js"></script>
>  <table align="center">
>      <tr>
>        <td colspan="2" style="font-weight:bold;">Please enter your
> name:</td>
>      </tr>
>      <tr>
>        <td id="nameFieldContainer"></td>
>        <td id="sendButtonContainer"></td>
>      </tr>
>    </table>
>
>   Then I access GWT RPC from javascript. For this I corrected "images"
> component war, because javascrip searches for servlet with path
> "/gwttest1/greet" :
>
> framework/images/webapp/images/war.xml :
>
> <web-app>
>  <display-name>Open For Business - demostore images</display-name>
>  <description>Demo Store Images for the Open For Business
> Project</description>
>
>  <servlet>
>    <servlet-name>greetServlet</servlet-name>
>
> <servlet-class>org.ginsoftware.server.GreetingServiceImpl</servlet-class>
>  </servlet>
>
>  <servlet-mapping>
>    <servlet-name>greetServlet</servlet-name>
>    <url-pattern>/gwttest1/greet</url-pattern>
>  </servlet-mapping>
>
>  <session-config>
>    <session-timeout>1</session-timeout>
>  </session-config>
>
>  <welcome-file-list>
>    <welcome-file>index.jsp</welcome-file>
>    <welcome-file>main.jsp</welcome-file>
>  </welcome-file-list>
>
> </web-app>
>
>
>
>    And I implemented servlet it self GreetingServiceImpl.java and classes
> is put into images/WEB-INF :
>
>   public class GreetingServiceImpl extends RemoteServiceServlet implements
> GreetingService {
>
>       public String greetServer(String input) {
>
>            //Haw to call ofbiz service ?
>
>            String serverInfo = getServletContext().getServerInfo();
>            String userAgent =
> getThreadLocalRequest().getHeader("User-Agent");
>
>            return "Hello, " + input + "!<br><br>I am running " + serverInfo
> + ".<br><br>It looks like you are using:<br>" + userAgent;
>
>       }
>    }
>
>
>    Until now everything works fine and my question is how do I call ofbiz
> service from greetServer() method ? I've tried obtain LocalServiceDispacher
> in variuos ways, but no luck at all.
>
> Or is there somebody who already did that integration in more convenient
> way
> that me ?
>
>
> Thanks,
> Gintare
>
Reply | Threaded
Open this post in threaded view
|

Re: Ofbiz service call from GWT RPC

ian tabangay
Hi.

I am also toying with integrating GWT and Ofbiz. Using rpc calls available
in Ofbiz (xml, soap or json) does work with GWT with not much problem. My
problem is that I dont want to make all the services I need in Ofbiz to be
publicly available. Is there a way to make a service available for RPC but
would limit it to specific IPs only? Or is my concern unnecessary?

Ian Tabangay

On Tue, Jul 21, 2009 at 1:01 AM, Ashish Vijaywargiya <
[hidden email]> wrote:

> I would suggest you to go with a xml-rpc way.
> Explore XmlRpcTests.java & XmlRpcClient.java files.
>
> You can export services to external world by setting service definition
> export attribute to true.
> Take a look at the service definition "testScv" for more details.
>
> OFBiz has XML-Rpc client and server inbuilt in it.
> So you can see the output generated by XmlRpcTests.java file by following
> command on console.
>
> java -jar ofbiz.jar -test
>
> Check block : "Running OFBiz Automated Tests" in the below document.
>
> http://docs.ofbiz.org/display/OFBTECH/Apache+OFBiz+Technical+Production+Setup+Guide
>
> --
> Ashish
Reply | Threaded
Open this post in threaded view
|

Re: Ofbiz service call from GWT RPC

Harmeet Bedi
In reply to this post by Gintare Ragaisiene
Regd integration.

Approach we took was:
ofbiz does not have GWT native RPC support but it can do JSON and Http/XML more easily.
Use http/JSON RPC instead of GWT Native RPC + GWT serialization.


Regd getting LocalServiceDispacher
You should be able to do:
        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
        result = dispatcher.runSync(...)
LocalDispatcher is set in ControlServlet.
ControlServlet is in each web.xml
    <servlet>
        <servlet-name>ControlServlet</servlet-name>
        <display-name>ControlServlet</display-name>
        <description>Main Control Servlet</description>
        <servlet-class>org.ofbiz.webapp.control.ControlServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>ControlServlet</servlet-name>
        <url-pattern>/control/*</url-pattern>
    </servlet-mapping>

Note Load on startup and that your URLS will have /control/ i.e. loading ControlServlet.
Make sure your control servlet is loaded or look at how ofbiz is setting things in ControlServlet. Perhaps override if you cannot use ControlServlet configuration as is.

Harmeet
----- Original Message -----
From: "Gintare Ragaisiene" <[hidden email]>
To: [hidden email]
Sent: Monday, July 20, 2009 3:11:32 AM GMT -05:00 US/Canada Eastern
Subject: Ofbiz service call from GWT RPC

Hello,

   I'm working on tintegration GWT into ofbiz. GWT compiled js files is
placed into ofbiz "images" component in order ftl access them:

gwt_test.ftl

  <script type="text/javascript" language="javascript"
src="/images/gwttest1/gwttest1.nocache.js"></script>
  <table align="center">
      <tr>
        <td colspan="2" style="font-weight:bold;">Please enter your
name:</td>
      </tr>
      <tr>
        <td id="nameFieldContainer"></td>
        <td id="sendButtonContainer"></td>
      </tr>
    </table>

   Then I access GWT RPC from javascript. For this I corrected "images"
component war, because javascrip searches for servlet with path
"/gwttest1/greet" :

framework/images/webapp/images/war.xml :

<web-app>
  <display-name>Open For Business - demostore images</display-name>
  <description>Demo Store Images for the Open For Business
Project</description>

  <servlet>
    <servlet-name>greetServlet</servlet-name>

<servlet-class>org.ginsoftware.server.GreetingServiceImpl</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>greetServlet</servlet-name>
    <url-pattern>/gwttest1/greet</url-pattern>
  </servlet-mapping>

  <session-config>
    <session-timeout>1</session-timeout>
  </session-config>

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>main.jsp</welcome-file>
  </welcome-file-list>

</web-app>



    And I implemented servlet it self GreetingServiceImpl.java and classes
is put into images/WEB-INF :

   public class GreetingServiceImpl extends RemoteServiceServlet implements
GreetingService {

       public String greetServer(String input) {

            //Haw to call ofbiz service ?

            String serverInfo = getServletContext().getServerInfo();
            String userAgent =
getThreadLocalRequest().getHeader("User-Agent");

            return "Hello, " + input + "!<br><br>I am running " + serverInfo
+ ".<br><br>It looks like you are using:<br>" + userAgent;

       }
    }


    Until now everything works fine and my question is how do I call ofbiz
service from greetServer() method ? I've tried obtain LocalServiceDispacher
in variuos ways, but no luck at all.

Or is there somebody who already did that integration in more convenient way
that me ?


Thanks,
Gintare