Example usage for java.lang ClassCastException getLocalizedMessage

List of usage examples for java.lang ClassCastException getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:com.mothsoft.alexis.security.CurrentUserUtil.java

public static UserAuthenticationDetails getCurrentUser() {
    final SecurityContext ctx = SecurityContextHolder.getContext();
    final Authentication authentication = ctx.getAuthentication();

    try {//from   w ww . j  a  v a  2  s.  c om
        return authentication != null && authentication.isAuthenticated()
                ? (UserAuthenticationDetails) authentication.getPrincipal()
                : null;
    } catch (ClassCastException e) {
        throw new AuthenticationServiceException(e.getLocalizedMessage(), e);
    }
}

From source file:it.geosolutions.filesystemmonitor.neutral.monitorpolling.GBFileSystemMonitorJob.java

/**
 * Try to build the Observer using informations stored into the JobDataMap
 * /*from   www .ja  v  a  2  s  .  c o  m*/
 * @note this method is not sync
 * @param jdm
 * @return
 * @throws JobExecutionException
 */
private static FileAlterationObserver buildObserver(JobDataMap jdm) throws JobExecutionException {

    FileAlterationObserver observer = null;
    final GBEventNotifier notifier;
    // first time build
    try {
        final File directory = new File(jdm.getString(FileSystemMonitorSPI.SOURCE_KEY));

        observer = new FileAlterationObserver(directory,
                new WildcardFileFilter(jdm.getString(FileSystemMonitorSPI.WILDCARD_KEY)));

        notifier = (GBEventNotifier) jdm.get(EVENT_NOTIFIER_KEY);

        final FileAlterationListener fal = new GBFileAlterationListener(notifier);

        observer.addListener(fal);
    } catch (ClassCastException cce) {
        // ClassCastException - if the identified object is not a String.
        throw exceptionPolicy(ExcPolicy.IMMEDIATELY,
                "The identified object is not a String.\n" + cce.getLocalizedMessage(), cce);

    } catch (NullPointerException npe) {
        // NullPointerException - If the pathname argument is null
        throw exceptionPolicy(ExcPolicy.IMMEDIATELY,
                "The pathname argument is null.\n" + npe.getLocalizedMessage(), npe);
    } catch (IllegalArgumentException iae) {
        // IllegalArgumentException - if the pattern is null
        throw exceptionPolicy(ExcPolicy.IMMEDIATELY, "The pattern is null.\n" + iae.getLocalizedMessage(), iae);
    } catch (Throwable e) {
        throw exceptionPolicy(ExcPolicy.IMMEDIATELY,
                "Probably the consumer cannot start.\n" + e.getLocalizedMessage(), e);
    }

    try {
        observer.initialize();
    } catch (Throwable t) {
        throw exceptionPolicy(ExcPolicy.IMMEDIATELY, "An error occurs.\n" + t.getLocalizedMessage(), t);
    }

    jdm.put(OBSERVER_KEY, observer);

    return observer;
}

From source file:org.kuali.mobility.push.service.CXFPushService.java

/**
 * CXF Service method used by devices informing KME that a message has been received
 * on the device./*www.j  a  v a2 s .  co  m*/
 * 
 * @param data
 *            JSON containing the device id and notification id
 * @return
 */
@GET
@Path("/received")
public Response receivedNotification(@QueryParam(value = "data") String data) {
    try {
        JSONObject inform = (JSONObject) JSONSerializer.toJSON(data);
        String deviceId = inform.getString("deviceId");
        List<Device> d = deviceService.findDevicesByDeviceId(deviceId);
        if (d == null || d.size() == 0) {
            return Response.status(Response.Status.OK.getStatusCode()).build();
        }
        // TODO update user push, update PushDeviceTuple
        /*
         * String username = d.get(0).getUsername(); long notificationId =
         * inform.getLong("notificationId");
         * this.userPushService.markPushReceived(username, notificationId);
         */
    } catch (JSONException je) {
        LOG.error("JSONException in :" + data + " : " + je.getMessage());
        return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).build();
    } catch (ClassCastException cce) {
        LOG.error(cce.getLocalizedMessage(), cce);
        return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).build();
    }
    return Response.status(Response.Status.OK.getStatusCode()).build();
}

From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.FileGraphSetup.java

