Example usage for java.lang Throwable getLocalizedMessage

List of usage examples for java.lang Throwable getLocalizedMessage

Introduction

In this page you can find the example usage for java.lang Throwable getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:it.cnr.icar.eric.client.ui.thin.RegistryObjectCollectionBean.java

private String checkExternalIdentifier(String status, RegistryObject ro) {
    StringBuffer eiFields = new StringBuffer();
    ExternalIdentifier tempEI = (ExternalIdentifier) ro;
    try {//from  w w  w.  ja  v  a2 s. c om
        if (tempEI.getIdentificationScheme() == null) {
            status = "failure";
            eiFields.append(WebUIResourceBundle.getInstance().getString("classificationScheme"));
        }

        if (tempEI.getValue() == null || tempEI.getValue().length() <= 0) {
            status = "failure";
            if (eiFields.toString().length() != 0) {
                eiFields.append("," + WebUIResourceBundle.getInstance().getString("classificationValueLabel"));
            } else {
                eiFields.append(WebUIResourceBundle.getInstance().getString("classificationValueLabel"));
            }
        }

        if (eiFields.toString().length() != 0) {
            append(WebUIResourceBundle.getInstance().getString("message.CouldNotCreateExternalIdentifier")
                    + eiFields.toString());
            return status;
        }
    } catch (Throwable t) {
        status = "failure";
        log.error(
                WebUIResourceBundle.getInstance().getString("message.FaildToValidateExternalIdentifierFields"),
                t);
        append(WebUIResourceBundle.getInstance().getString("validationEIROError") + t.getLocalizedMessage());
    }
    return status;
}

From source file:nl.mindef.c2sc.nbs.olsr.pud.uplink.server.distributor.impl.DistributorWorkerImpl.java

@Override
@Transactional(readOnly = true)//from   ww  w .j a  va2  s .  c om
public void distribute() {
    try {
        this.txChecker.checkInTx("DistributorWorker::distribute");
    } catch (Throwable e) {
        e.printStackTrace();
    }

    long currentTime = System.currentTimeMillis();

    if (this.logger.isDebugEnabled()) {
        this.logger.debug("*** Have to distribute <" + this.lastDistributionTime + ", " + currentTime + "]");
    }

    RelayServer me = this.relayServers.getMe();
    List<List<Node>> clusters = this.nodes.getClusters(me);
    if (clusters != null) {
        for (List<Node> cluster : clusters) {
            for (Node clusterLeaderNode : cluster) {
                Sender clusterLeaderNodeSender = clusterLeaderNode.getSender();
                if (clusterLeaderNodeSender == null) {
                    this.logger.debug("Cluster leader " + clusterLeaderNode.getMainIp()
                            + " has no sender: skipped to choose a different one");
                    continue;
                }

                RelayServer clusterLeaderNodeRelayServer = clusterLeaderNodeSender.getRelayServer();
                if (clusterLeaderNodeRelayServer != me) {
                    this.logger.debug("Cluster leader " + clusterLeaderNode.getMainIp()
                            + " did not report to me: cluster skipped");
                    break;
                }

                if (this.logger.isDebugEnabled()) {
                    this.logger.debug("*** cluster leader " + clusterLeaderNode.getMainIp().getHostAddress()
                            + " (sender=" + clusterLeaderNodeSender.getIp().getHostAddress() + ":"
                            + clusterLeaderNodeSender.getPort() + ")");
                }

                if ((this.myIPAddresses.isMe(clusterLeaderNodeSender.getIp())
                        || this.myIPAddresses.isMe(clusterLeaderNode.getMainIp()))
                        && (clusterLeaderNodeSender.getPort().intValue() == this.uplinkUdpPort)) {
                    /* do not distribute to ourselves */
                    if (this.logger.isDebugEnabled()) {
                        this.logger.debug("this is me: skipping");
                    }
                    break;
                }

                List<PositionUpdateMsg> p4ds = this.positions
                        .getPositionUpdateMsgForDistribution(this.lastDistributionTime, currentTime, cluster);
                if ((p4ds == null) || (p4ds.size() == 0)) {
                    if (this.logger.isDebugEnabled()) {
                        this.logger.debug("p4ds EMPTY");
                    }
                    break;
                }

                if (this.logger.isDebugEnabled()) {
                    StringBuilder s = new StringBuilder();
                    s.append("p4ds(" + p4ds.size() + ")=");
                    for (PositionUpdateMsg p4d : p4ds) {
                        s.append(" " + p4d.getId());
                    }
                    this.logger.debug(s.toString());
                }

                List<DatagramPacket> packets = positionUpdateMsgsToPackets(p4ds);
                if ((packets != null) && (packets.size() > 0)) {
                    StringBuilder s = new StringBuilder();
                    if (this.logger.isDebugEnabled()) {
                        s.setLength(0);
                        s.append("tx " + packets.size() + " packet(s) to "
                                + clusterLeaderNode.getMainIp().getHostAddress() + " (sender="
                                + clusterLeaderNodeSender.getIp().getHostAddress() + ":"
                                + clusterLeaderNodeSender.getPort() + "), sizes=");
                    }

                    for (DatagramPacket packet : packets) {
                        if (this.logger.isDebugEnabled()) {
                            s.append(" " + packet.getLength());
                        }
                        packet.setAddress(clusterLeaderNodeSender.getIp());
                        packet.setPort(clusterLeaderNodeSender.getPort().intValue());
                        try {
                            this.sock.send(packet);
                        } catch (IOException e) {
                            if (this.logger.isDebugEnabled()) {
                                s.append(" ERROR:" + e.getLocalizedMessage());
                                this.logger.debug(s.toString());
                            }
                            this.logger.error("Could not send to cluster leader "
                                    + clusterLeaderNode.getMainIp().getHostAddress() + " (sender="
                                    + clusterLeaderNodeSender.getIp().getHostAddress() + ":"
                                    + clusterLeaderNodeSender.getPort() + ") : " + e.getLocalizedMessage());
                        }
                    }
                    if (this.logger.isDebugEnabled()) {
                        this.logger.debug(s.toString());
                    }
                }

                break;
            }
        }
    }

    this.lastDistributionTime = currentTime;
}

