Example usage for com.liferay.portal.kernel.messaging DestinationNames IP_GEOCODER

List of usage examples for com.liferay.portal.kernel.messaging DestinationNames IP_GEOCODER

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.messaging DestinationNames IP_GEOCODER.

Prototype

String IP_GEOCODER

To view the source code for com.liferay.portal.kernel.messaging DestinationNames IP_GEOCODER.

Click Source Link

Usage

From source file:com.liferay.client.json.ipgeocoder.util.IPGeocoderUtil.java

License:Open Source License

public static IPInfo getIPInfo(String ipAddress) throws PortalException {
    Object response = MessageBusUtil.sendSynchronousMessage(DestinationNames.IP_GEOCODER, ipAddress);

    if (!(response instanceof JSONObject)) {
        return null;
    }/*from   w  w w.j  a  v  a  2  s  . c  om*/

    JSONObject ipInfoJSON = (JSONObject) response;

    if (ipInfoJSON == null) {
        return null;
    }

    float latitude = GetterUtil.getFloat(ipInfoJSON.getString("latitude"));
    float longitude = GetterUtil.getFloat(ipInfoJSON.getString("longitude"));

    return new IPInfo(ipAddress, latitude, longitude);
}

From source file:com.liferay.ipgeocoder.servlet.IPGeocoderServletContextListener.java

License:Open Source License

@Override
protected void doPortalInit() {
    _ipGeocoderDestination = new ParallelDestination(DestinationNames.IP_GEOCODER);

    MessageBusUtil.addDestination(_ipGeocoderDestination);

    _ipGeocoderMessageListener = new IPGeocoderMessageListener();

    _ipGeocoderDestination.register(_ipGeocoderMessageListener);

    Destination ipGeocoderResponseDestination = new ParallelDestination(DestinationNames.IP_GEOCODER_RESPONSE);

    MessageBusUtil.addDestination(ipGeocoderResponseDestination);
}