rhoconnect 3.0.6 → 3.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/CHANGELOG.md +9 -0
  2. data/Gemfile +3 -3
  3. data/Gemfile.lock +38 -17
  4. data/Rakefile +0 -10
  5. data/bench/benchapp/Gemfile.lock +1 -0
  6. data/bench/distr_bench/distr_bench_main +94 -27
  7. data/bench/distr_bench/run_test_query_script.sh +22 -18
  8. data/bench/lib/bench/aws_utils.rb +326 -0
  9. data/bench/lib/bench/bench_result_processor.rb +268 -75
  10. data/bench/lib/bench/cli.rb +1 -0
  11. data/bench/lib/bench/distr_runner.rb +102 -0
  12. data/bench/lib/bench/utils.rb +127 -0
  13. data/bench/lib/bench.rb +16 -15
  14. data/bench/prepare_bench +3 -11
  15. data/bench/scripts/test_query_script.rb +6 -7
  16. data/bin/rhoconnect-benchmark +257 -5
  17. data/doc/benchmarks-running.txt +140 -0
  18. data/doc/client-java.txt +236 -0
  19. data/doc/client-objc.txt +41 -1
  20. data/doc/client.txt +12 -0
  21. data/doc/command-line.txt +12 -3
  22. data/doc/cud-conflicts.txt +68 -0
  23. data/doc/deploying.txt +1 -70
  24. data/doc/hosting-rhohub.txt +3 -0
  25. data/doc/install.txt +50 -13
  26. data/doc/java-plugin.txt +217 -177
  27. data/doc/net-plugin.txt +97 -64
  28. data/doc/plugin-intro.txt +4 -2
  29. data/doc/preparing-production.txt +63 -0
  30. data/doc/rhoconnect-redis-stack.txt +252 -0
  31. data/doc/source-adapters.txt +3 -1
  32. data/doc/tutorial.txt +111 -49
  33. data/examples/simple/dump.rdb +0 -0
  34. data/installer/unix-like/rho_connect_install_constants.rb +6 -5
  35. data/installer/unix-like/rho_connect_install_installers.rb +6 -2
  36. data/installer/utils/nix_install_test.rb +2 -0
  37. data/installer/utils/package_upload/auto-repo.rb +136 -0
  38. data/installer/utils/package_upload/repos.rake +6 -3
  39. data/installer/utils/package_upload/s3_upload.rb +11 -6
  40. data/installer/windows/rhosync.nsi +5 -5
  41. data/lib/rhoconnect/client_sync.rb +2 -2
  42. data/lib/rhoconnect/document.rb +12 -0
  43. data/lib/rhoconnect/jobs/source_job.rb +2 -2
  44. data/lib/rhoconnect/predefined_adapters/bench_adapter.rb +61 -0
  45. data/lib/rhoconnect/source.rb +5 -0
  46. data/lib/rhoconnect/source_adapter.rb +10 -1
  47. data/lib/rhoconnect/source_sync.rb +161 -88
  48. data/lib/rhoconnect/store.rb +48 -0
  49. data/lib/rhoconnect/test_methods.rb +6 -6
  50. data/lib/rhoconnect/version.rb +1 -1
  51. data/lib/rhoconnect.rb +25 -2
  52. data/spec/apps/rhotestapp/sources/sample_adapter.rb +29 -0
  53. data/spec/jobs/source_job_spec.rb +5 -5
  54. data/spec/source_adapter_spec.rb +10 -0
  55. data/spec/source_sync_spec.rb +114 -33
  56. data/spec/spec_helper.rb +21 -2
  57. data/spec/store_spec.rb +29 -0
  58. data/spec/support/shared_examples.rb +1 -1
  59. data/spec/test_methods_spec.rb +4 -4
  60. data/tasks/redis.rake +2 -2
  61. metadata +59 -59
  62. data/bench/benchapp/log/passenger.3000.log +0 -1
  63. data/bench/benchapp/log/passenger.9292.log +0 -59
  64. data/bench/benchapp/tmp/pids/passenger.3000.pid.lock +0 -0
  65. data/bench/benchapp/tmp/pids/passenger.9292.pid.lock +0 -0
  66. data/bench/lib/testdata/0-data.txt +0 -0
  67. data/bench/lib/testdata/1-data.txt +0 -0
  68. data/bench/lib/testdata/10-data.txt +0 -15
  69. data/bench/lib/testdata/2-data.txt +0 -3
  70. data/bench/lib/testdata/25-data.txt +0 -39
  71. data/bench/lib/testdata/250-data.txt +0 -353
  72. data/bench/lib/testdata/3-data.txt +0 -4
  73. data/bench/lib/testdata/50-data.txt +0 -70
  74. data/bench/lib/testdata/500-data.txt +0 -711
