Example usage for com.liferay.portal.kernel.messaging MessageBusUtil sendSynchronousMessage

List of usage examples for com.liferay.portal.kernel.messaging MessageBusUtil sendSynchronousMessage

Introduction

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

Prototype

public static Object sendSynchronousMessage(String destinationName, Object payload) throws MessageBusException 

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;
    }/*w  ww.ja 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.client.json.ruon.util.RUONUtil.java

License:Open Source License

public static List<Presence> getPresences(long userId, Locale locale) throws PortalException {

    Message message = new Message();

    message.put("command", "getPresences");
    message.put("userId", userId);
    message.put("locale", locale);

    JSONObject responseJSON = (JSONObject) MessageBusUtil.sendSynchronousMessage(DestinationNames.RUON,
            message);//from  w ww. ja v  a 2 s  .c  o  m

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

    JSONArray presencesJSON = responseJSON.getJSONArray("presencesJSON");

    if ((presencesJSON == null) || (presencesJSON.length() == 0)) {
        return null;
    }

    List<Presence> presences = new ArrayList<Presence>();

    for (int i = 0; i < presencesJSON.length(); i++) {
        JSONObject presenceJSON = presencesJSON.getJSONObject(i);

        String output = presenceJSON.getString("output");

        Presence presence = new Presence(userId, output);

        presences.add(presence);
    }

    return presences;
}

From source file:com.liferay.osb.scv.internal.jsonws.Cloud.java

License:Open Source License

public static void addDataSource(String name, String urlString, String login, String password)
        throws Exception {

    Message message = new Message();

    Map<String, Object> parameters = new HashMap<>();

    parameters.put("method", "addDataSource");
    parameters.put("name", name);
    parameters.put("url", urlString);
    parameters.put("login", login);
    parameters.put("password", password);

    message.setValues(parameters);/*from w  w  w.  j a v a2s  .  c o  m*/

    Object object = MessageBusUtil.sendSynchronousMessage(UserMapperDestinationNames.SCV_USER_MAPPER, message);

    // **** START DEV ONLY ****

    JSONWebServiceClient jsonWebServiceClient = new JSONWebServiceClientImpl();

    URL url = new URL(urlString);

    jsonWebServiceClient.setHostName(url.getHost());
    jsonWebServiceClient.setHostPort(url.getPort());
    jsonWebServiceClient.setLogin(login);
    jsonWebServiceClient.setPassword(password);

    Map<String, String> responseParameters = new HashMap<>();

    String mappingDataSourceId = String.valueOf(object);

    responseParameters.put("mappingDataSourceId", mappingDataSourceId);

    jsonWebServiceClient.doPost(urlString + "/set-mapping-data-source-id", responseParameters);

    getFields(Long.parseLong(mappingDataSourceId));

    // **** END DEV ONLY ****

}

From source file:com.liferay.osb.scv.internal.jsonws.Cloud.java

License:Open Source License

public static Object addDataSource(String name, String availableFields) throws Exception {

    Message message = new Message();

    Map<String, Object> parameters = new HashMap<>();

    parameters.put("method", "addDataSource");
    parameters.put("name", name);
    parameters.put("availableFields", availableFields);

    message.setValues(parameters);/*w ww  . j  a  v  a2  s.  co m*/

    return MessageBusUtil.sendSynchronousMessage(UserMapperDestinationNames.SCV_USER_MAPPER, message);
}

From source file:com.liferay.portlet.documentlibrary.util.AudioProcessorImpl.java

License:Open Source License

private void _queueGeneration(FileVersion fileVersion) {
    if (_fileVersionIds.contains(fileVersion.getFileVersionId()) || !isSupported(fileVersion)) {

        return;/*from  w w  w .j  ava2  s  . c o m*/
    }

    _fileVersionIds.add(fileVersion.getFileVersionId());

    if (PropsValues.DL_FILE_ENTRY_PROCESSORS_TRIGGER_SYNCHRONOUSLY) {
        try {
            MessageBusUtil.sendSynchronousMessage(DestinationNames.DOCUMENT_LIBRARY_AUDIO_PROCESSOR,
                    fileVersion);
        } catch (MessageBusException mbe) {
            if (_log.isWarnEnabled()) {
                _log.warn(mbe, mbe);
            }
        }
    } else {
        MessageBusUtil.sendMessage(DestinationNames.DOCUMENT_LIBRARY_AUDIO_PROCESSOR, fileVersion);
    }
}

