This archive contains the API Proxy configuration files in the devicesync-proxy/ directory for setting up an Apigee proxy to use with Atlas Device Sync. The ApigeeTestApp/ directory contains the "todo" iOS template app that has been modified to work with the Apigee instance used for providing a demo of this capability.
The instructions below illustrate how this archive can be modified to work with your own template app and Apigee instance.
- Follow the instructions for Create an App Services App to create a template App Services App with Device Sync.
- Download the iOS template app. This can be used directly, or the contents of the App/atlasConfig.plist file will be needed for configuring the included sample iOS app.
- Follow the instructions to set up and configure the Apigee API proxy below and return here once the IP
address or hostname for the Apigee instance is available. The
clientApiBaseUrl
value from the App/atlasConfig.plist file will be needed when setting up the API proxy (e.g. for theUS-VA
deployment model, this value ishttps://us-east-1.aws.realm.mongodb.com
). - Update the App/atlasConfig.plist file in your own template app or the ApigeeTestApp directory based on the following configuration:
...
<dict>
<key>appId</key>
<string>DEVICE-SYNC-APP-ID</string>
...
<key>baseUrl</key>
<string>APIGEE-HOSTNAME-AND-PATH</string>
<key>clientApiBaseUrl</key>
<string>https://us-east-1.aws.realm.mongodb.com</string>
...
</dict>
</plist>
In the file contents above, the DEVICE-SYNC-APP-ID
value can be found in the App ID field on the
main DeviceSync page. The APIGEE-HOSTNAME-AND-PATH
value can be found in the Apigee instance
configuration as the values set for apigee-host
and apigee-prefix
, respectively. In the original
demo, this value was https://34.111.234.31.nip.io/device-sync
, where apigee-host
is
34.111.234.31.nip.io
and apigee-prefix
value is /device-sync
.
- Double-click on the .xcodeproj file in the iOS app to open it in XCode or open the directory directly in XCode.
- Click the run button to start the app - an iOS Simulator will be started and the app will run in that window.
NOTE: If the app has previously been run against Atlas Device Sync directly, the local realm file will need to be deleted or a new Simulator will need to be created (under Window->Devices and Simulators) and used for the new App run.
-
Start a new Debug Session in Apigee for the
devicesync-proxy
API Proxy so the flow through Apigee can be viewed. -
In the iOS app, either create a new user or log in using an existing user. The original demo used the
testuser@test.com
|t3stP4ss
ortestuser2@test.com
|t3stP4ss
credentials. -
In the Apigee Debug Session, the following message transfers should be seen:
- GET request to the **/location endpoint to retrieve the HTTP and WebSocket server addresses (this only occurs when the app is first started).
- GET request to the **/register endpoint if a new user is being created
- GET request to the **/login endpoint when the user logs in
- POST request to the **/profile endpoint to retrieve the user profile information
- GET requests to the **/realm-sync endpoint with a 101 response will be seen when a websocket is closed. These will be periodically while the app is running, likely due to an inactivity timeout imposed by Apigee. The websocket connection will be re-established by the iOS app after a second or two.
-
Create some new "todo" tasks by clicking the + button, entering an Item Name and clicking the Save button.
-
The new item will show in the main list and can be viewed in the
todo.item
Collection for the Deployment Database under the Data Services tab in the MongoDB portal. -
Click the Log Out button to log out the current user.
-
In the Apigee Debug Session a DELETE message to the **/session endpoint will be seen.
NOTE: Due to Apigee rejecting the 204 DELETE response since it contains the
Accept-Encoding
header value, the Apigee Proxy configuration includes aFaultRule
that will generate a "fake" 204 response that will be returned to the iOS App to confirm the logout operation.
-
If an Apigee instance has not already been configured, follow the steps in Get started in the Cloud Console to set up your Apigee instance. If necessary, be sure to select the options to register a hostname and configure TLS for the instance.
-
In the devicesync-proxy/apiproxy/resources/properties/devicesync.properties file, make the appropriate updates to match your Apigee and Atlas Device Sync configuration:
apigee-host
- update this value to the hostname for your Apigee instanceapigee-prefix
- update this value to your desired prefix for the API Proxy base pathsync-host
- update this value to the MongoDB hostname that matches your Device Sync deployment model. This can be found in theclientApiBaseUrl
value from the App/atlasConfig.plist file if a new iOS template app was downloaded. (e.g. theUS-VA
deployment model would behttps://us-east-1.aws.realm.mongodb.com
)
-
If the
apigee-prefix
was changed fromdevice-sync
, the following two files must also be modifed:- devicesync-proxy/apiproxy/proxies/default.xml - update the first part of the path in the
ProxyEndpoint
.HTTPProxyConnection
.BasePath
value to match the newapigee-prefix
value. - devicesync-proxy/apiproxy/devicesync-proxy.xml - update the first part of the path in the
APIProxy
.BasePaths
value to match the newapigee-prefix
value.
- devicesync-proxy/apiproxy/proxies/default.xml - update the first part of the path in the
NOTE: The remainder of the API Proxy base path (
/api/client/v2.0
) is required, since this is the first part of the path used by Device Sync client App when communicating with the server.
- In a terminal window, cd to the devicesync-apigee-test/devicesync-proxy/ directory and run the zip-devicesync-proxy.sh script to create a zip file containing the API Proxy configuration files.
- In the Apigee Console window, select API proxies from the left hand menu and click the CREATE button to create a new proxy.
- In the Create a proxy window, select the Upload proxy bundle template option, enter
devicesync-proxy
for the Proxy name and browse to the devicesync-apigee-test/devicesync-proxy/devicesync-proxy.zip to upload the zip archive. - To automatically deploy the API Proxy for immediate use, click the NEXT button and select the environment to deploy the API Proxy. Otherwise, the DEPLOY button can be used on the API Proxy details page.