The third party integration sample shows how to communicate with the client using external tools. This may be achieved by offering a custom javascript interface or adding a local web service to the client.
Besides the standard XML Automate interface and the default javascript interface, developers may create their own extensions to offer additional options to communitcate with the client using javascript or SOAP based web services.
Whenever an extension to the default javascript interface is needed, a new ScriptingObject must be created extending the AbstractScriptingObject or implementing the IScriptingObject interface.
In this sample there is a simple method getHalloWorldString() that might be called using javascript using window.MyJavascriptInterface.getHalloWorldString():
@ScriptingObject(name = "MyJavascriptInterface") public class JavascriptInterface extends AbstractScriptingObject { public JavascriptInterface() { super(); myPublicBooleanValue = false; } public boolean myPublicBooleanValue; /** * This method can be called by window.MyJavascriptInterface.getHalloWorldString() in your Javascript * * @return */ public String getHalloWorldString() { return "Hallo World String!"; } }
The SoapInterface is a local endpoint that is exposed on the client side as a standard SOAP based web service. Using this strategy it is possible to offer a standardized interface that may be called from any other application that is capable of consuming a web service:
@WebService(serviceName="SoapEndpointSample", portName="SoapEndpointSamplePort", endpointInterface="com.hgdn.gmsc.web.sdk.thirdparty.publish.soap.endpoint.SoapEndpointSample") @BindingType(SOAPBinding.SOAP11HTTP_BINDING) public class SoapEndpointSample { @Oneway public void showConfirmDialogAsynchron(@WebParam(name = "confirmMessage") String confirmMessage) { boolean confirmResult = GUIToolkit.showConfirmDialog(confirmMessage); Log.getLogger().log(Level.INFO, String.format("The result of the confirm dialog is '%s'", confirmResult)); } public boolean showConfirmDialogSynchron(@WebParam(name = "confirmMessage") String confirmMessage) { return GUIToolkit.showConfirmDialog(confirmMessage); } }
This web service itself is quite simple and only offers methods to open a confirm dialog containing a meesage that was sent from the connected client.
Besides the web service itself, a plugin must be created that takes care of hosting the service and publishes the endpoint:
@Plugin(alias = "EndpointPlugin", vendor = "Hexagon Geospatial") public class EndpointPlugin extends AbstractPlugin { private static final String SOAP_ENDPOINT_ADRESS ="http://localhost:8091/MySoapInterface"; private Endpoint endpoint; @Override public void start() throws Exception { endpoint = Endpoint.publish(SOAP_ENDPOINT_ADRESS, new SoapEndpointSample()); if (endpoint.isPublished()) { Log.getLogger().finest("The soap endpoint is now ready! ( " + SOAP_ENDPOINT_ADRESS + " )"); } else { Log.getLogger().finest("The soap endpoint isn't ready!"); } } @Override public void stop() throws Exception { endpoint.stop(); } }
To test the javascript interface and the web service, please find a simple have a look at the ThirdPartyIntergrationTest project: https://bitbucket.org/HGDN/hgdn_gmsc/src/5ee4237a7bf2c454e43861470eeaa5786bdae49d/Client/ThirdPartyI...