List of usage examples for java.lang ClassCastException getMessage
public String getMessage()
From source file:org.eclipse.gyrex.cloud.internal.locking.ZooKeeperLock.java
/** * Creates a new lock instance.//from w w w. j a va 2 s . c o m * * @param lockId * the lock id * @param lockMonitor * the lock monitor * @param lockNodeParentPath * the lock node parent path * @param ephemeral * <code>true</code> if an ephemeral node should be created, * <code>false</code> otherwise * @param recovarable * <code>true</code> if the lock is recoverable, * <code>false</code> otherwise */ public ZooKeeperLock(final String lockId, final ILockMonitor<T> lockMonitor, final IPath lockNodeParentPath, final boolean ephemeral, final boolean recovarable) { super(200l, 5); if (!IdHelper.isValidId(lockId)) throw new IllegalArgumentException("invalid lock id; please see IdHelper#isValidId"); this.lockId = lockId; lockNodePath = lockNodeParentPath.append(lockId); this.lockMonitor = lockMonitor; this.ephemeral = ephemeral; this.recoverable = recovarable; // pre-generate lock node content info NodeInfo nodeInfo = CloudState.getNodeInfo(); if (null == nodeInfo) { nodeInfo = new NodeInfo(); } try { lockNodeContent = nodeInfo.getNodeId() + SEPARATOR + nodeInfo.getLocation() + SEPARATOR + DigestUtils.shaHex(UUID.randomUUID().toString().getBytes(CharEncoding.US_ASCII)); } catch (final UnsupportedEncodingException e1) { throw new IllegalStateException("Please use a JVM that supports UTF-8."); } // check implementation try { asLockType(); } catch (final ClassCastException e) { throw new ClassCastException(String.format( "Cannot cast the lock implementation %s to the generic lock type. Please make sure that the implementation implements the interface. %s", getClass().getName(), e.getMessage())); } // activate activate(); }
From source file:org.seasar.dbflute.s2dao.extension.TnRowCreatorExtension.java
protected void throwMappingClassCastException(Object entity, DBMeta dbmeta, TnPropertyMapping mapping, Object selectedValue, ClassCastException e) { String msg = "Look! Read the message below." + ln(); msg = msg + "/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" + ln(); msg = msg + "Failed to cast a class while data mapping!" + ln(); msg = msg + ln();//from ww w.j ava 2 s . c o m msg = msg + "[Advice]" + ln(); msg = msg + "If you use Seasar(S2Container), this exception may be" + ln(); msg = msg + "from ClassLoader Headache about HotDeploy." + ln(); msg = msg + "Add the ignore-package setting to convention.dicon like this:" + ln(); msg = msg + " For example:" + ln(); msg = msg + " <initMethod name=?addIgnorePackageName?>" + ln(); msg = msg + " <arg>?com.example.xxx.dbflute?</arg>" + ln(); msg = msg + " </initMethod>" + ln(); msg = msg + "If you use an other DI container, this exception may be" + ln(); msg = msg + "from illegal state about your settings of DBFlute." + ln(); msg = msg + "Confirm your settings: for example, typeMappingMap.dfprop." + ln(); msg = msg + ln(); msg = msg + "[Exception Message]" + ln() + e.getMessage() + ln(); msg = msg + ln(); msg = msg + "[Target Entity]" + ln() + entity + ln(); msg = msg + "classLoader: " + entity.getClass().getClassLoader() + ln(); msg = msg + ln(); msg = msg + "[Target DBMeta]" + ln() + dbmeta + ln(); msg = msg + "classLoader: " + dbmeta.getClass().getClassLoader() + ln(); msg = msg + ln(); msg = msg + "[Property Mapping]" + ln() + mapping + ln(); msg = msg + "type: " + (mapping != null ? mapping.getClass() : null) + ln(); msg = msg + ln(); msg = msg + "[Selected Value]" + ln() + selectedValue + ln(); msg = msg + "type: " + (selectedValue != null ? selectedValue.getClass() : null) + ln(); msg = msg + "* * * * * * * * * */"; throw new MappingClassCastException(msg, e); }
From source file:net.sourceforge.buildmonitor.monitors.BambooMonitor.java
/** * Call a bamboo REST api method and return the result (or throw a MonitoringException) * @param url//from w w w. j a va 2 s.c o m * @return * ticket is not valid (anymore) and needs to be renewed. */ private String callBambooApi(URL url) throws MonitoringException { String returnedValue = null; try { returnedValue = getServerResponse(url); } catch (ClassCastException e) { throw new MonitoringException( "Problem: the base URL defined for the Bamboo server in Options is not an http URL.", true, null); } catch (UnknownHostException e) { throw new MonitoringException("Problem: cannot find host " + url.getHost() + " on the network.", true, null); } catch (ConnectException e) { throw new MonitoringException( "Problem: cannot connect to port " + url.getPort() + " on host " + url.getHost() + ".", true, null); } catch (FileNotFoundException e) { throw new MonitoringException( "Problem: cannot find the Bamboo server REST api using the base URL defined for the Bamboo server in Options. Seems that this URL is not the one to your Bamboo server home page...", true, null); } catch (SocketException e) { throw new MonitoringException("Problem: network error, connection lost.", null); } catch (IOException e) { if (e.getMessage().contains("Server returned HTTP response code: 401")) { throw new MonitoringException( "Problem: Authentication failed. Please check your username and password", null); } else { throw new MonitoringException(e, null); } } if (returnedValue.contains("<title>Bamboo Setup Wizard - Atlassian Bamboo</title>")) { throw new MonitoringException( "Your Bamboo server installation is not finished! Double click here to complete the Bamboo Setup Wizard !", getMainPageURI()); } return returnedValue; }
From source file:no.ntnu.okse.protocol.wsn.WSNotificationServer.java
public InternalMessage sendMessage(InternalMessage message) { // Fetch the requestInformation from the message, and extract the endpoint RequestInformation requestInformation = message.getRequestInformation(); String endpoint = requestInformation.getEndpointReference(); /* If we have nowhere to send the message */ if (endpoint == null) { log.error("Endpoint reference not set"); totalErrors.incrementAndGet();/*from w ww .ja v a 2s . c om*/ return new InternalMessage(InternalMessage.STATUS_FAULT, null); } /* Create the actual http-request*/ org.eclipse.jetty.client.api.Request request = _client .newRequest(requestInformation.getEndpointReference()); request.timeout(connectionTimeout, TimeUnit.SECONDS); /* Try to send the message */ try { /* Raw request */ if ((message.statusCode & InternalMessage.STATUS_HAS_MESSAGE) == 0) { request.method(HttpMethod.GET); log.debug("Sending message without content to " + requestInformation.getEndpointReference()); ContentResponse response = request.send(); totalRequests.incrementAndGet(); return new InternalMessage(InternalMessage.STATUS_OK | InternalMessage.STATUS_HAS_MESSAGE, response.getContentAsString()); /* Request with message */ } else { // Set proper request method request.method(HttpMethod.POST); // If the statusflag has set a message and it is not an input stream if ((message.statusCode & InternalMessage.STATUS_MESSAGE_IS_INPUTSTREAM) == 0) { log.error("sendMessage(): " + "The message contained something else than an inputStream." + "Please convert your message to an InputStream before calling this methbod."); return new InternalMessage( InternalMessage.STATUS_FAULT | InternalMessage.STATUS_FAULT_INVALID_PAYLOAD, null); } else { // Check if we should have had a message, but there was none if (message.getMessage() == null) { log.error("No content was found to send"); totalErrors.incrementAndGet(); return new InternalMessage( InternalMessage.STATUS_FAULT | InternalMessage.STATUS_FAULT_INVALID_PAYLOAD, null); } // Send the request to the specified endpoint reference log.info("Sending message with content to " + requestInformation.getEndpointReference()); InputStream msg = (InputStream) message.getMessage(); request.content(new InputStreamContentProvider(msg), "application/soap+xml; charset=utf-8"); ContentResponse response = request.send(); totalMessagesSent.incrementAndGet(); // Check what HTTP status we received, if is not A-OK, flag the internalmessage as fault // and make the response content the message of the InternalMessage returned if (!HttpStatus.isSuccess(response.getStatus())) { totalBadRequests.incrementAndGet(); return new InternalMessage( InternalMessage.STATUS_FAULT | InternalMessage.STATUS_HAS_MESSAGE, response.getContentAsString()); } else { return new InternalMessage(InternalMessage.STATUS_OK | InternalMessage.STATUS_HAS_MESSAGE, response.getContentAsString()); } } } } catch (ClassCastException e) { log.error("sendMessage(): The message contained something else than an inputStream." + "Please convert your message to an InputStream before calling this method."); totalErrors.incrementAndGet(); return new InternalMessage(InternalMessage.STATUS_FAULT | InternalMessage.STATUS_FAULT_INVALID_PAYLOAD, null); } catch (Exception e) { totalErrors.incrementAndGet(); e.printStackTrace(); log.error("sendMessage(): Unable to establish connection: " + e.getMessage()); return new InternalMessage(InternalMessage.STATUS_FAULT_INTERNAL_ERROR, null); } }
From source file:org.atomserver.core.AbstractAtomCollection.java
private Entry parseEntry(EntryTarget entryTarget, RequestContext request) { StopWatch stopWatch = new AtomServerStopWatch(); try {//from w w w . j a v a2 s .c om String errMsgPrefix = "Could not process PUT for [" + entryTarget.getWorkspace() + ", " + entryTarget.getCollection() + ", " + entryTarget.getLocale() + ", " + entryTarget.getEntryId() + ", " + entryTarget.getRevision(); String errMsgPostfix = "\n MAKE CERTAIN THAT YOU ARE INDEED SENDING VALID XML"; Entry entry = null; try { Document<Entry> document = request.getDocument(); entry = document.getRoot(); } catch (java.lang.ClassCastException ee) { String msg = errMsgPrefix + "]\n Reason:: Could not parse a valid <entry> from the Request provided. " + ee.getMessage() + "\n 1) MAKE CERTAIN THAT YOU HAVE A NAMESPACE ON THE <entry> ELEMENT!" + "\n (i.e. <entry xmlns=\"http://www.w3.org/2005/Atom\">)" + errMsgPostfix; log.error(msg, ee); throw new BadContentException(msg, ee); } catch (java.lang.ArrayIndexOutOfBoundsException ee) { String msg = errMsgPrefix + "]\n Reason:: MOST LIKELY THE <content> IS EMPTY. " + ee.getMessage() + errMsgPostfix; log.error(msg, ee); throw new BadContentException(msg, ee); } catch (org.apache.abdera.parser.ParseException ee) { String msg = errMsgPrefix + "]\n Reason:: The <content> XML could not be parsed. " + ee.getMessage() + "\n If this was caused by an ArrayIndexOutOfBoundsException. MOST LIKELY THE <content> IS EMPTY " + errMsgPostfix; log.error(msg, ee); throw new BadContentException(msg, ee); } catch (Exception ee) { String msg = errMsgPrefix + "]\n Reason:: UNKNOWN EXCEPTION THROWN while parsing the <entry>" + ee.getMessage() + errMsgPostfix; log.error(msg, ee); throw new BadContentException(msg, ee); } if (entry == null) { String msg = errMsgPrefix + "]\n Reason:: Content is NULL. Is the <content> element missing? "; log.error(msg); throw new BadContentException(msg); } return entry; } finally { stopWatch.stop("AC.parseEntry", AtomServerPerfLogTagFormatter.getPerfLogEntryString(entryTarget)); } }
From source file:com.impetus.kundera.query.KunderaQuery.java
/** * Sets the kundera query type object.//w w w .ja v a2 s .co m */ private void setKunderaQueryTypeObject() { try { if (isSelectStatement()) { this.setSelectStatement((SelectStatement) (this.getJpqlExpression().getQueryStatement())); } else if (isUpdateStatement()) { this.setUpdateStatement((UpdateStatement) (this.getJpqlExpression().getQueryStatement())); } else if (isDeleteStatement()) { this.setDeleteStatement((DeleteStatement) (this.getJpqlExpression().getQueryStatement())); } } catch (ClassCastException cce) { throw new JPQLParseException("Bad query format : " + cce.getMessage()); } }
From source file:org.slc.sli.dashboard.manager.impl.PopulationManagerImpl.java
@Override public List<GenericEntity> getAssessments(String token, List<GenericEntity> studentSummaries) { Set<GenericEntity> assessments = new TreeSet<GenericEntity>(new Comparator<GenericEntity>() { @Override/*from ww w . ja v a 2s . c om*/ public int compare(GenericEntity att1, GenericEntity att2) { return (att2.getString("id")).compareTo(att1.getString("id")); } }); for (GenericEntity studentSummary : studentSummaries) { List<Map<String, Object>> studentAssessments = (List<Map<String, Object>>) studentSummary .get(Constants.ATTR_STUDENT_ASSESSMENTS); for (Map<String, Object> studentAssessment : studentAssessments) { try { GenericEntity assessment = new GenericEntity((Map) studentAssessment.get("assessments")); assessments.add(assessment); } catch (ClassCastException cce) { LOG.warn(cce.getMessage()); } } } return new ArrayList<GenericEntity>(assessments); }
From source file:net.ssehub.easy.instantiation.core.model.buildlangModel.BuildlangExecution.java
@Override public Object visitForStatement(ForStatement stmt) throws VilException { Object result = null;/* w w w. j av a 2 s. com*/ try { environment.pushLevel(); tracer.visitLoop(stmt, environment); result = executeLoop(stmt, false, null); tracer.visitedLoop(stmt, environment); } catch (ClassCastException e) { // for handcrafted models throw new VilException(e.getMessage(), VilException.ID_INTERNAL); } catch (IndexOutOfBoundsException e) { // for handcrafted models throw new VilException("index out of bounds " + e.getMessage(), VilException.ID_INTERNAL); } environment.popLevel(); return result; }
From source file:net.ssehub.easy.instantiation.core.model.buildlangModel.BuildlangExecution.java
@Override public Object visitMapExpression(MapExpression map) throws VilException { boolean failed = false; List<Object> result; TypeDescriptor<?> mapType = map.inferType(); result = TypeRegistry.voidType() == mapType ? null : new ArrayList<Object>(); try {/*www . j a v a 2 s . co m*/ environment.pushLevel(); tracer.visitLoop(map, environment); failed = (null == executeLoop(map, true, result)); tracer.visitedLoop(map, environment); } catch (ClassCastException e) { // for handcrafted models throw new VilException(e.getMessage(), VilException.ID_INTERNAL); } catch (IndexOutOfBoundsException e) { // for handcrafted models throw new VilException("index out of bounds " + e.getMessage(), VilException.ID_INTERNAL); } environment.popLevel(); return mapResult(mapType, result, failed); }
From source file:ubic.basecode.ontology.OntologyLoader.java
/** * Load an ontology into memory. Use this type of model when fast access is critical and memory is available. * If load from URL fails, attempt to load from disk cache under @cacheName. * //from w w w . j a v a 2 s .c om * @param url * @param spec e.g. OWL_MEM_TRANS_INF * @param cacheName unique name of this ontology, will be used to load from disk in case of failed url connection * @return */ public static OntModel loadMemoryModel(String url, OntModelSpec spec, String cacheName) { StopWatch timer = new StopWatch(); timer.start(); OntModel model = getMemoryModel(url, spec); URLConnection urlc = null; int tries = 0; while (tries < MAX_CONNECTION_TRIES) { try { urlc = new URL(url).openConnection(); // help ensure mis-configured web servers aren't causing trouble. urlc.setRequestProperty("Accept", "application/rdf+xml"); try { HttpURLConnection c = (HttpURLConnection) urlc; c.setInstanceFollowRedirects(true); } catch (ClassCastException e) { // not via http, using a FileURLConnection. } if (tries > 0) { log.info("Retrying connecting to " + url + " [" + tries + "/" + MAX_CONNECTION_TRIES + " of max tries"); } else { log.info("Connecting to " + url); } urlc.connect(); // Will error here on bad URL if (urlc instanceof HttpURLConnection) { String newUrl = urlc.getHeaderField("Location"); if (StringUtils.isNotBlank(newUrl)) { log.info("Redirect to " + newUrl); urlc = new URL(newUrl).openConnection(); // help ensure mis-configured web servers aren't causing trouble. urlc.setRequestProperty("Accept", "application/rdf+xml"); urlc.connect(); } } break; } catch (IOException e) { // try to recover. log.error(e + " retrying?"); tries++; } } if (urlc != null) { try (InputStream in = urlc.getInputStream();) { Reader reader; if (cacheName != null) { // write tmp to disk File tempFile = getTmpDiskCachePath(cacheName); if (tempFile == null) { reader = new InputStreamReader(in); } else { tempFile.getParentFile().mkdirs(); Files.copy(in, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING); reader = new FileReader(tempFile); } } else { // Skip the cache reader = new InputStreamReader(in); } assert reader != null; try (BufferedReader buf = new BufferedReader(reader);) { model.read(buf, url); } log.info("Load model: " + timer.getTime() + "ms"); } catch (IOException e) { log.error(e.getMessage(), e); } } if (cacheName != null) { File f = getDiskCachePath(cacheName); File tempFile = getTmpDiskCachePath(cacheName); File oldFile = getOldDiskCachePath(cacheName); if (model.isEmpty()) { // Attempt to load from disk cache if (f == null) { throw new RuntimeException( "Ontology cache directory required to load from disk: ontology.cache.dir"); } if (f.exists() && !f.isDirectory()) { try (BufferedReader buf = new BufferedReader(new FileReader(f));) { model.read(buf, url); // We successfully loaded the cached ontology. Copy the loaded ontology to oldFile // so that we don't recreate indices during initialization based on a false change in // the ontology. Files.copy(f.toPath(), oldFile.toPath(), StandardCopyOption.REPLACE_EXISTING); log.info("Load model from disk: " + timer.getTime() + "ms"); } catch (IOException e) { log.error(e.getMessage(), e); throw new RuntimeException( "Ontology failed load from URL (" + url + ") and disk cache: " + cacheName); } } else { throw new RuntimeException("Ontology failed load from URL (" + url + ") and disk cache does not exist: " + cacheName); } } else { // Model was successfully loaded into memory from URL with given cacheName // Save cache to disk (rename temp file) log.info("Caching ontology to disk: " + cacheName); if (f != null) { try { // Need to compare previous to current so instead of overwriting we'll move the old file f.createNewFile(); Files.move(f.toPath(), oldFile.toPath(), StandardCopyOption.REPLACE_EXISTING); Files.move(tempFile.toPath(), f.toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { log.error(e.getMessage(), e); } } else { log.warn("Ontology cache directory required to save to disk: ontology.cache.dir"); } } } assert !model.isEmpty(); return model; }