Example usage for com.liferay.portal.kernel.messaging Message setResponseId

List of usage examples for com.liferay.portal.kernel.messaging Message setResponseId

Introduction

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

Prototype

public void setResponseId(String responseId) 

Source Link

Usage

From source file:com.liferay.exportimport.resources.importer.internal.messaging.ResourcesImporterHotDeployMessageListener.java

License:Open Source License

private void _importResources(Company company, ServletContext servletContext,
        PluginPackageProperties pluginPackageProperties, String messageResponseId) throws Exception {

    long companyId = CompanyThreadLocal.getCompanyId();

    try {/*from   w  w w  . j  av a  2s  . c o m*/
        CompanyThreadLocal.setCompanyId(company.getCompanyId());

        Importer importer = _importerFactory.createImporter(company.getCompanyId(), servletContext,
                pluginPackageProperties);

        if (!importer.isDeveloperModeEnabled() && importer.isExisting() && !importer.isCompanyGroup()) {

            if (_log.isInfoEnabled()) {
                _log.info(
                        "Group or layout set prototype already exists for " + "company " + company.getWebId());
            }

            return;
        }

        long startTime = 0;

        if (_log.isInfoEnabled()) {
            startTime = System.currentTimeMillis();
        }

        importer.importResources();

        if (_log.isInfoEnabled()) {
            StringBundler sb = new StringBundler(7);

            sb.append("Importing resources from ");
            sb.append(servletContext.getServletContextName());
            sb.append(" to group ");
            sb.append(importer.getGroupId());
            sb.append(" takes ");

            long endTime = System.currentTimeMillis() - startTime;

            sb.append(endTime);

            sb.append(" ms");

            _log.info(sb.toString());
        }

        Message message = new Message();

        message.put("companyId", company.getCompanyId());
        message.put("servletContextName", servletContext.getServletContextName());
        message.put("targetClassName", importer.getTargetClassName());
        message.put("targetClassPK", importer.getTargetClassPK());

        if (Validator.isNotNull(messageResponseId)) {
            Map<String, Object> responseMap = new HashMap<>();

            responseMap.put("groupId", importer.getTargetClassPK());

            message.setPayload(responseMap);

            message.setResponseId(messageResponseId);
        }

        MessageBusUtil.sendMessage("liferay/resources_importer", message);
    } catch (ImporterException ie) {
        Message message = new Message();

        message.put("companyId", company.getCompanyId());
        message.put("error", ie.getMessage());
        message.put("servletContextName", servletContext.getServletContextName());
        message.put("targetClassName", pluginPackageProperties.getTargetClassName());
        message.put("targetClassPK", 0);

        MessageBusUtil.sendMessage("liferay/resources_importer", message);
    } finally {
        CompanyThreadLocal.setCompanyId(companyId);
    }
}

From source file:com.liferay.mobile.camel.LiferayProducer.java

License:Open Source License

public void process(Exchange exchange) throws Exception {
    Object payload = exchange.getIn().getBody();

    if (_log.isDebugEnabled()) {
        _log.debug("LiferayProducer.process " + payload);
    }//from ww  w .ja  v a 2  s .  c  o m

    LiferayEndpoint endpoint = getEndpoint();
    MessageBus messageBus = endpoint.getMessageBus();
    String destinationName = endpoint.getDestinationName();

    Message message = new Message();
    message.setPayload(payload);

    String responseId = (String) exchange.getIn().getHeader("liferay-ResponseId");
    if (responseId != null) {
        message.setResponseId(responseId);
    }

    messageBus.sendMessage(destinationName, message);
}

From source file:com.liferay.osb.scv.internal.messaging.SourceUserMapperMessageListener.java

License:Open Source License

protected void sendResponse(String destinationName, String responseId, long mappingDataSourceId, String method,
        String fields) throws Exception {

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

    parameters.put("fields", fields);

    String response = JSONWebServiceClientUtil.doGet(mappingDataSourceId, method, parameters);

    Message message = new Message();

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

    values.put("method", method);

    message.setValues(values);/*from   www  .j a  v a2  s.c o  m*/

    message.setPayload(response);
    message.setResponseId(responseId);

    MessageBusUtil.sendMessage(destinationName, message);
}

From source file:com.liferay.osb.scv.user.mapper.internal.event.BaseEvent.java

License:Open Source License