From source file:org.rhq.core.pc.inventory.InventoryManager.java

public MergeResourceResponse manuallyAddResource(ResourceType resourceType, int parentResourceId,
        Configuration pluginConfiguration, int ownerSubjectId)
        throws InvalidPluginConfigurationClientException, PluginContainerException {
    // TODO (ghinkle): This is hugely flawed. It assumes discovery components will only return the manually discovered
    // resource, but never says this is required. It then proceeds to auto-import the first resource returned. For
    // discoveries that are process based it works because this passes in a null process scan... also a bad idea.

    // Look up the full Resource type (the one provided by the Server is just the keys).
    String resourceTypeString = resourceType.toString();
    resourceType = this.pluginManager.getMetadataManager().getType(resourceType);
    if (resourceType == null) {
        throw new IllegalStateException("Server specified unknown Resource type: " + resourceTypeString);
    }/*from  www  .  ja v a2s.c  o  m*/

    MergeResourceResponse mergeResourceResponse;
    Resource resource = null;
    boolean resourceAlreadyExisted = false;
    Throwable startError = null;

    try {
        ResourceContainer parentResourceContainer = getResourceContainer(parentResourceId);
        ResourceComponent parentResourceComponent = parentResourceContainer.getResourceComponent();

        // Get the discovery component responsible for discovering resources of the specified resource type.
        PluginComponentFactory pluginComponentFactory = PluginContainer.getInstance()
                .getPluginComponentFactory();
        ResourceDiscoveryComponent discoveryComponent = pluginComponentFactory
                .getDiscoveryComponent(resourceType, parentResourceContainer);

        DiscoveredResourceDetails discoveredResourceDetails;
        if (discoveryComponent instanceof ManualAddFacet) {
            // The plugin is using the new manual add API.
            ResourceDiscoveryContext<ResourceComponent<?>> discoveryContext = new ResourceDiscoveryContext<ResourceComponent<?>>(
                    resourceType, parentResourceComponent, parentResourceContainer.getResourceContext(),
                    SystemInfoFactory.createSystemInfo(), new ArrayList<ProcessScanResult>(0),
                    new ArrayList<Configuration>(0), this.configuration.getContainerName(),
                    this.configuration.getPluginContainerDeployment());

            // Ask the plugin's discovery component to find the new resource, throwing exceptions if it cannot be
            // found at all.
            discoveredResourceDetails = discoverResource(discoveryComponent, pluginConfiguration,
                    discoveryContext, parentResourceContainer);
            if (discoveredResourceDetails == null) {
                log.info("Plugin Error: During manual add, discovery component method ["
                        + discoveryComponent.getClass().getName() + ".discoverResource()] returned null "
                        + "(either the Resource type was blacklisted or the plugin developer "
                        + "did not implement support for manually discovered Resources correctly).");
                throw new PluginContainerException("The [" + resourceType.getPlugin()
                        + "] plugin does not properly support manual addition of [" + resourceType.getName()
                        + "] Resources.");
            }
        } else {
            // The plugin is using the old manual add API, which we must continue to support to maintain
            // backward compatibility.
            log.info("Plugin Warning: Resource type '" + resourceType.getName() + "' from '"
                    + resourceType.getPlugin() + "' is still using the deprecated manual Resource add API, "
                    + "rather than the new ManualAddFacet interface.");
            List<Configuration> pluginConfigurations = new ArrayList<Configuration>(1);
            pluginConfigurations.add(pluginConfiguration);
            ResourceDiscoveryContext<ResourceComponent<?>> discoveryContext = new ResourceDiscoveryContext<ResourceComponent<?>>(
                    resourceType, parentResourceComponent, parentResourceContainer.getResourceContext(),
                    SystemInfoFactory.createSystemInfo(), new ArrayList<ProcessScanResult>(0),
                    pluginConfigurations, this.configuration.getContainerName(),
                    this.configuration.getPluginContainerDeployment());

            // Ask the plugin's discovery component to find the new resource, throwing exceptions if it cannot be
            // found at all.
            try {
                Set<DiscoveredResourceDetails> discoveredResources = invokeDiscoveryComponent(
                        parentResourceContainer, discoveryComponent, discoveryContext);
                if ((discoveredResources == null) || discoveredResources.isEmpty()) {
                    log.info("Plugin Error: During manual add, discovery component method ["
                            + discoveryComponent.getClass().getName() + ".discoverResources()] returned "
                            + discoveredResources + " when passed a single plugin configuration "
                            + "(either the resource type was blacklisted or the plugin developer "
                            + "did not implement support for manually discovered resources correctly).");
                    throw new PluginContainerException("The [" + resourceType.getPlugin()
                            + "] plugin does not properly support manual addition of [" + resourceType.getName()
                            + "] resources.");
                }
                discoveredResourceDetails = discoveredResources.iterator().next();
            } catch (DiscoverySuspendedException e) {
                String message = "The discovery class [" + discoveryComponent.getClass().getName() + "]"
                        + " uses a legacy implementation of \"manual add\" functionality. Some of the child resources"
                        + " with the resource type [" + resourceType + "] under the parent resource ["
                        + parentResourceContainer.getResource() + "]"
                        + " failed to upgrade, which makes it impossible to support the legacy manual-add implementation. Either upgrade the plugin ["
                        + resourceType.getPlugin()
                        + "] to successfully upgrade all resources or consider implementing the ManualAdd facet.";
                log.info(message);
                throw new PluginContainerException(message, e);
            }
        }

        // Create the new Resource and add it to inventory if it isn't already there.
        resource = createNewResource(discoveredResourceDetails);
        Resource parentResource = getResourceContainer(parentResourceId).getResource();
        Resource existingResource = findMatchingChildResource(resource, parentResource);
        if (existingResource != null) {
            if (log.isDebugEnabled()) {
                log.debug("Manual add for resource type [" + resourceType.getName()
                        + "] and parent resource id [" + parentResourceId
                        + "] found a resource that already exists in inventory - updating existing resource ["
                        + existingResource + "]");
            }
            resourceAlreadyExisted = true;
            resource = existingResource;
            if (resource.getInventoryStatus() != InventoryStatus.COMMITTED) {
                resource.setPluginConfiguration(pluginConfiguration);
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Adding manually discovered resource [" + resource + "] to inventory...");
            }
            resource.setInventoryStatus(InventoryStatus.COMMITTED);
            parentResource.addChildResource(resource);
            initResourceContainer(resource);
        }

        // Make sure the resource's component is activated (i.e. started).
        boolean newPluginConfig = true;
        ResourceContainer resourceContainer = getResourceContainer(resource);
        if (log.isDebugEnabled()) {
            log.debug("Activating resource [" + resource + "]...");
        }
        // if it fails to start keep going, we already have the resource in inventory and
        // need to coordinate with the server. The new resource will be unavailable but at least
        // it will be accessible and editable by the user. Report the start exception at the end.
        try {
            activateResource(resource, resourceContainer, newPluginConfig);
        } catch (Throwable t) {
            startError = t;
        }

        // NOTE: We don't mess with inventory status - that's the server's responsibility.

        // Tell the server to merge the resource into its inventory.
        DiscoveryServerService discoveryServerService = this.configuration.getServerServices()
                .getDiscoveryServerService();
        mergeResourceResponse = discoveryServerService.addResource(resource, ownerSubjectId);

        // Sync our local resource up with the one now in server inventory. Treat this like a newlyCommittedResource
        resource.setId(mergeResourceResponse.getResourceId());
        resource.setMtime(0); // this will indicate that this resource is "dirty" and needs to be synced/merged later
        Set newResources = new LinkedHashSet<Resource>();
        newResources.add(resource);
        postProcessNewlyCommittedResources(newResources);
        performServiceScan(resource.getId());

        if (null != startError) {
            handleInvalidPluginConfigurationResourceError(resource, startError);
            throw new PluginContainerException("The resource [" + resource
                    + "] has been added but could not be started. Verify the supplied configuration values: ",
                    startError);
        }
    }

    // Catch any other RuntimeExceptions or Errors, so the server doesn't have to worry about deserializing or
    // catching them. Before rethrowing, wrap them in a WrappedRemotingException and then wrap that in either an
    // InvalidPluginConfigurationException or a PluginContainerException.
    catch (Throwable t) {
        if ((resource != null) && !resourceAlreadyExisted && (getResourceContainer(resource) != null)) {
            // If the resource got added to inventory, roll it back (i.e. deactivate it, then remove it from inventory).
            log.debug("Rolling back manual add of resource of type [" + resourceType.getName()
                    + "] - removing resource with id [" + resource.getId() + "] from inventory...");
            deactivateResource(resource);
            uninventoryResource(resource.getId());
        }

        if (t instanceof InvalidPluginConfigurationException) {
            String errorMessage = "Unable to connect to managed resource of type [" + resourceType.getName()
                    + "] using the specified connection properties - resource will not be added to inventory.";
            log.info(errorMessage, t);

            // In the exception we throw over to the server, strip the InvalidPluginConfigurationException out of the
            // stack trace, but append the message from that exception to the message of the exception we throw. This
            // will make for a nicer error message for the server to display in the UI.
            errorMessage += ((t.getLocalizedMessage() != null) ? (" " + t.getLocalizedMessage()) : "");
            throw new InvalidPluginConfigurationClientException(errorMessage,
                    (t.getCause() != null) ? new WrappedRemotingException(t.getCause()) : null);
        } else {
            log.error("Manual add failed for resource of type [" + resourceType.getName()
                    + "] and parent resource id [" + parentResourceId + "]", t);
            throw new PluginContainerException("Failed to add resource with type [" + resourceType.getName()
                    + "] and parent resource id [" + parentResourceId + "]", new WrappedRemotingException(t));
        }
    }

    return mergeResourceResponse;
}

