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

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

Introduction

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

Prototype

public String getResponseId() 

Source Link

Usage

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

License:Open Source License

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

    ServletContext servletContext = _serviceTrackerMap.getService(servletContextName);

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

    PluginPackageProperties pluginPackageProperties = new PluginPackageProperties(servletContext);

    String resourcesDir = pluginPackageProperties.getResourcesDir();

    if ((servletContext.getResource(ImporterFactory.RESOURCES_DIR) == null)
            && (servletContext.getResource(ImporterFactory.TEMPLATES_DIR) == null)
            && Validator.isNull(resourcesDir)) {

        return;
    }

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

    try {
        ExportImportThreadLocal.setLayoutImportInProcess(true);
        ExportImportThreadLocal.setPortletImportInProcess(true);

        for (Company company : companies) {
            _importResources(company, servletContext, pluginPackageProperties, message.getResponseId());
        }
    } finally {
        ExportImportThreadLocal.setLayoutImportInProcess(false);
        ExportImportThreadLocal.setPortletImportInProcess(false);
    }
}

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

License:Open Source License

@Override
public void receive(Message message) throws MessageListenerException {
    Exchange exchange = getEndpoint().createExchange();
    Object payload = message.getPayload();

    if (_log.isDebugEnabled()) {
        _log.debug("LiferayConsumer.receive " + payload);
    }//from w w w .  j  av  a  2 s.  c  o m

    exchange.getIn().setBody(payload);
    exchange.getIn().setHeader("liferay-ResponseId", message.getResponseId());

    try {
        getProcessor().process(exchange);
    } catch (Exception e) {
        _log.error("Error processing message", e);
    }
}

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

License:Open Source License

@Override
protected void doReceive(Message message) throws Exception {
    try {//  w  w  w.ja  v  a2 s . co  m
        Map<String, Object> parameters = message.getValues();

        long mappingDataSourceId = GetterUtil.getLong(parameters.get("mappingDataSourceId"));
        String method = String.valueOf(parameters.get("method"));

        Map<String, List<String>> fields = (Map) parameters.get("fields");

        String fieldsString = null;

        if (fields != null) {
            JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

            for (Map.Entry<String, List<String>> entrySet : fields.entrySet()) {

                jsonObject.put(entrySet.getKey(), StringUtil.merge(entrySet.getValue()));
            }

            fieldsString = jsonObject.toString();
        }

        sendResponse(message.getResponseDestinationName(), message.getResponseId(), mappingDataSourceId, method,
                fieldsString);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.liferay.osb.scv.user.mapper.internal.messaging.UserMapperMessageListener.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
protected void doReceive(Message message) throws Exception {
    String responseId = message.getResponseId();

    Event event = EventManager.getEvent(responseId);

    if (event != null) {
        event.handleResponse(message);/*from   w  ww .  j  a  v  a 2s  . co  m*/

        return;
    }

    String method = message.getString("method");
    long mappingDataSourceId = message.getLong("mappingDataSourceId");

    if (method.equals("addData")) {
        List<UserMappingRule> userMappingRules = null;

        MappingDataSource mappingDataSource = MappingDataSourceLocalServiceUtil
                .fetchMappingDataSource(mappingDataSourceId);

        if (mappingDataSource.getType() == MappingDataSourceConstants.CUSTOM) {

            userMappingRules = UserMappingRuleLocalServiceUtil.getUserMappingRules(mappingDataSourceId);
        } else {
            userMappingRules = UserMappingRuleLocalServiceUtil.getUserMappingRules(mappingDataSourceId,
                    FrequencyUtil.INSTANT);
        }

        event = new UpdateUsersEvent(mappingDataSourceId, userMappingRules);

        event.handleResponse(message);
    } else if (method.equals("addDataSource")) {
        String name = message.getString("name");
        String url = message.getString("url");

        long type = MappingDataSourceConstants.CUSTOM;

        if (!Validator.isBlank(url)) {
            type = MappingDataSourceConstants.LIFERAY;
        }

        String login = message.getString("login");
        String password = message.getString("password");
        String availableFields = message.getString("availableFields");

        MappingDataSource mappingDataSource = MappingDataSourceServiceUtil.addMappingDataSource(name, url,
                login, password, type, availableFields);

        Message responseMessage = MessageBusUtil.createResponseMessage(message);

        responseMessage.setPayload(mappingDataSource.getMappingDataSourceId());

        MessageBusUtil.sendMessage(responseMessage.getDestinationName(), responseMessage);
    } else if (method.equals("addUserMappingRule")) {
        String modelName = message.getString("modelName");
        String sourceField = message.getString("sourceField");
        String destinationField = message.getString("destinationField");

        UserMappingRuleServiceUtil.addUserMappingRule(mappingDataSourceId, 0, modelName, sourceField,
                destinationField, FrequencyUtil.ONCE, false);
    } else if (method.equals("getFields")) {
        GetFieldsEvent getFieldsEvent = new GetFieldsEvent(mappingDataSourceId);

        getFieldsEvent.run();
    }
}

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  a2  s. c  om*/
    }

    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

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

    ServletContext servletContext = ServletContextPool.get(servletContextName);

    PluginPackageProperties pluginPackageProperties = new PluginPackageProperties(servletContext);

    String resourcesDir = pluginPackageProperties.getResourcesDir();

    if ((servletContext.getResource(ImporterFactory.RESOURCES_DIR) == null)
            && (servletContext.getResource(ImporterFactory.TEMPLATES_DIR) == null)
            && Validator.isNull(resourcesDir)) {

        return;/*from w w w  .  ja  v  a2 s . com*/
    }

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

    try {
        ExportImportThreadLocal.setLayoutImportInProcess(true);
        ExportImportThreadLocal.setPortletImportInProcess(true);

        for (Company company : companies) {
            importResources(company, servletContext, pluginPackageProperties, message.getResponseId());
        }
    } finally {
        ExportImportThreadLocal.setLayoutImportInProcess(false);
        ExportImportThreadLocal.setPortletImportInProcess(false);
    }
}

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  .j  av  a  2 s .co  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.EndpointMessageListener.java

License:Open Source License

private Exchange createExchange(Message message) {
    Exchange exchange = new DefaultExchange(endpoint);
    org.apache.camel.Message in = new DefaultMessage();

    Object payload = message.getPayload();
    if (payload instanceof Map) {
        String query = HttpRequest.mapToQuery((Map) payload).toString();
        in.setBody(query);/* w w  w .  j a v a 2s .co  m*/
    } else if (payload instanceof HttpRequest) {
        HttpRequest httpRequest = (HttpRequest) payload;
        String queryString = httpRequest.getQueryString();
        if (queryString != null) {
            in.setHeader(Exchange.HTTP_QUERY, queryString);
        }
        String body = httpRequest.getBody();
        if (body != null) {
            in.setBody(body);
        }
        for (Map.Entry<String, String> entry : httpRequest.getHeaders().entrySet()) {
            in.setHeader(entry.getKey(), entry.getValue());
        }
    } else {
        in.setBody(payload);
    }
    in.setHeader("responseId", message.getResponseId());

    Map<String, Object> params = endpoint.getParams();
    if (params != null) {
        String inHeaderKeys = (String) params.get("MessageInHeaders");
        if (inHeaderKeys != null) {
            for (String key : inHeaderKeys.split(",")) {
                Object value = message.get(key);
                if (value != null) {
                    in.setHeader(key, value);
                }
            }
        }
    }

    exchange.setIn(in);

    return exchange;
}