@Override
public void run(Map<String, Object> parameters) {
    String responseId = generateUUID();

    EventManager.addEvent(responseId, this);

    Message message = new Message();

    message.setResponseId(responseId);
    message.setValues(parameters);//from w w  w. j a va2 s.co m

    message.setResponseDestinationName(UserMapperDestinationNames.SCV_USER_MAPPER);

    MessageBusUtil.sendMessage(UserMapperDestinationNames.SCV_SOURCE, message);
}

From source file:com.liferay.resourcesimporter.messaging.HotDeployMessageListener.java

License:Open Source License

protected void doReceive(Message message) throws Exception {
    String command = message.getString("command");

    if (!command.equals("deploy")) {
        return;/*from  w w w .  ja v  a2s  .  c o  m*/
    }

    String servletContextName = message.getString("servletContextName");

    ServletContext servletContext = ServletContextPool.get(servletContextName);

    URL resourcesDirURL = servletContext.getResource(_RESOURCES_DIR);

    if (resourcesDirURL == null) {
        return;
    }

    Properties pluginPackageProperties = getPluginPackageProperties(servletContext);

    String targetClassName = pluginPackageProperties.getProperty("resources-importer-target-class-name",
            LayoutSetPrototype.class.getName());

    Set<String> resourcePaths = servletContext.getResourcePaths(_RESOURCES_DIR);

    URL privateLARURL = null;
    URL publicLARURL = servletContext.getResource(_RESOURCES_DIR.concat("archive.lar"));

    if (publicLARURL == null) {
        privateLARURL = servletContext.getResource(_RESOURCES_DIR.concat("private.lar"));
        publicLARURL = servletContext.getResource(_RESOURCES_DIR.concat("public.lar"));
    }

    List<Company> companies = CompanyLocalServiceUtil.getCompanies();

    for (Company company : companies) {
        long companyId = CompanyThreadLocal.getCompanyId();

        try {
            CompanyThreadLocal.setCompanyId(company.getCompanyId());

            Importer importer = null;

            if ((privateLARURL != null) || (publicLARURL != null)) {
                LARImporter larImporter = getLARImporter();

                URLConnection privateLARURLConnection = null;

                if (privateLARURL != null) {
                    privateLARURLConnection = privateLARURL.openConnection();

                    larImporter.setPrivateLARInputStream(privateLARURLConnection.getInputStream());
                }

                URLConnection publicLARURLConnection = null;

                if (publicLARURL != null) {
                    publicLARURLConnection = publicLARURL.openConnection();

                    larImporter.setPublicLARInputStream(publicLARURLConnection.getInputStream());
                }

                importer = larImporter;
            } else if ((resourcePaths != null) && !resourcePaths.isEmpty()) {
                importer = getResourceImporter();

                importer.setResourcesDir(_RESOURCES_DIR);
            } else {
                String resourcesDir = pluginPackageProperties.getProperty("resources-importer-external-dir");

                if (Validator.isNotNull(resourcesDir)) {
                    importer = getFileSystemImporter();

                    importer.setResourcesDir(resourcesDir);
                }
            }

            if (importer == null) {
                throw new ImporterException("No valid importer found");
            }

            importer.setCompanyId(company.getCompanyId());
            importer.setServletContext(servletContext);
            importer.setServletContextName(servletContextName);
            importer.setTargetClassName(targetClassName);

            String targetValue = pluginPackageProperties.getProperty("resources-importer-target-value");

            if (Validator.isNull(targetValue)) {
                targetValue = TextFormatter.format(servletContextName, TextFormatter.J);
            }

            importer.setTargetValue(targetValue);

            importer.afterPropertiesSet();

            boolean developerModeEnabled = GetterUtil.getBoolean(
                    pluginPackageProperties.getProperty("resources-importer-developer-mode-enabled"));

            if (!developerModeEnabled && importer.isExisting()) {
                if (_log.isInfoEnabled()) {
                    _log.info("Group or layout set prototype already exists " + "for company "
                            + company.getWebId());
                }

                continue;
            }

            long startTime = 0;

            if (_log.isInfoEnabled()) {
                startTime = System.currentTimeMillis();
            }

            importer.importResources();

            if (_log.isInfoEnabled()) {
                long endTime = System.currentTimeMillis() - startTime;

                _log.info("Importing resources from " + servletContextName + " to group "
                        + importer.getGroupId() + " takes " + endTime + " ms");
            }

            Message newMessage = new Message();

            newMessage.put("companyId", company.getCompanyId());
            newMessage.put("servletContextName", servletContextName);
            newMessage.put("targetClassName", targetClassName);
            newMessage.put("targetClassPK", importer.getTargetClassPK());

            if (message.getResponseId() != null) {
                Map<String, Object> responseMap = new HashMap<String, Object>();

                responseMap.put("groupId", importer.getTargetClassPK());

                newMessage.setPayload(responseMap);

                newMessage.setResponseId(message.getResponseId());
            }

            MessageBusUtil.sendMessage("liferay/resources_importer", newMessage);
        } catch (ImporterException ie) {
            Message newMessage = new Message();

            newMessage.put("companyId", company.getCompanyId());
            newMessage.put("error", ie.getMessage());
            newMessage.put("servletContextName", servletContextName);
            newMessage.put("targetClassName", targetClassName);
            newMessage.put("targetClassPK", 0);

            MessageBusUtil.sendMessage("liferay/resources_importer", newMessage);
        } finally {
            CompanyThreadLocal.setCompanyId(companyId);
        }
    }
}

