IBM Worklight: Extend Server-side Java Code

2019-08-23 05:02发布

Can I extend the server-side Java Code in Worklight? For example, there is a class called JavaScriptIntegrationLibraryImplementation under com.worklight.integration.js. Inside this class, there is a method broadcastNotification and I would like to override this method. Is it possible to do so?

EDIT
The reason is that: When I make the subscription in client side with option field (e.g. add customType: A), I would like to retrieve a list of devices which have been subscribed to this event source. Base on the option field in deviceSubscrpition, I would like to have some business logic to determine who to send the notification message. For example, I will only submit the message to the user which 'customType=A'.

However, there is no API in Worklight which can retrieve a list of devices which make me to retrieve the list first. Then do the logic in JavaScript and called WL.Server.notifyDevice..

Therefore, I would like to check whether there is any method to retrieve a list of devices (through API / Adapter which connects to DB) which have subscribed to an event source.

Thanks.

2条回答
姐就是有狂的资本
2楼-- · 2019-08-23 05:24

This part of Worklight is not extendable. You can try and override this method as you say, but do note this is not supported and we cannot help in this case.

Edit

Now that it is clear what you're trying to achieve... what you are looking for currently not available. I will open a feature request for it and it will get evaluated at some point (if you are a customer of IBM, I suggest to get in touch with your contact...).

My suggestion (somewhat hackish in form): you could perhaps use multiple Event Sources, where each event source represents an iOS version. On the client-side, upon app initialization, you can retrieve the iOS version and use it to register to the correct event source (this would be very generic code to allow re-use). In case a new iOS version is released (you will likely know of this in advance), you simply add this event source to the adapter code and re-deploy the adapter. Users of the new iOS version could still register for notification, because you get the iOS version upon init, and use this information to register to the correct event source...

To reiterate:

The adapter contains: ES_iOS5 ES_iOS6

The client:

  • fetches iOS version, stores it in some variable.
  • registers to event source, where event source name is ES_${iOSVersion}
  • if a new iOS version is released, simply create a new event source and re-deploy the adapter; the client is already equipped to handle this.
查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-08-23 05:26

@Red23jordon,

i had similar case, i created a custom table where at the time of subscription, I was saving user ID and event type in custom table. and when user unsubscribe then i also remove details from custom table.

For sending push to users subscribed to a particular "even type" i look into custom table to get list of user IDs subscribed to particular event type, and then i went into Notification user/device tables and fetching corresponding devices and sending Push.

Hope it may help you.

thanks

查看更多
登录 后发表回答