@Override
public void contextInitialized(ServletContextEvent sce) {

    boolean aboxChanged = false; // indicates whether any ABox file graph model has changed
    boolean tboxChanged = false; // indicates whether any TBox file graph model has changed

    ServletContext ctx = sce.getServletContext();

    try {//from  ww w.  j a va 2 s . c o  m
        OntDocumentManager.getInstance().setProcessImports(true);
        Dataset dataset = ModelAccess.on(ctx).getDataset();
        RDFService rdfService = ModelAccess.on(ctx).getRDFService(CONTENT);

        // ABox files
        Set<Path> paths = getFilegraphPaths(ctx, RDF, ABOX, FILEGRAPH);

        cleanupDB(dataset, pathsToURIs(paths, ABOX), ABOX);

        // Just update the ABox filegraphs in the DB; don't attach them to a base model.
        aboxChanged = readGraphs(paths, rdfService, ABOX, /* aboxBaseModel */ null);

        // TBox files
        paths = getFilegraphPaths(ctx, RDF, TBOX, FILEGRAPH);

        cleanupDB(dataset, pathsToURIs(paths, TBOX), TBOX);

        OntModel tboxBaseModel = ModelAccess.on(ctx).getOntModel(ModelNames.TBOX_ASSERTIONS);
        tboxChanged = readGraphs(paths, rdfService, TBOX, tboxBaseModel);
    } catch (ClassCastException cce) {
        String errMsg = "Unable to cast servlet context attribute to the appropriate type "
                + cce.getLocalizedMessage();
        log.error(errMsg);
        throw new ClassCastException(errMsg);
    } catch (Throwable t) {
        log.error(t, t);
    } finally {
        OntDocumentManager.getInstance().setProcessImports(false);
    }

    if ((aboxChanged || tboxChanged) && !isUpdateRequired(ctx)) {
        log.info("a full recompute of the Abox will be performed because"
                + " the filegraph abox(s) and/or tbox(s) have changed or are being read for the first time.");
        SimpleReasonerSetup.setRecomputeRequired(ctx, SimpleReasonerSetup.RecomputeMode.BACKGROUND);
    }
}

From source file:com.hybris.mobile.app.commerce.fragment.CatalogMenuFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    // Make sure that the activity implements the callback interface
    try {//from ww  w .jav  a2s. com
        mActivity = (OnCategorySelectedListener) activity;
    } catch (ClassCastException e) {
        Log.e(TAG, e.getLocalizedMessage());
    }
}

From source file:org.kuali.mobility.push.service.CXFPushService.java

private Response service(String data) {
    LOG.info("Service JSON: " + data);
    JSONObject queryParams;//  ww w  .ja v  a2 s. co m
    List<Device> devices = new ArrayList<Device>();
    String title;
    String message;
    String url;
    String recipient;
    String sender = "KME_PUSH";
    String senderKey;
    JSONArray recipients;
    try {
        queryParams = (JSONObject) JSONSerializer.toJSON(data);
        title = queryParams.getString("title");
        message = queryParams.getString("message");
        url = queryParams.getString("url");
        senderKey = queryParams.getString("senderKey");
        sender = this.getSenderService().findSenderBySenderKey(senderKey).getShortName();

        String source = getKmeProperties().getProperty("push.sender.key.source", "database");
        if ("database".equalsIgnoreCase(source)) {
            LOG.info("Getting SenderKeys from database.");
            Sender senderObj = senderService.findSenderBySenderKey(senderKey);
            if (senderObj == null) {
                LOG.info("---- " + senderKey + " is Not in LHM. May not Send Push Notifications");
                return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).build();
            } else {
                sender = senderObj.getShortName();
            }
        } else if ("properties".equalsIgnoreCase(source)) {
            LOG.info("Getting SenderKeys from properties file.");
            String shortName = getSenderKeysProperties().getProperty(senderKey);
            if (shortName == null) {
                LOG.info("---- " + senderKey + " is Not in LHM. May not Send Push Notifications");
                return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).build();
            } else {
                sender = shortName;
            }
        }

        if (queryParams.has(RECIPIENTS)) {
            if ("net.sf.json.JSONArray".equals(queryParams.get(RECIPIENTS).getClass().getName())) {

                recipients = queryParams.getJSONArray(RECIPIENTS);
                LOG.info("recipients: " + recipients.toString());
                Iterator i = recipients.iterator();
                while (i.hasNext()) {
                    String username = i.next().toString();
                    LOG.info("username: " + username);
                    devices.addAll(deviceService.findDevicesByUsername(username));
                }
            } else {
                recipient = queryParams.getString("recipients");
                if (KME_ALL_USERS.equals(recipient)) {
                    devices = deviceService.findAllDevices();
                } else if (KME_USERNAMELESS.equals(recipient)) {
                    devices = deviceService.findDevicesWithoutUsername();
                }
                LOG.info(recipient);
            }
        }
        if (queryParams.has("devices")
                && "net.sf.json.JSONArray".equals(queryParams.get("devices").getClass().getName())) {
            JSONArray jDevices = queryParams.getJSONArray("devices");
            LOG.info("devices: " + jDevices.toString());
            Iterator i = jDevices.iterator();
            while (i.hasNext()) {
                String sDevice = i.next().toString();
                LOG.info("device: " + sDevice);
                devices.add(deviceService.findDeviceByDeviceId(sDevice));
            }
        }

    } catch (JSONException je) {
        LOG.error("JSONException in :" + data + " : " + je.getMessage());
        return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).build();
    } catch (ClassCastException cce) {
        LOG.error(cce.getLocalizedMessage(), cce);
        return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).build();
    }

    Push push = new Push();
    push.setEmergency(false);
    push.setMessage(message);
    push.setTitle(title);
    push.setUrl(url);
    push.setSender(sender);
    push.setPostedTimestamp(new Timestamp(System.currentTimeMillis()));
    pushService.savePush(push, devices);
    pushService.sendPush(push, devices);
    LOG.info(push.toString());

    return Response.status(Response.Status.OK.getStatusCode()).build();
}