From source file:com.liferay.resourcesimporter.messaging.ResourcesImporterHotDeployMessageListener.java

License:Open Source License

private void importResources(Company company, ServletContext servletContext,
        PluginPackageProperties pluginPackageProperties, String messageResponseId) throws Exception {

    long companyId = CompanyThreadLocal.getCompanyId();

    try {//from  w  w  w.j a v  a 2s  .c  om
        CompanyThreadLocal.setCompanyId(company.getCompanyId());

        ImporterFactory importerFactory = ImporterFactory.getInstance();

        Importer importer = importerFactory.createImporter(company.getCompanyId(), servletContext,
                pluginPackageProperties);

        if (!importer.isDeveloperModeEnabled() && importer.isExisting() && !importer.isCompanyGroup()) {

            if (_log.isInfoEnabled()) {
                _log.info(
                        "Group or layout set prototype already exists " + "for company " + company.getWebId());
            }

            return;
        }

        long startTime = 0;

        if (_log.isInfoEnabled()) {
            startTime = System.currentTimeMillis();
        }

        importer.importResources();

        if (_log.isInfoEnabled()) {
            long endTime = System.currentTimeMillis() - startTime;

            _log.info("Importing resources from " + servletContext.getServletContextName() + " to group "
                    + importer.getGroupId() + " takes " + endTime + " ms");
        }

        Message message = new Message();

        message.put("companyId", company.getCompanyId());
        message.put("servletContextName", servletContext.getServletContextName());
        message.put("targetClassName", importer.getTargetClassName());
        message.put("targetClassPK", importer.getTargetClassPK());

        if (Validator.isNotNull(messageResponseId)) {
            Map<String, Object> responseMap = new HashMap<String, Object>();

            responseMap.put("groupId", importer.getTargetClassPK());

            message.setPayload(responseMap);

            message.setResponseId(messageResponseId);
        }

        MessageBusUtil.sendMessage("liferay/resources_importer", message);
    } catch (ImporterException ie) {
        Message message = new Message();

        message.put("companyId", company.getCompanyId());
        message.put("error", ie.getMessage());
        message.put("servletContextName", servletContext.getServletContextName());
        message.put("targetClassName", pluginPackageProperties.getTargetClassName());
        message.put("targetClassPK", 0);

        MessageBusUtil.sendMessage("liferay/resources_importer", message);
    } finally {
        CompanyThreadLocal.setCompanyId(companyId);
    }
}

From source file:com.liferay.resourcesimporter.servlet.ResourcesImporterServletContextListener.java

License:Open Source License