data/doc/deploying.txt CHANGED
@@ -1,73 +1,4 @@
1
- Deploying a RhoConnect Application
2
- ===
3
-
4
- Since RhoConnect applications are standard ruby [sinatra](http://www.sinatrarb.com/) applications, you have many hosting options. This section will cover two ways to deploy a RhoConnect application: use the RhoHub service, deploy to an on-premise server.
5
-
6
- ## Preparing App for Production
7
- By default your RhoConnect application generates a few files that you should be familiar with and understand the settings.
8
-
9
- ### `config.ru`
10
- This rackup file contains runtime configuration for the RhoConnect sinatra application:
11
-
12
- :::ruby
13
- Rhoconnect::Server.disable :run
14
- Rhoconnect::Server.disable :clean_trace
15
- Rhoconnect::Server.enable :raise_errors
16
- Rhoconnect::Server.set :secret, '<changeme>'
17
- Rhoconnect::Server.set :root, ROOT_PATH
18
- Rhoconnect::Server.use Rack::Static, :urls => ["/data"], :root => Rhoconnect::Server.root
19
-
20
- The important setting here `:secret` you will want to change. `:secret` should be set to a long random string, it ___should not___ be set to a dictionary word or short string (30 characters or more is sufficient). This is used for the session storage using a digest algorithm as described [here](http://guides.rubyonrails.org/security.html#session-storage).
21
-
22
- If you don't change the `:secret` setting, RhoConnect automatically warns you each time the application starts:
23
-
24
- [11:34:56 AM 2011-01-12] ************************************************************
25
-
26
- [11:34:56 AM 2011-01-12] WARNING: Change the session secret in config.ru from <changeme> to something secure.
27
- [11:34:56 AM 2011-01-12] i.e. running `rake rhoconnect:secret` in your app will generate a secret you could use.
28
-
29
- [11:34:56 AM 2011-01-12] ************************************************************
30
-
31
-
32
- As this warning states, a good way to generate a cryptographically secure secret is by running `rake rhoconnect:secret` in your RhoConnect application.
33
-
34
- :::term
35
- $ cd storemanager-server
36
- $ rake rhoconnect:secret
37
- 040a2355475e9d0fb591ef78d5b9ca61a34cbcfd3f11942b18bc1d91f1ca66c27b2e0386333843a7efa29f40fff03624cd908d0883364ffbfa3208ab23fa2664
38
-
39
- Then plug this secret into your `config.ru`:
40
-
41
- :::ruby
42
- Rhoconnect::Server.set :secret, '040a2355475e9d0fb591ef78d5b9ca61a34cbcfd3f11942b18bc1d91f1ca66c27b2e0386333843a7efa29f40fff03624cd908d0883364ffbfa3208ab23fa2664'
43
-
44
- To run RhoConnect in production mode, use `RACK_ENV` environment variable set to "production". This ensures RhoConnect will use the `:production` section of the settings. For example:
45
-
46
- :::term
47
- $ thin start -e production -p 9292
48
-
49
- Will start thin in with `RACK_ENV` set to "production".
50
-
51
- NOTE: If you deploy using passenger or on RhoHub, this variable is automatically set to production.
52
-
53
- ### `settings/settings.yml`
54
- This file contains all source adapter options and settings like the redis server connection. Before deploying to production, make sure you have the appropriate production settings:
55
-
56
- :::yaml
57
- :sources:
58
- Product:
59
- :poll_interval: 300
60
-
61
- :production:
62
- :redis: myredishost:6379
63
- :licensefile: settings/license.key
64
- :syncserver: http://localhost:9292/application/
65
-
66
- ### `settings/license.key`
67
- This contains your RhoConnect license key text. By default, a RhoConnect application comes with a 10 device license. Please see the [licensing page](/rhoconnect/licensing) for more details.
68
-
69
- ## Hosting on RhoHub
70
- The [RhoHub](/rhohub/introduction) service offers several [production RhoConnect application hosting levels](http://rhohub.com/pricing). Simply sign up on [rhohub.com](http://rhohub.com/) and go through the [tutorial](/rhohub/tutorial) on deploying your first RhoConnect application with RhoHub.
1
+ # Deploying a RhoConnect Application
71
2
 
72
3
  ## Deploying On-Premise
73
4
  The [sinatra book](http://sinatra-book.gittr.com/) has some great [deployment documentation](http://sinatra-book.gittr.com/#deployment) that you should review before running your RhoConnect application in production.
@@ -0,0 +1,3 @@
1
+ # Hosting on RhoHub
2
+
3
+ The [RhoHub](/rhohub/introduction) service offers several [production RhoConnect application hosting levels](http://rhohub.com/pricing). Simply sign up on [rhohub.com](http://rhohub.com/) and go through the [tutorial](/rhohub/tutorial) on deploying your first RhoConnect application with RhoHub.
data/doc/install.txt CHANGED
@@ -1,27 +1,64 @@
1
- Installing RhoConnect
2
- ===
1
+ # Installing RhoConnect
2
+
3
+ On Windows and Mac OS, the usual way to install RhoConnect is to install RhoStudio.
4
+
5
+ On Linux, you install the Rhodes gem from the command line; you can also do this from Windows or Mac OS.
6
+
7
+ ## Mac OS
8
+
9
+ If you're running Mac OS, download the latest [RhoStudio for Macintosh](http://rhomobile.com/rhostudio-mac). This contains the [Ruby stack](http://www.ruby-lang.org/en/), [Redis](http://redis.io/), [RhoConnect](/rhoconnect/introduction) and [Rhodes](/rhodes/introduction).
10
+
11
+ Click on the RhoStudioInstaller for Mac download file to open it. You will get a window similar to this:
12
+
13
+ <img src="http://rhodocs.s3.amazonaws.com/rhodes-devel/rhostudio-mac-install.png" alt="RhoStudioInstaller Mac" />
14
+
15
+ Run the install gems script appropriate for you. You can run "Install gems." If you have Ruby Version Manager, you can run "Install gems on rvm." A terminal window will open; wait for the gems install process to complete.
16
+
17
+ Then drag RhoStudio to the Applications folder.
3
18
 
4
19
  ## Windows
5
20
 
6
- If you're running Windows, download the latest [RhoStudio for Windows](http://rhomobile.com/rhostudio-windows). This installs the [Ruby stack](http://www.ruby-lang.org/en/), [Redis](http://redis.io/), [RhoConnect](/rhoconnect/introduction) and [Rhodes](/rhodes/introduction).
21
+ If you're running Windows, download the latest [RhoStudio for Windows](http://rhomobile.com/rhostudio-windows). This installs the [Ruby stack](http://www.ruby-lang.org/en/), [Redis](http://redis.io/), [RhoConnect](/rhoconnect/introduction), and [Rhodes](/rhodes/introduction).
22
+
23
+ If you are running Windows 64-bit, you need to have 64-bit Eclipse, and then you [install RhoStudio as a plugin for Eclipse](/rhodes/rhostudio-eclipse).
24
+
25
+ ## Java Development Kit (JDK)
7
26
 
8
- You can now skip to the [generating a new application instructions](/rhoconnect/command-line#generate-an-application) in the next section.
27
+ You need to have the Java Development Kit (JDK) installed for RhoStudio. If you are planning to build for Blackberry or Android, make sure you have JDK version 1.6.0_2 or higher installed; the 32-bit Windows version of the JDK is required for Blackberry tools.
9
28
 
10
- ## Mac OS / Linux
29
+ ### Installing the Java Development Kit
11
30
 
12
- ### Prerequisites
31
+ The Sun JDK for Windows or Linux is available [here](http://java.sun.com/javase/downloads/index.jsp). For Windows, install the 32-bit version of the JDK; RhoStudio needs the 32-bit version.
13
32
 
14
- 1. [Ruby v1.8.7+](http://www.ruby-lang.org/en/downloads/)
33
+ For Mac OS 10.6 and earlier, the JDK is already installed. For Mac OS 10.7, Java is not automatically installed. Download the Java for Mac Installer from [Apple support](http://support.apple.com/kb/DL1421) and install Java.
15
34
 
16
- 2. [RubyGems v1.8.5+](http://rubygems.org/pages/download)
35
+ ### Setting the JDK Path
17
36
 
18
- 3. Ruby Web Server - We test with [thin](http://code.macournoyer.com/thin/), and [passenger](http://www.modrails.com/). WEBrick, the web server that ships with ruby, is known to cause issues with HTTP headers/cookies and is ***not*** recommended.
37
+ On Windows installs for RhoMobile, go to RhoStudio Preferences (Windows -> Preferences) and set the JDK path in the rhobuild.yml file. On Windows 64-bit installations, you must set this path to the 32-bit version of the JDK, such as `C:/Program Files (x86)/Java/jdk1.7.0_01/bin`.
19
38
 
20
- 4. [Redis 2.4.x](http://redis.io/) - RhoConnect includes a simple [rake task](/rhoconnect/command-line#rake-tasks) `redis:install` to install redis, covered in the [Rake Tasks section](/rhoconnect/command-line#rake-tasks). Alternatively, you can [install redis directly](http://redis.io/download).
39
+ On Mac OS, the path to the JDK is automatically set once Java is installed.
21
40
 
22
- ### Installing RhoConnect Gem
41
+ For non-RhoStudio installations, set the JDK path on the JAVA_HOME variable in your PATH.
23
42
 
24
- To install the RhoConnect gem, run:
43
+ ## Rhoconnect Gem for Linux and non-RhoStudio
44
+
45
+ For Linux installations, and for Windows or Mac OS installations that are not using RhoStudio, you need to install the RhoConnect gem. Download and install:
46
+
47
+ 1. [Ruby v1.8.7+](http://www.ruby-lang.org/en/downloads/) (On Windows, [RubyInstaller](http://rubyinstaller.org) is a convenient way to install Ruby.)
48
+
49
+ 2. [RubyGems v1.8.5+](http://rubygems.org/pages/download) (RubyGems offers a .tgz, a .zip, and a .gem download. You want the .zip.) NOTE: Windows doesn't come with the necessary build tools to install gems ('make', for example). There are various ways to get these tools, but the GnuWin32 project at http://gnuwin32.sourceforge.net/ provides the tools, and can be conveniently installed via the GetGnuWin32 installer at http://sourceforge.net/projects/getgnuwin32/files/.
50
+
51
+ 3. Ruby Web Server - We tested with [thin](http://code.macournoyer.com/thin/), and [passenger](http://www.modrails.com/). WEBrick, the web server that ships with ruby, is known to cause issues with HTTP headers/cookies and is ***not*** recommended.
52
+
53
+ 4. [Redis 2.2.14+](http://redis.io/) - RhoConnect includes a simple [rake task](/rhoconnect/command-line#rake-tasks) `redis:install` to install redis, covered in the [Rake Tasks section](rhoconnect/command-line#rake-tasks). Alternatively, you can [install redis directly](http://redis.io/download).
54
+
55
+ 5. Install the RhoConnect Gem.
56
+
57
+ Run this command to install.
25
58
 
26
59
  :::term
27
- $ [sudo] gem install rhoconnect
60
+ $ [sudo] gem install rhoconnect
61
+
62
+ NOTE: If you get any `no such file to load -- something` messages while running the rake tasks or rhodes commands, this can usually be resolved by putting "sudo" in front of the command, as in `sudo gem install something`.
63
+
64
+ RhoSimulator, which comes with RhoStudio for Mac and Windows, does not work with Linux.
data/doc/java-plugin.txt CHANGED
@@ -1,39 +1,86 @@
1
1
  RhoConnect-Java
2
2
  ===
3
3
 
4
- RhoConnect-Java library is designed for the [RhoConnect](http://rhomobile.com/products/rhoconnect/) App Integration Server.
4
+ RhoConnect-Java library is designed for the [RhoConnect](http://rhomobile.com/products/rhoconnect/) Application Integration Server.
5
5
 
6
- Using the RhoConnect-Java plugin, your [Spting 3 MVC](http://www.springsource.org/) application's data will transparently synchronize with a mobile application built on the [Rhodes framework](http://rhomobile.com/products/rhodes), or any of the available [RhoConnect clients](http://rhomobile.com/products/rhoconnect/).
6
+ Using the RhoConnect-Java plugin, your [Spring 3 MVC](http://www.springsource.org/) application's data will transparently synchronize with a mobile application built on the [Rhodes framework](http://rhomobile.com/products/rhodes), or any of the available [RhoConnect clients](http://rhomobile.com/products/rhoconnect/).
7
+
8
+ ## Prerequisites
9
+
10
+ * Java (1.6)
11
+ * Maven2 (2.2.1)
12
+ * Git
13
+ * [Rhoconncect-java](https://github.com/downloads/rhomobile/rhoconnect-java/rhoconnect-java-1.0-SNAPSHOT.jar) plugin jar file
7
14
 
8
15
  ## Getting started
9
16
 
10
17
  We assume that you have a complete java end-to-end application using Spring 3.0 MVC as the front end technology and Hibernate as backend ORM. For this application we will also use Maven2 for build and dependency management and some database to persist the data. The database is accessed by a Data Access (DAO) layer.
11
18
 
12
- For testing and evaluation purposes you can use [RhoconnectJavaSample](https://github.com/shurab/RhoconnectJavaSample) application as a starting point before continuing with the following steps.
19
+ Copy [Rhoconncect-java](https://github.com/downloads/rhomobile/rhoconnect-java/rhoconnect-java-1.0-SNAPSHOT.jar) plugin jar file to your PC.
20
+ You can also create target rhoconnect-java plugin jar from sources by cloning rhoconnect-java repository
21
+
22
+ :::term
23
+ $ git clone git@github.com:rhomobile/rhoconnect-java.git
24
+
25
+ and executing in cloned project directory the following commands:
26
+
27
+ :::term
28
+ $ mvn clean
29
+ $ mvn compile
30
+ $ mvn jar:jar
31
+
32
+ The archived rhoconnect-java-x.y.z.jar file will be created in the project target/ directory.
33
+
34
+ For testing and evaluation purposes you can use [RhoconnectJavaSample](https://github.com/shurab/RhoconnectJavaSample) application as a starting point before continuing with the following steps.
13
35
 
14
36
  ### Adding Dependencies to Your Maven 2 Project
15
37
 
16
- Add dependencies to your Apache Maven 2 project object model (POM): apache common beanutils, and Jackson JSON mapper. In the RhoconnectJavaSample application, this code is in the pom.xml file.
38
+ Add dependencies to your Apache Maven 2 project object model (POM): log4j, Apache common beanutils, and Jackson JSON mapper. In the RhoconnectJavaSample application, this code is in the pom.xml file.
17
39
 
18
40
  :::xml
19
- <!-- apache commons beanutils -->
20
- <dependency>
21
- <groupId>commons-beanutils</groupId>
22
- <artifactId>commons-beanutils</artifactId>
23
- <version>1.8.3</version>
41
+ <!-- Log4j -->
42
+ <dependency>
43
+ <groupId>log4j</groupId>
44
+ <artifactId>log4j</artifactId>
45
+ <version>1.2.9</version>
46
+ <type>jar</type>
47
+ <optional>false</optional>
48
+ </dependency>
49
+ <!-- Apache Commons Beanutils and Jackson JSON Mapper required by rhoconnect-java plugin -->
50
+ <dependency>
51
+ <groupId>commons-beanutils</groupId>
52
+ <artifactId>commons-beanutils</artifactId>
53
+ <version>1.8.3</version>
24
54
  </dependency>
25
- <!-- Jackson JSON Mapper -->
26
55
  <dependency>
27
56
  <groupId>org.codehaus.jackson</groupId>
28
57
  <artifactId>jackson-mapper-asl</artifactId>
29
58
  <version>1.9.0</version>
30
59
  <type>jar</type>
31
60
  <optional>false</optional>
32
- </dependency>
61
+ </dependency>
62
+
63
+ You must also add the rhoconnect-java jar to your Maven 2 project. At this moment rhoconnect-plugin jar is not available in Maven public repositories and you need install the jar manually into your Maven's local repository.
64
+ Download the `rhoconnect-java-1.0-SNAPSHOT.jar` jar file and put it into your hard drive, and issue the following Maven's command:
65
+
66
+ :::term
67
+ $ mvn install:install-file -Dfile=/path-to-jar/rhoconnect-java-1.0-SNAPSHOT.jar -DgroupId=com.rhomobile.rhoconnect -DartifactId=rhoconnect-java -Dversion=1.0-SNAPSHOT -Dpackaging=jar
68
+
69
+ Now, the `rhoconnect-java` jar library is included into your Maven local repository.
70
+ In the RhoconnectJavaSample application, you would add this code to the pom.xml file.
71
+
72
+ :::xml
73
+ <!-- Rhoconnect-java plugin -->
74
+ <dependency>
75
+ <groupId>com.rhomobile.rhoconnect</groupId>
76
+ <artifactId>rhoconnect-java</artifactId>
77
+ <version>1.0-SNAPSHOT</version>
78
+ <type>jar</type>
79
+ </dependency>
33
80
 
34
81
  ### Updating Your Servlet XML Configuration File
35
82
 
36
- Update your servlet xml configuration file to include rhoconnect-java metadata: the packages, converters, and beans. In the RhoconnectJavaSample, this code is in comments in the src/main/webapp/WEB-INF/spring-servlet.xml file.
83
+ Update your servlet xml configuration file to include rhoconnect-java metadata: the packages, converters, and beans. In the RhoconnectJavaSample, the following code is added to src/main/webapp/WEB-INF/spring-servlet.xml file.
37
84
 
38
85
  :::xml
39
86
  <!-- rhoconnect-java plugin packages -->
@@ -49,14 +96,11 @@ Update your servlet xml configuration file to include rhoconnect-java metadata:
49
96
  </list>
50
97
  </property>
51
98
  </bean>
52
-
53
99
  <bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
54
100
  <property name="supportedMediaTypes" value="application/json" />
55
101
  </bean>
56
-
57
102
  <bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
58
103
  </bean>
59
-
60
104
  <bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
61
105
  <property name="messageConverters">
62
106
  <list>
@@ -67,14 +111,16 @@ Update your servlet xml configuration file to include rhoconnect-java metadata:
67
111
  </bean>
68
112
 
69
113
  <!-- rhoconnect-java plugin beans -->
70
- <bean id="rhoconnect" class = "com.rhomobile.rhoconnect.RhoconnectImpl" />
71
-
114
+ <bean id="dispatcher" class = "com.rhomobile.rhoconnect.RhoconnectDispatcher"></bean>
72
115
  <bean id="rhoconnectClient" class = "com.rhomobile.rhoconnect.RhoconnectClient" init-method="setAppEndpoint" >
73
116
  <property name="restTemplate"><ref bean="restTemplate"/></property>
74
117
  <property name="endpointUrl" value="your_rhoconnect_server_url" />
75
118
  <property name="appEndpoint" value="your_spring_app_url" />
76
119
  <property name="apiToken" value="rhoconnect_api_token" />
77
120
  </bean>
121
+
122
+ <!--The following bean handles the application's authentication routine and should be implemented by you -->
123
+ <bean id="authenticate" class = "com.rhomobile.contact.ContactAuthenticate" />
78
124
 
79
125
  The `setAppEndpoint` method in the `rhoconnectClient` bean in the above code sample is a main point in establishing the communication
80
126
  link between the `Rhoconnect` server and the Spring 3 MVC application. It has the following properties that you need to configure.
@@ -82,208 +128,202 @@ link between the `Rhoconnect` server and the Spring 3 MVC application. It has th
82
128
  <table border="1">
83
129
  <tr>
84
130
  <td><code>endpointUrl</code></td>
85
- <td>rhoconnect server's url, for example <code>http://localhost:9292</code>.</td>
131
+ <td>rhoconnect server's url, for example <code>http://localhost:9292</code></td>
86
132
  </tr>
87
133
  <tr>
88
134
  <td><code>appEndpoint</code></td>
89
- <td>your Spring 3 MVC app url, for example <code>http://localhost:8080/contacts</code>.</td>
135
+ <td>your Spring 3 MVC app url, for example <code>http://localhost:8080/contacts</code></td>
90
136
  </tr>
91
137
  <tr>
92
138
  <td><code>apiToken</code></td>
93
- <td>rhoconnect server's api_token, for example <code>sometokenforme</code>.</td>
139
+ <td>rhoconnect server's api_token, for example <code>sometokenforme</code></td>
94
140
  </tr>
95
141
  </table>
96
142
 
97
-
98
- ### Adding rhoconnect-java to the Build Path
99
-
100
- You must add the rhoconnect-java jar to your apache maven 2 build classpath. In the RhoconnectJavaSample application, you would add this code to the pom.xml file, putting in the path to your rhoconnect-java jar into the systemPath.
101
-
102
- :::xml
103
- <dependency>
104
- <groupId>rhoconnect-java</groupId>
105
- <artifactId>rhoconnect-java</artifactId>
106
- <version>0.0.1</version>
107
- <scope>system</scope>
108
- <!-- Set absolute path to your rhoconnect-java jar -->
109
- <systemPath>/path-to-jar-directory/rhoconnect-java-0.0.1.jar</systemPath>
110
- </dependency>
111
-
112
-
113
- ### Establishing communication from the RhoConnect server to java back-end application
114
-
115
- You need to establish communication from the RhoConnect instance to your java back-end application by implementing Rhoconnect interface.
143
+ The `authenticate` bean will be called by rhoconnect server to authenticate users, and has to implement `Rhoconnect` interface provided by rhoconnect-java plugin:
116
144
 
117
145
  :::java
118
146
  package com.rhomobile.rhoconnect;
119
147
  import java.util.Map;
120
148
 
121
149
  public interface Rhoconnect {
122
- boolean authenticate(String login, String password, Map<String, Object> attribures);
123
-
124
- Map<String, Object> query_objects(String resource, String partition);
125
- Integer create(String resource, String partition, Map<String, Object> attributes);
126
- Integer update(String resource, String partition, Map<String, Object> attributes);
127
- Integer delete(String resource, String partition, Map<String, Object> attributes);
150
+ boolean authenticate(String login, String password, Map<String, Object> attributes);
128
151
  }
129
152
 
130
- For example, `RhoconnectJavaSample` application implementation is based on `contactService` API:
153
+ For example:
131
154
 
132
155
  :::java
133
- /**
134
- * RhoconnectImpl.java
135
- */
136
- package com.rhomobile.rhoconnect;
156
+ package com.rhomobile.contact;
137
157
 
138
- import java.util.HashMap;
139
- import java.util.Iterator;
140
- import java.util.List;
141
158
  import java.util.Map;
159
+ import org.apache.log4j.Logger;
160
+ import com.rhomobile.rhoconnect.Rhoconnect;
142
161
 
143
- import org.apache.commons.beanutils.BeanUtils;
144
- import org.springframework.beans.factory.annotation.Autowired;
145
-
146
- import com.rhomobile.contact.form.Contact;
147
- import com.rhomobile.contact.service.ContactService;
148
-
149
- public class RhoconnectImpl implements Rhoconnect {
150
-
151
- @Autowired
152
- private ContactService contactService;
162
+ public class ContactAuthenticate implements Rhoconnect {
163
+ private static final Logger logger = Logger.getLogger(ContactAuthenticate.class);
153
164
 
154
165
  @Override
155
- public boolean authenticate(String login, String password, Map<String, Object> attribures) {
166
+ public boolean authenticate(String login, String password, Map<String, Object> attributes) {
167
+ logger.info("ContactAuthenticate#authenticate: implement your authentication code!");
156
168
  // TODO: your authentication code goes here ...
157
169
  return true;
158
170
  }
159
-
160
- @Override
161
- public Map<String, Object> query_objects(String resource, String partition) {
162
- Map<String, Object> h = new HashMap<String, Object>();
163
- List<Contact> contacts = contactService.listContact();
164
- Iterator<Contact> it = contacts.iterator( );
165
- while(it.hasNext()) {
166
- Contact c =(Contact)it.next();
167
- h.put(c.getId().toString(), c);
168
- }
169
- return h;
170
- }
171
-
172
- @Override
173
- public Integer create(String resource, String partition, Map<String, Object> attributes) {
174
- Contact contact = new Contact();
175
- try {
176
- BeanUtils.populate(contact, attributes);
177
- int id = contactService.addContact(contact);
178
- return id;
179
- } catch(Exception e) {
180
- e.printStackTrace();
181
- }
182
- return null;
183
- }
184
-
185
- @Override
186
- public Integer update(String resource, String partition, Map<String, Object> attributes) {
187
- Integer id = Integer.parseInt((String)attributes.get("id"));
188
- Contact contact = contactService.getContact(id);
189
- try {
190
- BeanUtils.populate(contact, attributes);
191
- contactService.updateContact(contact);
192
- return id;
193
- } catch(Exception e) {
194
- e.printStackTrace();
195
- }
196
- return null;
197
- }
198
-
199
- @Override
200
- public Integer delete(String resource, String partition, Map<String, Object> attributes) {
201
- String objId = (String)attributes.get("id");
202
- Integer id = Integer.parseInt(objId);
203
- contactService.removeContact(id);
204
- return id;
205
- }
206
171
  }
207
172
 
208
- ### Establishing communication from java back-end application to the RhoConnect server
209
-
210
- You also must to establish the communication from your java back-end application to the RhoConnect instance by autowiring your data access (DAO) service layer with RhoconnectClient bean and inserting notifications hooks there.
211
-
212
- :::java
213
- package com.rhomobile.rhoconnect;
214
-
215
- public class RhoconnectClient {
216
- // ...
217
- public boolean notifyOnCreate(String sourceName, String partition, Object objId, Object object);
218
- public boolean notifyOnUpdate(String sourceName, String partition, Object objId, Object object);
219
- public boolean notifyOnDelete(String sourceName, String partition, Object objId);
220
- // ...
221
- }
173
+ ### Establishing communication from the RhoConnect server to java back-end application
222
174
 
223
- For example, `RhoconnectJavaSample` application uses the following implementation:
175
+ You need to establish communication from the RhoConnect instance to your java back-end application by mixing RhoconnectResource interface in your data access (DAO) service class:
224
176
 
225
177
  :::java
226
- package com.rhomobile.contact.service;
227
- import java.util.List;
228
-
229
- import org.springframework.beans.factory.annotation.Autowired;
230
- import org.springframework.stereotype.Service;
231
- import org.springframework.transaction.annotation.Transactional;
178
+ package com.rhomobile.rhoconnect;
232
179
 
233
- import com.rhomobile.contact.dao.ContactDAO;
234
- import com.rhomobile.contact.form.Contact;
180
+ import java.util.Map;
235
181
 
236
- import com.rhomobile.rhoconnect.RhoconnectClient;
237
- //import org.apache.log4j.Logger;
182
+ public interface RhoconnectResource {
183
+ Map<String, Object> rhoconnectQuery(String partition);
184
+ Integer rhoconnectCreate(String partition, Map<String, Object> attributes);
185
+ Integer rhoconnectUpdate(String partition, Map<String, Object> attributes);
186
+ Integer rhoconnetDelete(String partition, Map<String, Object> attributes);
187
+ String getPartition();
188
+ }
238
189
 
239
- @Service
240
- public class ContactServiceImpl implements ContactService {
190
+ To help rhoconnect-java plugin correctly do mapping of model name to service bean you should take into account the following conventions:
241
191
 
242
- @Autowired
243
- private ContactDAO contactDAO;
244
-
245
- @Autowired
246
- private RhoconnectClient client;
247
-
248
- //private static final Logger logger = Logger.getLogger(ContactServiceImpl.class);
249
-
250
- private static final String sourceName = "Contact"; // name of DAO model
251
-
252
- // Data partitioning: i.e. your user name for filtering data on per user basis
253
- private static final String partition = "your_partition";
254
-
255
- @Transactional
256
- public int addContact(Contact contact) {
257
- int id = contactDAO.addContact(contact);
258
- client.notifyOnCreate(sourceName, partition, Integer.toString(id), contact);
259
- return id;
260
- }
192
+ * Name of the DAO service bean (class) should be model name followed by `ServiceImpl` suffix (i. e. `ContactServiceImpl` for model `Contact`)
193
+ * Service bean should be auto-wired into corresponding controller via @Autowired annotation
261
194
 
262
- @Transactional
263
- public void updateContact(Contact contact) {
264
- contactDAO.updateContact(contact);
265
- client.notifyOnUpdate(sourceName, partition, Integer.toString(contact.getId()), contact);
266
- }
195
+ Data partitioning in your code should be based on filtering data for unique user (i.e. your user name) or per application (shared dataset for all users).
196
+ For more information about RhoConnect partitions, please refer to the [RhoConnect docs](http://docs.rhomobile.com/rhosync/source-adapters#data-partitioning).
267
197
 
268
- @Transactional
269
- public void removeContact(Integer id) {
270
- contactDAO.removeContact(id);
271
- client.notifyOnDelete(sourceName, partition, Integer.toString(id));
272
- }
198
+ ### Establishing communication from java back-end application to the RhoConnect server
273
199
 
274
- @Transactional
275
- public List<Contact> listContact() {
276
- return contactDAO.listContact();
277
- }
200
+ You also must to establish the communication from your java back-end application to the RhoConnect instance by auto-wiring `RhoconnectClient` bean into your DAO service class and inserting notifications hooks into data access (create/update/delete) methods.
201
+ `RhoconnectClient` bean is provided by rhoconnect-java plugin and responds to the following methods you have to call:
278
202
 
279
- @Transactional
280
- public Contact getContact(Integer id) {
281
- return contactDAO.getContact(id);
282
- }
283
- }
203
+ * boolean notifyOnCreate(String sourceName, String partition, Object objId, Object object)
204
+ * boolean notifyOnUpdate(String sourceName, String partition, Object objId, Object object)
205
+ * boolean notifyOnDelete(String sourceName, String partition, Object objId)
284
206
 
285
- For more information about RhoConnect partitions, please refer to the [RhoConnect docs](http://docs.rhomobile.com/rhosync/source-adapters#data-partitioning).
207
+ Example for `RhoconnectJavaSample` application:
286
208
 
209
+ :::java
210
+ package com.rhomobile.contact.service;
211
+
212
+ import java.util.HashMap;
213
+ import java.util.Iterator;
214
+ import java.util.List;
215
+ import java.util.Map;
216
+
217
+ import org.apache.commons.beanutils.BeanUtils;
218
+ import org.springframework.beans.factory.annotation.Autowired;
219
+ import org.springframework.stereotype.Service;
220
+ import org.springframework.transaction.annotation.Transactional;
221
+
222
+ import com.rhomobile.contact.dao.ContactDAO;
223
+ import com.rhomobile.contact.form.Contact;
224
+
225
+ import com.rhomobile.rhoconnect.RhoconnectClient;
226
+ import com.rhomobile.rhoconnect.RhoconnectResource;
227
+
228
+ @Service
229
+ public class ContactServiceImpl implements ContactService, RhoconnectResource {
230
+ //private static final Logger logger = Logger.getLogger(ContactServiceImpl.class);
231
+
232
+ @Autowired
233
+ private ContactDAO contactDAO;
234
+ @Autowired
235
+ private RhoconnectClient client;
236
+ private static final String sourceName = "Contact"; // name of DAO model
237
+
238
+ @Transactional
239
+ public int addContact(Contact contact) {
240
+ int id = contactDAO.addContact(contact);
241
+ client.notifyOnCreate(sourceName, getPartition(), Integer.toString(id), contact);
242
+ return id;
243
+ }
244
+
245
+ @Transactional
246
+ public void updateContact(Contact contact) {
247
+ contactDAO.updateContact(contact);
248
+ client.notifyOnUpdate(sourceName, getPartition(), Integer.toString(contact.getId()), contact);
249
+ }
250
+
251
+ @Transactional
252
+ public void removeContact(Integer id) {
253
+ contactDAO.removeContact(id);
254
+ client.notifyOnDelete(sourceName, getPartition(), Integer.toString(id));
255
+ }
256
+
257
+ @Transactional
258
+ public List<Contact> listContact() {
259
+ return contactDAO.listContact();
260
+ }
261
+
262
+ @Transactional
263
+ public Contact getContact(Integer id) {
264
+ return contactDAO.getContact(id);
265
+ }
266
+
267
+ @Override
268
+ @Transactional
269
+ public Map<String, Object> rhoconnectQuery(String partition) {
270
+ Map<String, Object> h = new HashMap<String, Object>();
271
+ List<Contact> contacts = listContact();
272
+
273
+ Iterator<Contact> it = contacts.iterator( );
274
+ while(it.hasNext()) {
275
+ Contact c =(Contact)it.next();
276
+ h.put(c.getId().toString(), c);
277
+ }
278
+ return h;
279
+ }
280
+
281
+ @Override
282
+ @Transactional
283
+ public Integer rhoconnectCreate(String partition, Map<String, Object> attributes) {
284
+ Contact contact = new Contact();
285
+ try {
286
+ BeanUtils.populate(contact, attributes);
287
+ int id = addContact(contact);
288
+ return id;
289
+ } catch(Exception e) {
290
+ e.printStackTrace();
291
+ }
292
+ return null;
293
+ }
294
+
295
+ @Override
296
+ @Transactional
297
+ public Integer rhoconnectUpdate(String partition, Map<String, Object> attributes) {
298
+ Integer id = Integer.parseInt((String)attributes.get("id"));
299
+ Contact contact = getContact(id);
300
+ try {
301
+ BeanUtils.populate(contact, attributes);
302
+ updateContact(contact);
303
+ return id;
304
+ } catch(Exception e) {
305
+ e.printStackTrace();
306
+ }
307
+ return null;
308
+ }
309
+
310
+ @Override
311
+ @Transactional
312
+ public Integer rhoconnetDelete(String partition, Map<String, Object> attributes) {
313
+ String objId = (String)attributes.get("id");
314
+ Integer id = Integer.parseInt(objId);
315
+ removeContact(id);
316
+ return id;
317
+ }
318
+
319
+ @Override
320
+ public String getPartition() {
321
+ // Data partitioning: i.e. your user name for filtering data on per user basis
322
+ return "alexb";
323
+ }
324
+ }
325
+
326
+ Click [here](https://github.com/shurab/RhoconnectJavaPluginDemo) to download full source code of Contact manager application with rhoconnect-java plugin.
287
327
 
288
328
  ## Meta
289
329
  Created and maintained by Alexander Babichev.