From source file:org.pentaho.di.ui.spoon.Spoon.java

private void onLoginError(Throwable t) {
    if (t instanceof KettleAuthException) {
        ShowMessageDialog dialog = new ShowMessageDialog(loginDialog.getShell(), SWT.OK | SWT.ICON_ERROR,
                BaseMessages.getString(PKG, "Spoon.Dialog.LoginFailed.Title"), t.getLocalizedMessage());
        dialog.open();//w ww. j  a v a  2  s  . c o  m
    } else {
        new ErrorDialog(loginDialog.getShell(), BaseMessages.getString(PKG, "Spoon.Dialog.LoginFailed.Title"),
                BaseMessages.getString(PKG, "Spoon.Dialog.LoginFailed.Message", t), t);
    }
}

From source file:org.opencms.db.CmsDriverManager.java

/**
 * Publishes the resources of a specified publish list.<p>
 *
 * @param cms the current request context
 * @param dbc the current database context
 * @param publishList a publish list//  w  ww  . j  av  a2 s  .com
 * @param report an instance of <code>{@link I_CmsReport}</code> to print messages
 * 
 * @throws CmsException if something goes wrong
 * 
 * @see #fillPublishList(CmsDbContext, CmsPublishList)
 */
public synchronized void publishProject(CmsObject cms, CmsDbContext dbc, CmsPublishList publishList,
        I_CmsReport report) throws CmsException {

    // check the parent folders
    checkParentFolders(dbc, publishList);
    ensureSubResourcesOfMovedFoldersPublished(cms, dbc, publishList);

    try {
        // fire an event that a project is to be published
        Map<String, Object> eventData = new HashMap<String, Object>();
        eventData.put(I_CmsEventListener.KEY_REPORT, report);
        eventData.put(I_CmsEventListener.KEY_PUBLISHLIST, publishList);
        eventData.put(I_CmsEventListener.KEY_PROJECTID, dbc.currentProject().getUuid());
        eventData.put(I_CmsEventListener.KEY_DBCONTEXT, dbc);
        CmsEvent beforePublishEvent = new CmsEvent(I_CmsEventListener.EVENT_BEFORE_PUBLISH_PROJECT, eventData);
        OpenCms.fireCmsEvent(beforePublishEvent);
    } catch (Throwable t) {
        if (report != null) {
            report.addError(t);
            report.println(t);
        }
        if (LOG.isErrorEnabled()) {
            LOG.error(t.getLocalizedMessage(), t);
        }
    }

    // lock all resources with the special publish lock
    Iterator<CmsResource> itResources = new ArrayList<CmsResource>(publishList.getAllResources()).iterator();
    while (itResources.hasNext()) {
        CmsResource resource = itResources.next();
        CmsLock lock = m_lockManager.getLock(dbc, resource, false);
        if (lock.getSystemLock().isUnlocked() && lock.isLockableBy(dbc.currentUser())) {
            if (getLock(dbc, resource).getEditionLock().isNullLock()) {
                lockResource(dbc, resource, CmsLockType.PUBLISH);
            } else {
                changeLock(dbc, resource, CmsLockType.PUBLISH);
            }
        } else if (lock.getSystemLock().isPublish()) {
            if (LOG.isWarnEnabled()) {
                LOG.warn(Messages.get().getBundle().key(Messages.RPT_PUBLISH_REMOVED_RESOURCE_1,
                        dbc.removeSiteRoot(resource.getRootPath())));
            }
            // remove files that are already waiting to be published
            publishList.remove(resource);
            continue;
        } else {
            // this is needed to fix TestPublishIsssues#testPublishScenarioE
            changeLock(dbc, resource, CmsLockType.PUBLISH);
        }
        // now re-check the lock state
        lock = m_lockManager.getLock(dbc, resource, false);
        if (!lock.getSystemLock().isPublish()) {
            if (report != null) {
                report.println(Messages.get().container(Messages.RPT_PUBLISH_REMOVED_RESOURCE_1,
                        dbc.removeSiteRoot(resource.getRootPath())), I_CmsReport.FORMAT_WARNING);
            }
            if (LOG.isWarnEnabled()) {
                LOG.warn(Messages.get().getBundle().key(Messages.RPT_PUBLISH_REMOVED_RESOURCE_1,
                        dbc.removeSiteRoot(resource.getRootPath())));
            }
            // remove files that could not be locked
            publishList.remove(resource);
        }
    }

    // enqueue the publish job
    CmsException enqueueException = null;
    try {
        m_publishEngine.enqueuePublishJob(cms, publishList, report);
    } catch (CmsException exc) {
        enqueueException = exc;
    }

    // if an exception was raised, remove the publish locks
    // and throw the exception again
    if (enqueueException != null) {
        itResources = publishList.getAllResources().iterator();
        while (itResources.hasNext()) {
            CmsResource resource = itResources.next();
            CmsLock lock = m_lockManager.getLock(dbc, resource, false);
            if (lock.getSystemLock().isPublish() && lock.getSystemLock().isOwnedInProjectBy(
                    cms.getRequestContext().getCurrentUser(), cms.getRequestContext().getCurrentProject())) {
                unlockResource(dbc, resource, true, true);
            }
        }

        throw enqueueException;
    }
}