From source file:com.hybris.mobile.app.commerce.fragment.AccountFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    // This makes sure that the container activity has implemented
    // the callback interface. If not, it throws an exception
    try {//from ww w  . ja  v a  2 s  .c o m
        mActivity = (OnAccountEditedListener) activity;
    } catch (ClassCastException e) {
        Log.e(TAG, e.getLocalizedMessage());
    }

}

From source file:com.hybris.mobile.app.commerce.fragment.CatalogContentFragmentBase.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    // Make sure that the activity implements the callback interface
    try {/*  ww  w  .j a  v  a  2  s  .  co m*/
        mActivity = (OnSearchRequestListener) activity;
    } catch (ClassCastException e) {
        Log.e(TAG, e.getLocalizedMessage());
    }
}

From source file:com.hybris.mobile.app.commerce.fragment.ProductDetailFragmentBase.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    // This makes sure that the container activity has implemented
    // the callback interface. If not, it throws an exception
    try {/*  w w w.  j a  v a2 s.  com*/
        mActivity = (OnReviewClickListener) activity;
    } catch (ClassCastException e) {
        Log.e(TAG, e.getLocalizedMessage());
    }

}

From source file:edu.harvard.i2b2.fhir.server.ws.I2b2FhirWS.java

@POST
@Path("{resourceName:" + FhirUtil.RESOURCE_LIST_REGEX + "}/$validate")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/xml+fhir",
        "application/json+fhir" })
public Response validate(@PathParam("resourceName") String resourceName,
        @HeaderParam("accept") String acceptHeader, @Context HttpServletRequest request, String inTxt,
        String profile) throws IOException, URISyntaxException, ParserConfigurationException, SAXException,
        FhirServerException, JAXBException {
    HttpSession session = request.getSession();
    String mediaType;/* w  w w. java2s .  co m*/
    Parameters ps = null;
    String resourceTxt = null;
    Resource r = null;
    String outTxt = "-";
    logger.trace("will run validator");

    try {
        Class resourceClass = FhirUtil.getResourceClass(resourceName);

        try {
            ps = JAXBUtil.fromXml(inTxt, Parameters.class);
            if (ps != null) {
                for (ParametersParameter p : ps.getParameter()) {
                    logger.trace("pname:" + p.getName().getValue());
                }
            } else {
                logger.trace("ps is null");
            }
        } catch (ClassCastException e) {
        }

        if (ps == null) {
            resourceTxt = inTxt;
            try {
                r = JAXBUtil.fromXml(resourceTxt, resourceClass);
            } catch (JAXBException e) {

                Throwable e2 = e.getLinkedException();
                throw new FhirServerException(e2.getMessage(), e2);
            }
            logger.trace(
                    "could transform to" + resourceClass.getSimpleName() + "\n" + r.getClass().getSimpleName());

        } else {
            for (ParametersParameter p : ps.getParameter()) {
                logger.trace("getting pname:" + p.getName().getValue());
                if (p.getName().getValue().equals("resource")) {
                    r = FhirUtil.getResourceFromContainer(p.getResource());
                    resourceTxt = JAXBUtil.toXml(r);
                }

            }
            if (r == null) {
                String msg = "Resource was not specified correctly in the Parameters";
                logger.warn(msg);
                throw new FhirServerException(msg);
            }
        }

        if (!r.getClass().getSimpleName().equals(resourceClass.getSimpleName())) {
            String msg = "The input is not an instance of class:" + resourceClass;
            logger.warn(msg);
            throw new FhirServerException(msg);
        }

        outTxt = Validate.runValidate(resourceTxt, profile);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        return generateResponse(acceptHeader, request, FhirHelper.generateOperationOutcome(e.toString(),
                IssueTypeList.EXCEPTION, IssueSeverityList.FATAL));
    }

    Resource rOut = JAXBUtil.fromXml(outTxt, OperationOutcome.class);
    return generateResponse(acceptHeader, request, rOut);
}