Worklight アダプターは、Worklight モバイル・アプリケーション・プラットフォーム上にデプロイされ、このプラットフォームによってサービスが提供されるアプリケーションのサーバー・サイド・コードです。アダプターは Worklight Server をエンタープライズ・アプリケーション (WebSphere Message Broker で実行されるアプリケーションなど) に接続します。以下は、プロバイダー・アプリケーションからモバイル・アプリケーションまでの通知の送達の順序を示しています。
このセクションでは、Worklight アダプター用に生成されるファイルについて説明します。
このパターンは 2 つの構成ファイルを使用して Worklight アダプターを作成します。1 つ目の構成ファイルは、アダプター XML ファイルです。アダプター XML ファイルは、Message Broker への接続を構成するために使用されます。以下の例は、生成されるアダプター XML 構成ファイルを示します。
<?xml version="1.0" encoding="UTF-8"?> <wl:adapter name="PushAdapter" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wl="http://www.worklight.com/integration" xmlns:http="http://www.worklight.com/integration/http"> <displayName>PushAdapter</displayName> <description>Worklight: push notifications adapter</description> <connectivity> <connectionPolicy xsi:type="http:HTTPConnectionPolicyType"> <protocol>http</protocol> <domain>localhost</domain> <port>7800</port> </connectionPolicy> <loadConstraints maxConcurrentConnectionsPerNode="1" /> </connectivity> </wl:adapter>
このアダプター XML ファイル内の値の多くは、パターン・パラメーター (displayName
、domain
、port
など) から構成されます。
パターンは、通知アダプター実装を含む JavaScript ファイルも生成します。この生成ファイルの主なセクションは先頭にあり、アダプターがイベント・ソースを構成します。イベント・ソース名は、モバイル・アプリケーションがサブスクライブするイベント・ソース名に一致している必要があります。
WL.Server.createEventSource({ name : "PushEventSource", onDeviceSubscribe : "deviceSubscribeFunc", onDeviceUnsubscribe : "deviceUnsubscribeFunc", poll : { interval : 30, onPoll: "getNotifications" } });
以下に示す XML スキーマは、キューに配置される通知メッセージおよび Web サービスによって返される通知メッセージの形式を指定します。
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" xmlns:tns="urn://patterns/worklight" targetNamespace="urn://patterns/worklight"> <xsd:element name="GetNotification"> <xsd:annotation> <xsd:documentation xml:lang="en">Request message to get the next available pending notification.</xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:sequence> <xsd:element name="AdapterName" type="xsd:string"/> <xsd:element name="EventSource" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="GetNotificationResponse"> <xsd:annotation> <xsd:documentation xml:lang="en">Response message for next available pending notification.</xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:sequence> <xsd:element name="Notification" type="tns:Notification"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="PutNotification"> <xsd:annotation> <xsd:documentation xml:lang="en">Request message to add a pending notification message.</xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:sequence> <xsd:element name="Notification" type="tns:Notification"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="PutNotificationResponse"> <xsd:annotation> <xsd:documentation xml:lang="en">Response message for putting a pending notification messages.</xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:sequence> <xsd:element name="AdapterName" type="xsd:string"/> <xsd:element name="EventSource" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:complexType name="Payload"> <xsd:annotation> <xsd:documentation xml:lang="en">Application specific data in the notification messages.</xsd:documentation> </xsd:annotation> <xsd:sequence> </xsd:sequence> </xsd:complexType> <xsd:complexType name="Notification"> <xsd:annotation> <xsd:documentation xml:lang="en">Data definition for notification messages.</xsd:documentation> </xsd:annotation> <xsd:sequence> <xsd:element name="UserId" type="xsd:string"/> <xsd:element minOccurs="0" name="Badge" type="xsd:string"/> <xsd:element minOccurs="0" name="Sound" type="xsd:string"/> <xsd:element minOccurs="0" name="ActivateButtonLabel" type="xsd:string"/> <xsd:element minOccurs="0" name="NotificationText" type="xsd:string"/> <xsd:element minOccurs="0" name="Payload" type="tns:Payload"/> </xsd:sequence> </xsd:complexType> </xsd:schema>
Payload
エレメントには、パターンによって、追加のアプリケーション固有のフィールドの名前が指定されます。
以下に、プッシュ通知 Web サービス WSDL からの抜粋を示します。
<wsdl:definitions name="Notification" targetNamespace="urn://patterns/worklight" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="urn://patterns/worklight" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <wsdl:types> <xsd:schema targetNamespace="urn://patterns/worklight" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:include schemaLocation="Notification.xsd"/> </xsd:schema> </wsdl:types> <wsdl:message name="GetNotification"> <wsdl:part element="tns:GetNotification" name="GetNotification"/> </wsdl:message> <wsdl:message name="GetNotificationResponse"> <wsdl:part element="tns:GetNotificationResponse" name="GetNotificationResponse"/> </wsdl:message> <wsdl:message name="PutNotification"> <wsdl:part element="tns:PutNotification" name="PutNotification"/> </wsdl:message> <wsdl:message name="PutNotificationResponse"> <wsdl:part element="tns:PutNotificationResponse" name="PutNotificationResponse"/> </wsdl:message> <wsdl:portType name="NotificationPortType"> <wsdl:operation name="GetNotification"> <wsdl:input message="tns:GetNotification"/> <wsdl:output message="tns:GetNotificationResponse"/> </wsdl:operation> <wsdl:operation name="PutNotification"> <wsdl:input message="tns:PutNotification"/> <wsdl:output message="tns:PutNotificationResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="NotificationSOAPBinding" type="tns:NotificationPortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="GetNotification"> <soap:operation soapAction="http://notification/get"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="PutNotification"> <soap:operation soapAction="http://notification/put"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> </wsdl:definitions>
このパターンによって生成されるアダプターは、GetNotification
操作を使用して、保留中のプッシュ通知を Message Broker から取り出します。Web サービスは、PutNotification
操作も提供します。これは、メッセージをキューに書き込む代わりに Web サービスを呼び出すことによって、Message Broker を使用して通知をキューに入れることに適したプロバイダー・アプリケーション用の操作です。