protected void initialize(Message message) throws Exception {
    String servletContextName = message.getString("servletContextName");

    ServletContext servletContext = ServletContextPool.get(servletContextName);

    URL url = servletContext.getResource(_RESOURCES_DIR);

    if (url == null) {
        return;//from  ww w  . ja v a 2s .  c  o m
    }

    Properties pluginPackageProperties = getPluginPackageProperties(servletContext);

    String targetClassName = pluginPackageProperties.getProperty("resources-importer-target-class-name",
            LayoutSetPrototype.class.getName());

    Set<String> resourcePaths = servletContext.getResourcePaths(_RESOURCES_DIR);

    URL privateLARURL = null;
    URL publicLARURL = servletContext.getResource(_RESOURCES_DIR.concat("archive.lar"));

    if (publicLARURL == null) {
        privateLARURL = servletContext.getResource(_RESOURCES_DIR.concat("private.lar"));
        publicLARURL = servletContext.getResource(_RESOURCES_DIR.concat("public.lar"));
    }

    List<Company> companies = CompanyLocalServiceUtil.getCompanies();

    for (Company company : companies) {
        long companyId = CompanyThreadLocal.getCompanyId();

        try {
            CompanyThreadLocal.setCompanyId(company.getCompanyId());

            Importer importer = null;

            if ((privateLARURL != null) || (publicLARURL != null)) {
                LARImporter larImporter = getLARImporter();

                URLConnection privateLARURLConnection = null;

                if (privateLARURL != null) {
                    privateLARURLConnection = privateLARURL.openConnection();

                    larImporter.setPrivateLARInputStream(privateLARURLConnection.getInputStream());
                }

                URLConnection publicLARURLConnection = null;

                if (publicLARURL != null) {
                    publicLARURLConnection = publicLARURL.openConnection();

                    larImporter.setPublicLARInputStream(publicLARURLConnection.getInputStream());
                }

                importer = larImporter;
            } else if ((resourcePaths != null) && !resourcePaths.isEmpty()) {
                importer = getResourceImporter();

                importer.setResourcesDir(_RESOURCES_DIR);
            } else {
                String resourcesDir = pluginPackageProperties.getProperty("resources-importer-external-dir");

                if (Validator.isNotNull(resourcesDir)) {
                    importer = getFileSystemImporter();

                    importer.setResourcesDir(resourcesDir);
                }
            }

            if (importer == null) {
                throw new ImporterException("No valid importer found");
            }

            importer.setCompanyId(company.getCompanyId());
            importer.setServletContext(servletContext);
            importer.setServletContextName(servletContextName);
            importer.setTargetClassName(targetClassName);

            String targetValue = pluginPackageProperties.getProperty("resources-importer-target-value");

            if (Validator.isNull(targetValue)) {
                targetValue = TextFormatter.format(servletContextName, TextFormatter.J);
            }

            importer.setTargetValue(targetValue);

            importer.afterPropertiesSet();

            boolean developerModeEnabled = GetterUtil.getBoolean(
                    pluginPackageProperties.getProperty("resources-importer-developer-mode-enabled"));

            if (!developerModeEnabled && importer.isExisting()) {
                if (_log.isInfoEnabled()) {
                    _log.info("Group or layout set prototype already exists " + "for company "
                            + company.getWebId());
                }

                continue;
            }

            long startTime = 0;

            if (_log.isInfoEnabled()) {
                startTime = System.currentTimeMillis();
            }

            importer.importResources();

            if (_log.isInfoEnabled()) {
                long endTime = System.currentTimeMillis() - startTime;

                _log.info("Importing resources from " + servletContextName + " to group "
                        + importer.getGroupId() + " takes " + endTime + " ms");
            }

            Message newMessage = new Message();

            newMessage.put("companyId", company.getCompanyId());
            newMessage.put("servletContextName", servletContextName);
            newMessage.put("targetClassName", targetClassName);
            newMessage.put("targetClassPK", importer.getTargetClassPK());

            if (message.getResponseId() != null) {
                Map<String, Object> responseMap = new HashMap<String, Object>();

                responseMap.put("groupId", importer.getTargetClassPK());

                newMessage.setPayload(responseMap);

                newMessage.setResponseId(message.getResponseId());
            }

            MessageBusUtil.sendMessage("liferay/resources_importer", newMessage);
        } catch (ImporterException ie) {
            Message newMessage = new Message();

            newMessage.put("companyId", company.getCompanyId());
            newMessage.put("error", ie.getMessage());
            newMessage.put("servletContextName", servletContextName);
            newMessage.put("targetClassName", targetClassName);
            newMessage.put("targetClassPK", 0);

            MessageBusUtil.sendMessage("liferay/resources_importer", newMessage);
        } finally {
            CompanyThreadLocal.setCompanyId(companyId);
        }
    }
}

From source file:se.vgregion.messagebus.MessageBusProducer.java

License:Open Source License

/**
 * Process the <code>Exchange</code>.
 *
 * @param exchange exchange/*from w  w w  . jav  a2 s  . c om*/
 * @throws Exception Exception
 */
public void process(Exchange exchange) throws Exception {
    se.vgregion.messagebus.MessageBusEndpoint endpoint = (MessageBusEndpoint) getEndpoint();
    MessageBus messageBus = endpoint.getMessageBus();

    String destination = endpoint.getDestination();

    Message body = exchange.getIn().getBody(Message.class);
    body.setResponseId((String) exchange.getIn().getHeader("responseId"));

    messageBus.sendMessage(destination, body);
}