Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » Calling Scout from Mobile Device(Calling Scout from Mobile Device)
Calling Scout from Mobile Device [message #1006393] Thu, 31 January 2013 08:53 Go to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 309
Registered: August 2011
Senior Member
Hi,

I want to call the Scout server from a Mobile Device (built with PhoneGap/Cordova). Is that possible and are there any examples of this.

Regards Bertin
Re: Calling Scout from Mobile Device [message #1006449 is a reply to message #1006393] Thu, 31 January 2013 11:28 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 790
Registered: October 2011
Senior Member
Hi Bertin,

I am not sure to understand what you want to achieve...

You are in a PhoneGap / Cordova Application and you want to use your Scout Server as Service Provider for this Application?

What is the library you use in your Cordova Application. I assume a JS lib like JQuery or AngularJS. So far I know these libraries expect a RESTful backend Interface exposing data in the JSon format.

Out of the box, Scout does not offer this kind of interface. If I had to do something like that, I would have a look on the JAX-WS Scout integration. Maybe this can give you some input on how you can build RESTful interface on the Scout server (I am thinking JAX-RS but I am not sure).


I hope I understand your problem correctly.

Re: Calling Scout from Mobile Device [message #1006465 is a reply to message #1006449] Thu, 31 January 2013 12:08 Go to previous messageGo to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 309
Registered: August 2011
Senior Member
Hi Jeremie,

We have a mobile application build with PhoneGap/Cordova. The application is for children to make some simple homework. If the user starts, he/she has to download this homework from the server (its just some simple data). Later on, the application uploads the results to the server again.

On the client side we use JQuery, JQuery Mobile and this like that.

We alreay have something like this in a browser, but the student has to be online all the time. Because more and more children use tablets we want to give them this possibility also.

The browser version does not work in IPad and Android perfectly so we want to create "native" aps.

In the office we a Scout application for teachers to prepare the homework.

I hope this makes the use case clear.

Regards Bertin
Re: Calling Scout from Mobile Device [message #1006541 is a reply to message #1006465] Thu, 31 January 2013 15:49 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 790
Registered: October 2011
Senior Member
If you use JQuery, JQuery Mobile in your client WebApplication, what are your expecting from the server?

Don't you agree with my previous answer?
Re: Calling Scout from Mobile Device [message #1006615 is a reply to message #1006541] Fri, 01 February 2013 07:58 Go to previous messageGo to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 309
Registered: August 2011
Senior Member
Hi,

From the server I just want some data, nothing else.

I think I can agree on your answer about RESTful, JAX-WS , but I have very little hands-on experience with that. So I hoped someone already did something like this and good give me some good examples.

Regards Bertin

Re: Calling Scout from Mobile Device [message #1436079 is a reply to message #1006615] Thu, 02 October 2014 11:11 Go to previous messageGo to next message
Dennis Geesen is currently offline Dennis GeesenFriend
Messages: 43
Registered: June 2014
Member
Hi,

This thread is a little bit older, but I have exaclty the same question.
So, did some (first of all Bertin) get something more experience?

I heard that RAP also used JSON!? Does someone knows about this? Is this only for the GUI to get the widgets to the browser? And what exactly makes the ajax interface of scout?

My background: I just want to have one certain form in an app with some fields that is pushed to the scout server.
In sum, I would also like to simply call a web service and pass the form data from my mobile app. In the ideal case RAP should be completely removed!

Re: Calling Scout from Mobile Device [message #1436163 is a reply to message #1436079] Thu, 02 October 2014 13:46 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 790
Registered: October 2011
Senior Member
Dennis Geesen wrote on Thu, 02 October 2014 13:11
I heard that RAP also used JSON!? Does someone knows about this?


Yes RAP uses JSON as format for its protocol. But forget the idea to consume it yourself. The protocol is not easy and describes the UI at a very low level. I do not think you will be able to use it.
* Remote The New "R" in RAP
* RAP protocol: all about messages
* RAP Protocol on the Eclipse Wiki.

Dennis Geesen wrote on Thu, 02 October 2014 13:11
And what exactly makes the ajax interface of scout?

I think this is a special servlet that is needed by the "rap Scout Client" (that is the RAP Server): it is used for the login but I am not sure.

Dennis Geesen wrote on Thu, 02 October 2014 13:11
And My background: I just want to have one certain form in an app with some fields that is pushed to the scout server.
In sum, I would also like to simply call a web service and pass the form data from my mobile app


I still think that the best way is to embed a small Jax-RS Server in the Scout Server (that will be deployed in the same servlet Container [Jetty or Tomcat]). You will need to write some glue code to come from the Jax-RS Server to the Scout Server (starting a ServerJob, being in the correct Transaction...) This will most likely look-like what we have realized in the Jax-WS integration.
Re: Calling Scout from Mobile Device [message #1438938 is a reply to message #1436163] Mon, 06 October 2014 18:03 Go to previous messageGo to next message
Dennis Geesen is currently offline Dennis GeesenFriend
Messages: 43
Registered: June 2014
Member
Ah ok, that confirms exactly what I thought.

I think I will try to integrate JAX-RS and then to use JQuery or something like that...
Of course, I will share my experiences!
Re: Calling Scout from Mobile Device [message #1439627 is a reply to message #1438938] Tue, 07 October 2014 10:42 Go to previous messageGo to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 309
Registered: August 2011
Senior Member
Hi,

sorry for the late answer.

For our mobile platforms, we are still working with a php service on the server side that delivers data in a JSON format. Still like to convert that to the Scout Server but as long as the php works, it does not get a high priority.

Regards Bertin





Re: Calling Scout from Mobile Device [message #1441467 is a reply to message #1439627] Thu, 09 October 2014 19:39 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 790
Registered: October 2011
Senior Member
I have put a simple Custom Servlet example on the wiki.

Discussion and next step is available on the forum: I want to have access to other Scout Server Services from a custom servlet.

Another related forum topic:
* Call Scout Service from webpage

.
Re: Calling Scout from Mobile Device [message #1441780 is a reply to message #1441467] Fri, 10 October 2014 07:02 Go to previous messageGo to next message
Dennis Geesen is currently offline Dennis GeesenFriend
Messages: 43
Registered: June 2014
Member
I also started an approach yesterday and have more or less the same solution. I currently try to integrate Jersey (https://jersey.java.net) for the custom servlet to publish the rest services using the jax rs annotations...
Re: Calling Scout from Mobile Device [message #1441882 is a reply to message #1441780] Fri, 10 October 2014 10:05 Go to previous message
Dennis Geesen is currently offline Dennis GeesenFriend
Messages: 43
Registered: June 2014
Member
I've got it. To roughly sketch the solution for integrating Jersey into Scout:

First, download the Jersey ( I used 2.13) libraries and add the bunch of jars them to the build path. To avoid any side-effects due to potential OSGi-classloading issues, I currently have all jersey jars in a lib folder of the scout server-plugin.


First we have a resource, I call it Hello

  
package de.scout.test.rest.server;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.scout.commons.exception.ProcessingException;
import org.eclipse.scout.service.SERVICES;

@Path("/hello")
public class Hello {

@GET
  @Produces(MediaType.TEXT_PLAIN)
  public String hello() {
    try {
      String result = SERVICES.getService(IHelloService.class).getGreetings();
      return "{" + "SAY: " + result + "}";
    }
    catch (ProcessingException e) {
      e.printStackTrace();
    }
    return "";
  }


Create a JerseyApplication to define the resources that should be provided by Jersey. Although Jersey normally has a package lookup mechanism, this doesn't work for me. Maybe I will check this in the future.

package de.scout.test.rest.server;

import java.util.HashSet;
import java.util.Set;

import javax.ws.rs.core.Application;

public class JerseyApplication extends Application {
  @Override
  public Set<Class<?>> getClasses() {
    Set<Class<?>> result = new HashSet<Class<?>>();
    result.add(Hello.class);
    return result;
  }
}



Since the rest request is called in another thread than the normal server session is running, we use an own servletcontainer to wrap the request. For this, I created a ProxyServletContainer. Each request is passed by the service method and is delegated to the "normal" jersey ServletContainer, but uses the scout ServerSession (Thread) for this. This "custom servlet" is also discussed here: https://www.eclipse.org/forums/index.php/t/827899/ and I only show the interesting parts:

package de.scout.test.rest.server;
//...
import org.glassfish.jersey.servlet.ServletContainer;
//...

public class ProxyServletContainer extends ServletContainer {
//....
@Override
  protected void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    try {
      lazyInit(request, response);
      Subject subject = new Subject();
      subject.getPrincipals().add(new SimplePrincipal("server"));
      UserAgent agent = UserAgent.createDefault();
      if (subject != null && agent != null) {
        IServerSession session = lookupScoutServerSessionOnHttpSession(request, response, subject, agent);

        ServerJob serverJob = new ServerJob("Transactional handler", session, subject) {

          @Override
          protected IStatus runTransaction(IProgressMonitor monitor) throws Exception {
            ServletContainer sc = new ServletContainer();
            sc.init(getServletConfig());
            sc.service(request, response);
            return Status.OK_STATUS;
          }
        };
        serverJob.setSystem(true);
        serverJob.runNow(new NullProgressMonitor());
      }
      else {
        throw new ServletException("could not create subject or agent!");
      }
    }
    catch (ProcessingException ex) {
      throw new ServletException(ex);
    }
  }


//....
}



Finally you have to register the ProxyServletContainer to the erquinox http service by adding an entry to the extension point. Add the following to the plugin.xml of the server plugin:
 <servlet
            alias="/rest"
            class="package de.scout.test.rest.server.ProxyServletContainer">
         <init-param
               name="javax.ws.rs.Application"
               value="package de.scout.test.rest.server.JerseyApplication">
         </init-param>
      </servlet>


All Jersey resources are now published to /rest/*, so the Hello.class is publishd to http://localhost:8080/rest/hello (if your scour server is running on 8080).
And it is possible to directly use the SERVICES class to call any service.

Next thing should be a security filter that filters all request on /rest/*...
Previous Topic:getDataByText() for SmartFields with CodeTypes
Next Topic:Run scout server standalone?
Goto Forum:
  


Current Time: Sun Nov 23 15:00:27 GMT 2014

Powered by FUDForum. Page generated in 0.03812 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software