From source file:com.liferay.portlet.documentlibrary.util.ImageProcessorImpl.java

License:Open Source License

private void _queueGeneration(FileVersion fileVersion) {
    if (!_fileVersionIds.contains(fileVersion.getFileVersionId()) && isSupported(fileVersion)
            && !_hasImages(fileVersion)) {
        _fileVersionIds.add(fileVersion.getFileVersionId());

        if (PropsValues.DL_FILE_ENTRY_PROCESSORS_TRIGGER_SYNCHRONOUSLY) {
            try {
                MessageBusUtil.sendSynchronousMessage(DestinationNames.DOCUMENT_LIBRARY_IMAGE_PROCESSOR,
                        fileVersion);//from ww w  .jav  a  2s  .c  o  m
            } catch (MessageBusException mbe) {
                if (_log.isWarnEnabled()) {
                    _log.warn(mbe, mbe);
                }
            }
        } else {
            MessageBusUtil.sendMessage(DestinationNames.DOCUMENT_LIBRARY_IMAGE_PROCESSOR, fileVersion);
        }
    }
}

From source file:com.liferay.portlet.documentlibrary.util.PDFProcessorImpl.java

License:Open Source License

private void _queueGeneration(FileVersion fileVersion) {
    if (_fileVersionIds.contains(fileVersion.getFileVersionId())) {
        return;//  ww  w.j ava 2 s.c  o  m
    }

    boolean generateImages = false;

    String extension = fileVersion.getExtension();

    if (extension.equals("pdf")) {
        generateImages = true;
    } else if (DocumentConversionUtil.isEnabled()) {
        String[] conversions = DocumentConversionUtil.getConversions(extension);

        for (String conversion : conversions) {
            if (conversion.equals("pdf")) {
                generateImages = true;

                break;
            }
        }
    }

    if (generateImages) {
        _fileVersionIds.add(fileVersion.getFileVersionId());

        if (PropsValues.DL_FILE_ENTRY_PROCESSORS_TRIGGER_SYNCHRONOUSLY) {
            try {
                MessageBusUtil.sendSynchronousMessage(DestinationNames.DOCUMENT_LIBRARY_PDF_PROCESSOR,
                        fileVersion);
            } catch (MessageBusException mbe) {
                if (_log.isWarnEnabled()) {
                    _log.warn(mbe, mbe);
                }
            }
        } else {
            MessageBusUtil.sendMessage(DestinationNames.DOCUMENT_LIBRARY_PDF_PROCESSOR, fileVersion);
        }
    }
}

From source file:com.liferay.portlet.documentlibrary.util.VideoProcessorImpl.java

License:Open Source License

private void _queueGeneration(FileVersion fileVersion) {
    if (_fileVersionIds.contains(fileVersion.getFileVersionId()) || !isSupported(fileVersion)) {

        return;//from   w  w  w.  j  av a 2 s  .com
    }

    _fileVersionIds.add(fileVersion.getFileVersionId());

    if (PropsValues.DL_FILE_ENTRY_PROCESSORS_TRIGGER_SYNCHRONOUSLY) {
        try {
            MessageBusUtil.sendSynchronousMessage(DestinationNames.DOCUMENT_LIBRARY_VIDEO_PROCESSOR,
                    fileVersion);
        } catch (MessageBusException mbe) {
            if (_log.isWarnEnabled()) {
                _log.warn(mbe, mbe);
            }
        }
    } else {
        MessageBusUtil.sendMessage(DestinationNames.DOCUMENT_LIBRARY_VIDEO_PROCESSOR, fileVersion);
    }
}

From source file:com.liferay.testpacl.util.TestPACLUtil.java

License:Open Source License

public static Map<String, Boolean> testMessageBusThread(long userId) throws Exception {

    Message message = new Message();

    message.put("userId", userId);

    return (Map<String, Boolean>) MessageBusUtil.sendSynchronousMessage("liferay/test_pacl", message);
}