List of usage examples for java.lang IllegalArgumentException getCause
public synchronized Throwable getCause()
From source file:jp.terasoluna.fw.util.GenericPropertyUtilTest.java
/** * testGetMethod04() <br>/*from ww w . ja v a2 s . c om*/ * <br> * <br> * G <br> * <br> * () bean:bean1???????getter????<br> * () name:"bean1.string"<br> * <br> * () :IllegalArgumentException<br> * "Failed to detect getter for "<br> * + bean??? + "#bean1.string"<br> * ??NoSuchMethodException<br> * <br> * PropertyUtils#getPropertyDescriptor?NoSuchMethodException???? <br> * @throws Exception ????? */ @Test public void testGetMethod04() throws Exception { try { // GenericPropertyUtil.getMethod(new GenericPropertyUtil_Stub02(), "bean1.string"); // fail("???????"); } catch (IllegalArgumentException e) { String message = "Failed to detect getter for " + GenericPropertyUtil_Stub02.class.getName() + "#bean1.string"; assertEquals(message, e.getMessage()); assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertTrue(e.getCause() instanceof NoSuchMethodException); } }
From source file:jp.terasoluna.fw.util.GenericPropertyUtilTest.java
/** * testGetMethod05() <br>//from ww w.j av a 2 s . c om * <br> * <br> * G <br> * <br> * () bean:bean2????getter??<br> * (getter??RuntimeException??)<br> * () name:"bean2.string"<br> * () PropertyUtils#getPropertyDescriptor??: InvocationTargetException JavaBean?getter?RuntimeException<br> * <br> * () :IllegalArgumentException<br> * "Failed to detect getter for "<br> * + bean??? + "#bean2.string"<br> * ??InvocationTargetException<br> * <br> * PropertyUtils#getPropertyDescriptor?InvocationTargetException???? <br> * @throws Exception ????? */ @Test public void testGetMethod05() throws Exception { try { // GenericPropertyUtil.getMethod(new GenericPropertyUtil_Stub02(), "bean2.string"); // fail("???????"); } catch (IllegalArgumentException e) { String message = "Failed to detect getter for " + GenericPropertyUtil_Stub02.class.getName() + "#bean2.string"; assertEquals(message, e.getMessage()); assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertTrue(e.getCause() instanceof InvocationTargetException); } }
From source file:jp.terasoluna.fw.util.GenericPropertyUtilTest.java
/** * testGetMethod06() <br>/*from w w w. ja va2 s . co m*/ * <br> * <br> * G <br> * <br> * () bean:String string2????getter??<br> * () name:"string2"<br> * () PropertyUtils#getPropertyDescriptor??: IllegalAccessException * PropertyUtilsBean??IllegalAccessException<br> * <br> * () :IllegalArgumentException<br> * "Failed to detect getter for "<br> * + bean??? + "#string2"<br> * ??IllegalAccessException<br> * <br> * PropertyUtils#getPropertyDescriptor?IllegalAccessException???? <br> * @throws Exception ????? */ @Test public void testGetMethod06() throws Exception { // ?? BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance(); ReflectionTestUtils.setField(beanUtilsBean, "propertyUtilsBean", new GenericPropertyUtil_PropertyUtilsBeanStub01()); try { // GenericPropertyUtil.getMethod(new GenericPropertyUtil_Stub02(), "string2"); // fail("???????"); } catch (IllegalArgumentException e) { String message = "Failed to detect getter for " + GenericPropertyUtil_Stub02.class.getName() + "#string2"; assertEquals(message, e.getMessage()); assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertTrue(e.getCause() instanceof IllegalAccessException); } }
From source file:nl.mpi.lamus.workspace.exporting.implementation.AddedNodeExporterTest.java
@Test public void exportNodeNullWorkspace() throws MalformedURLException, URISyntaxException, IOException, MetadataException, TransformerException, WorkspaceExportException { final boolean keepUnlinkedFiles = Boolean.FALSE; //not used in this exporter final WorkspaceSubmissionType submissionType = WorkspaceSubmissionType.SUBMIT_WORKSPACE; final WorkspaceExportPhase exportPhase = WorkspaceExportPhase.TREE_EXPORT; final String parentCorpusNamePathToClosestTopNode = "TopNode"; try {/*from w w w .j ava 2 s . c o m*/ addedNodeExporter.exportNode(null, mockParentWsNode, parentCorpusNamePathToClosestTopNode, mockChildWsNode, keepUnlinkedFiles, submissionType, exportPhase); fail("should have thrown exception"); } catch (IllegalArgumentException ex) { String errorMessage = "Workspace not set"; assertEquals("Message different from expected", errorMessage, ex.getMessage()); assertNull("Cause should be null", ex.getCause()); } }
From source file:nl.mpi.lamus.workspace.exporting.implementation.AddedNodeExporterTest.java
@Test public void export_ExportPhaseUnlinkedNodes() throws WorkspaceExportException { final boolean keepUnlinkedFiles = Boolean.TRUE; //not used in this exporter final WorkspaceSubmissionType submissionType = WorkspaceSubmissionType.SUBMIT_WORKSPACE; final WorkspaceExportPhase exportPhase = WorkspaceExportPhase.UNLINKED_NODES_EXPORT; final String parentCorpusNamePathToClosestTopNode = ""; try {/*from w w w . j ava 2s .c o m*/ addedNodeExporter.exportNode(testWorkspace, mockParentWsNode, parentCorpusNamePathToClosestTopNode, mockChildWsNode, keepUnlinkedFiles, submissionType, exportPhase); fail("should have thrown exception"); } catch (IllegalArgumentException ex) { String errorMessage = "This exporter should only be used when exporting the tree, not for unlinked nodes"; assertEquals("Message different from expected", errorMessage, ex.getMessage()); assertNull("Cause should be null", ex.getCause()); } }
From source file:nl.mpi.lamus.workspace.exporting.implementation.AddedNodeExporterTest.java
@Test public void export_SubmissionTypeDelete() throws WorkspaceExportException { final boolean keepUnlinkedFiles = Boolean.TRUE; //not used in this exporter final WorkspaceSubmissionType submissionType = WorkspaceSubmissionType.DELETE_WORKSPACE; final WorkspaceExportPhase exportPhase = WorkspaceExportPhase.UNLINKED_NODES_EXPORT; final String parentCorpusNamePathToClosestTopNode = ""; // top node try {//from w ww .j ava2s . co m addedNodeExporter.exportNode(testWorkspace, mockParentWsNode, parentCorpusNamePathToClosestTopNode, mockChildWsNode, keepUnlinkedFiles, submissionType, exportPhase); fail("should have thrown exception"); } catch (IllegalArgumentException ex) { String errorMessage = "This exporter should only be used when submitting the workspace, not when deleting"; assertEquals("Message different from expected", errorMessage, ex.getMessage()); assertNull("Cause should be null", ex.getCause()); } }
From source file:org.apache.hadoop.hbase.client.TestAdmin1.java
@Test public void testSplitAndMergeWithReplicaTable() throws Exception { // The test tries to directly split replica regions and directly merge replica regions. These // are not allowed. The test validates that. Then the test does a valid split/merge of allowed // regions./*from w ww . j a va2s . c om*/ // Set up a table with 3 regions and replication set to 3 TableName tableName = TableName.valueOf("testSplitAndMergeWithReplicaTable"); HTableDescriptor desc = new HTableDescriptor(tableName); desc.setRegionReplication(3); byte[] cf = "f".getBytes(); HColumnDescriptor hcd = new HColumnDescriptor(cf); desc.addFamily(hcd); byte[][] splitRows = new byte[2][]; splitRows[0] = new byte[] { (byte) '4' }; splitRows[1] = new byte[] { (byte) '7' }; TEST_UTIL.getHBaseAdmin().createTable(desc, splitRows); List<HRegion> oldRegions; do { oldRegions = TEST_UTIL.getHBaseCluster().getRegions(tableName); Thread.sleep(10); } while (oldRegions.size() != 9); //3 regions * 3 replicas // write some data to the table Table ht = TEST_UTIL.getConnection().getTable(tableName); List<Put> puts = new ArrayList<Put>(); byte[] qualifier = "c".getBytes(); Put put = new Put(new byte[] { (byte) '1' }); put.add(cf, qualifier, "100".getBytes()); puts.add(put); put = new Put(new byte[] { (byte) '6' }); put.add(cf, qualifier, "100".getBytes()); puts.add(put); put = new Put(new byte[] { (byte) '8' }); put.add(cf, qualifier, "100".getBytes()); puts.add(put); ht.put(puts); ht.close(); List<Pair<HRegionInfo, ServerName>> regions = MetaTableAccessor .getTableRegionsAndLocations(TEST_UTIL.getConnection(), tableName); boolean gotException = false; // the element at index 1 would be a replica (since the metareader gives us ordered // regions). Try splitting that region via the split API . Should fail try { TEST_UTIL.getHBaseAdmin().split(regions.get(1).getFirst().getRegionName()); } catch (IllegalArgumentException ex) { gotException = true; } assertTrue(gotException); gotException = false; // the element at index 1 would be a replica (since the metareader gives us ordered // regions). Try splitting that region via a different split API (the difference is // this API goes direct to the regionserver skipping any checks in the admin). Should fail try { TEST_UTIL.getHBaseAdmin().split(regions.get(1).getSecond(), regions.get(1).getFirst(), new byte[] { (byte) '1' }); } catch (IOException ex) { gotException = true; } assertTrue(gotException); gotException = false; // Try merging a replica with another. Should fail. try { TEST_UTIL.getHBaseAdmin().mergeRegions(regions.get(1).getFirst().getEncodedNameAsBytes(), regions.get(2).getFirst().getEncodedNameAsBytes(), true); } catch (IllegalArgumentException m) { gotException = true; } assertTrue(gotException); // Try going to the master directly (that will skip the check in admin) try { DispatchMergingRegionsRequest request = RequestConverter.buildDispatchMergingRegionsRequest( regions.get(1).getFirst().getEncodedNameAsBytes(), regions.get(2).getFirst().getEncodedNameAsBytes(), true); TEST_UTIL.getHBaseAdmin().getConnection().getMaster().dispatchMergingRegions(null, request); } catch (ServiceException m) { Throwable t = m.getCause(); do { if (t instanceof MergeRegionException) { gotException = true; break; } t = t.getCause(); } while (t != null); } assertTrue(gotException); gotException = false; // Try going to the regionservers directly // first move the region to the same regionserver if (!regions.get(2).getSecond().equals(regions.get(1).getSecond())) { moveRegionAndWait(regions.get(2).getFirst(), regions.get(1).getSecond()); } try { AdminService.BlockingInterface admin = TEST_UTIL.getHBaseAdmin().getConnection() .getAdmin(regions.get(1).getSecond()); ProtobufUtil.mergeRegions(admin, regions.get(1).getFirst(), regions.get(2).getFirst(), true); } catch (MergeRegionException mm) { gotException = true; } assertTrue(gotException); }
From source file:com.gemstone.gemfire.cache.hdfs.internal.hoplog.HdfsSortedOplogOrganizer.java
@Override public SortedHoplogPersistedEvent read(byte[] key) throws IOException { long startTime = stats.getRead().begin(); String user = logger.isDebugEnabled() ? "Read" : null; // collect snapshot of hoplogs List<TrackedReference<Hoplog>> hoplogs = null; hoplogs = hoplogReadersController.getTrackedSortedOplogList(user); try {/*from w w w .j a v a 2 s . com*/ // search for the key in order starting with the youngest oplog for (TrackedReference<Hoplog> hoplog : hoplogs) { HoplogReader reader = hoplog.get().getReader(); byte[] val = reader.read(key); if (val != null) { // value found in a younger hoplog. stop iteration SortedHoplogPersistedEvent eventObj = deserializeValue(val); stats.getRead().end(val.length, startTime); return eventObj; } } } catch (IllegalArgumentException e) { if (IOException.class.isAssignableFrom(e.getCause().getClass())) { throw handleIOError((IOException) e.getCause()); } else { throw e; } } catch (IOException e) { throw handleIOError(e); } catch (HDFSIOException e) { throw handleIOError(e); } finally { hoplogReadersController.releaseHoplogs(hoplogs, user); } stats.getRead().end(0, startTime); return null; }
From source file:org.metis.sql.SqlStmnt.java
/** * Called by the Controller bean (RDB or PDB) to execute this SQL statement * with the given params.// w ww. j a va 2 s . c o m * * @param params * @throws SQLException */ public SqlResult execute(List<Map<String, String>> params) { if (params == null) { params = new ArrayList<Map<String, String>>(); } LOG.debug("execute: executing this statement: " + getOriginal()); LOG.debug("execute: ... with this number of param maps = " + params.size()); // first, do some light validation work if (params.size() == 0 && (isPrepared() || isCallable())) { // if it is callable and it requires an IN param if (isCallable() && getInTokens().size() > 0) { LOG.error("execute: ERROR, IN params were not provided " + "for this callable statement that requires IN params: " + getPrepared()); return null; } // all prepared statements that are not callable require an // input param else { LOG.error("execute: ERROR, params were not provided " + "for this prepared statement: " + getPrepared()); return null; } } else if (params.size() > 0 && !isPrepared()) { LOG.error("execute: ERROR, params were provided " + "for this static or non-prepared statement that does not " + "require params: " + getOriginal()); return null; } // make sure given params match if (params.size() > 0) { for (Map<String, String> pMap : params) { if (!isMatch(pMap.keySet())) { LOG.error("execute: ERROR, given key:value set does not match " + "this statement's key:value set\n" + getKeyTokens().toString() + " vs. " + params.toString()); return null; } } } // if trace is on, dump params if any if (params.size() > 0 && LOG.isTraceEnabled()) { for (Map<String, String> pMap : params) { LOG.trace("execute: valid param set = " + pMap.toString()); } } // A list that essentially represents the result set returned by the // DB for queries. List<Map<String, Object>> listOfMaps = new ArrayList<Map<String, Object>>(); // dequeue a sqlResult object from the SqlResult cache SqlResult sqlResult = SqlResult.dequeue(); try { // if this statement is call'able, then execute its stored procedure // object. Note that we don't support batching calls to stored // procedures and functions. Maybe that can be a future // enhancement... if (isCallable()) { LOG.debug("execute: invoking this stored procedure or function: " + getStoredProcName()); Map<String, Object> kvMap = new HashMap<String, Object>(); // first prepare the IN params (if any) if (params.size() > 0) { for (KeyValueObject kvObj : getPreparedObjects(params.get(0))) { kvMap.put(kvObj.getKey(), kvObj.getObj()); } } // now execute the function or stored proc // Note from Spring docs: The execute() method returns a // map with an entry for each declared output parameter, // using the parameter name as the key. kvMap = getStoredProcedure().execute(kvMap); // now that the execute has completed, fetch the OUT params // from the kvMap. i suppose it is possible for a stored proc // not to have any OUT params. // need to transfer each key:value that is associated with // the OUT param as a map to listOfMaps. However, those // keys that pertain to cursors or sets, point // to a List of Maps!! for (SqlToken sqlToken : getSortedKeyTokens()) { // skip IN only params; we're only looking for OUT params if (sqlToken.isIn()) { continue; } Object outObj = kvMap.remove(sqlToken.getKey()); if (outObj == null) { LOG.error("execute: object was not returned for this " + "out param: " + sqlToken.getKey()); continue; } if (sqlToken.isCursor() || sqlToken.isRset()) { if (outObj instanceof List) { List<Map<String, Object>> mList = (List<Map<String, Object>>) outObj; for (Map<String, Object> map : mList) { listOfMaps.add(map); } } else { LOG.error("execute: this OUT result set param did not return a type of List: " + sqlToken.getKey()); LOG.error("execute: got this type/class instead: " + outObj.getClass().getName()); } } else { Map<String, Object> map = new HashMap<String, Object>(); map.put(sqlToken.getKey(), outObj); listOfMaps.add(map); } } /* * Any undeclared results returned are added to the output map * with generated names like "#result-set-1" "#result-set-2" * etc. You can change this by setting 'skipUndeclaredResults' * to true, and then these undeclared resultsets will be * skipped. TODO: look into the update count */ if (!kvMap.isEmpty()) { LOG.debug("execute: looking for result sets"); for (Object kvObj : kvMap.values()) { if (kvObj instanceof List) { for (Map<String, Object> map : (List<Map<String, Object>>) kvObj) { listOfMaps.add(map); } } else { LOG.debug( "execute: unknown object returned from execute: " + kvObj.getClass().getName()); LOG.debug("execute: unknown object's toString value: " + kvObj.toString()); } } } sqlResult.setResultSet(listOfMaps); return sqlResult; } // if (isCallable()... // key:value type objects used for binding the input params to // prepared statements List<KeyValueObject> kvObjs = null; Object bindObjs[] = null; // is this a query; i.e., select statement? if (getSqlStmntType() == SqlStmntType.SELECT) { if (isPrepared()) { LOG.debug("execute: executing this prepared SELECT statement: " + getPrepared()); kvObjs = getPreparedObjects(params.get(0)); bindObjs = new Object[kvObjs.size()]; for (int i = 0; i < bindObjs.length; i++) { bindObjs[i] = kvObjs.get(i).getObj(); } listOfMaps = getJdbcTemplate().query(getPrepared(), bindObjs, this); } else { LOG.trace("execute: executing this SELECT statement: " + getOriginal()); listOfMaps = getJdbcTemplate().query(getOriginal(), this); } if (listOfMaps != null && listOfMaps.size() > 0) { LOG.trace("execute: dumping first map - " + listOfMaps.get(0).toString()); } sqlResult.setResultSet(listOfMaps); return sqlResult; } // ok, this statement is neither call'able nor a query so it // must be either an update of some kind; i.e., insert, update or // delete // note that keyHolders are only used for INSERT statements! if (!isPrepared()) { PreparedStmntCreator creatorSetter = new PreparedStmntCreator(this, bindObjs); // i guess it is possible to have a non prepared update of some // sort if (getSqlStmntType() == SqlStmntType.INSERT) { GeneratedKeyHolder keyHolder = new GeneratedKeyHolder(); sqlResult.setNumRows(getJdbcTemplate().update(creatorSetter, keyHolder)); sqlResult.setKeyHolder(keyHolder); } else { sqlResult.setNumRows(getJdbcTemplate().update(getOriginal(), creatorSetter)); } } // we have a prepared update; is the client requesting a batch // update? else if (params.size() > 1) { LOG.debug("execute: invoking batch update for this statement: " + getPrepared()); // create the list of objects for the batch update List<Object[]> batchArgs = new ArrayList<Object[]>(); for (Map<String, String> map : params) { // prepare the bind objects for the prepared // statement kvObjs = getPreparedObjects(map); bindObjs = new Object[kvObjs.size()]; for (int i = 0; i < bindObjs.length; i++) { bindObjs[i] = kvObjs.get(i).getObj(); } batchArgs.add(bindObjs); } sqlResult.setBatchNumRows(getJdbcTemplate().batchUpdate(getPrepared(), batchArgs)); // note that a key holder is not possible with a batch // update } // we have a prepared update, but it is not a batch update else if (params.size() == 1) { LOG.debug("execute: invoking prepared update for this statement: " + getPrepared()); kvObjs = getPreparedObjects(params.get(0)); bindObjs = new Object[kvObjs.size()]; for (int i = 0; i < bindObjs.length; i++) { bindObjs[i] = kvObjs.get(i).getObj(); } // note that PreparedStmntCreator is both a creator and setter PreparedStmntCreator creatorSetter = new PreparedStmntCreator(this, bindObjs); if (getSqlStmntType() == SqlStmntType.INSERT) { LOG.trace("execute: executing prepared INSERT statement"); GeneratedKeyHolder keyHolder = new GeneratedKeyHolder(); int numRows = getJdbcTemplate().update(creatorSetter, keyHolder); sqlResult.setNumRows(numRows); sqlResult.setKeyHolder(keyHolder); } else { LOG.trace("execute: executing UPDATE statement"); int numRows = getJdbcTemplate().update(getPrepared(), creatorSetter); sqlResult.setNumRows(numRows); } } } catch (IllegalArgumentException exc) { LOG.error("execute: ERROR, caught this " + "IllegalArgumentException while executing sql: " + exc.toString()); LOG.error("execute: exception stack trace follows:"); dumpStackTrace(exc.getStackTrace()); if (exc.getCause() != null) { LOG.error("execute: Caused by " + exc.getCause().toString()); LOG.error("execute: causing exception stack trace follows:"); dumpStackTrace(exc.getCause().getStackTrace()); } if (sqlResult != null) { SqlResult.enqueue(sqlResult); } sqlResult = null; } catch (DataAccessException exc) { LOG.error("execute:ERROR, caught this " + "DataAccessException while executing sql: " + exc.toString()); LOG.error("execute: exception stack trace follows:"); dumpStackTrace(exc.getStackTrace()); LOG.error("execute: Most Specific Cause = " + exc.getMostSpecificCause().toString()); LOG.error("execute: MSC exception stack trace follows:"); dumpStackTrace(exc.getMostSpecificCause().getStackTrace()); if (sqlResult != null) { SqlResult.enqueue(sqlResult); } sqlResult = null; } return sqlResult; }
From source file:org.osaf.cosmo.mc.MorseCodeServlet.java
/** * Handles publish requests.// w w w . j ava 2 s. c o m */ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (log.isDebugEnabled()) log.debug("handling PUT for " + req.getPathInfo()); CollectionPath cp = CollectionPath.parse(req.getPathInfo()); if (cp != null) { String parentUid = req.getParameter(PARAM_PARENT_UID); if (StringUtils.isEmpty(parentUid)) parentUid = null; EimmlStreamReader reader = null; try { if (!checkWritePreconditions(req, resp)) return; reader = new EimmlStreamReader(req.getReader()); if (!reader.getCollectionUuid().equals(cp.getUid())) { String msg = "EIMML collection uid " + reader.getCollectionUuid() + " does not match target collection uid " + cp.getUid(); handleGeneralException(new BadRequestException(msg), resp); return; } EimmlStreamReaderIterator i = new EimmlStreamReaderIterator(reader); PubRecords records = new PubRecords(i, reader.getCollectionName(), reader.getCollectionHue()); Set<TicketType> ticketTypes = null; try { ticketTypes = parseTicketTypes(req); } catch (IllegalArgumentException e) { handleGeneralException(new BadRequestException(e), resp); return; } PubCollection pubCollection = controller.publishCollection(cp.getUid(), parentUid, records, ticketTypes); resp.setStatus(HttpServletResponse.SC_CREATED); resp.addHeader(HEADER_SYNC_TOKEN, pubCollection.getToken().serialize()); for (Ticket ticket : pubCollection.getCollection().getTickets()) resp.addHeader(HEADER_TICKET, formatTicket(ticket)); return; } catch (CosmoSecurityException e) { if (e instanceof ItemSecurityException) { InsufficientPrivilegesException ipe = new InsufficientPrivilegesException( (ItemSecurityException) e); handleGeneralException(ipe, resp); } else { resp.sendError(HttpServletResponse.SC_FORBIDDEN, e.getMessage()); } return; } catch (IllegalArgumentException e) { String msg = "Parent uid must be specified when authenticated principal is not a user"; handleGeneralException(new BadRequestException(msg), resp); return; } catch (EimmlStreamException e) { Throwable cause = e.getCause(); String msg = "Unable to read EIM stream: " + e.getMessage(); msg += cause != null ? ": " + cause.getMessage() : ""; handleGeneralException(new BadRequestException(msg, e), resp); return; } catch (UidInUseException e) { handleGeneralException(new MorseCodeException(HttpServletResponse.SC_CONFLICT, e), resp); return; } catch (ServerBusyException e) { log.debug("received ServerBusyException during PUT"); resp.setIntHeader(HEADER_RETRY_AFTER, 5); resp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "The server was busy, try again later"); return; } catch (MorseCodeException e) { Throwable root = e.getCause(); if (root != null && root instanceof EimmlStreamException) { String msg = "Unable to read EIM stream: " + root.getMessage(); handleGeneralException(new BadRequestException(msg, e), resp); return; } if (root != null && root instanceof EimSchemaException) { String msg = "Unable to process EIM records: " + root.getMessage(); handleGeneralException(new BadRequestException(msg, e), resp); return; } handleGeneralException(e, resp); return; } catch (RuntimeException e) { handleGeneralException(new MorseCodeException(e), resp); return; } finally { if (reader != null) reader.close(); } } resp.setStatus(HttpServletResponse.SC_NOT_FOUND); }