/** * Reserved for internal use. A static factory method to create a {@link TableServiceException} instance using * the specified parameters. * @param res * A {@link RequestResult} containing the result of the table storage service operation. * @param op * The {@link TableOperation} representing the table operation that caused the exception. * @param inStream * The <code>java.io.InputStream</code> of the error response from the table operation request. * @param format * The {@link TablePayloadFormat} to use for parsing * * @return * A {@link TableServiceException} instance initialized with values from the input parameters. */ protected static TableServiceException generateTableServiceException(RequestResult res, TableOperation op, InputStream inStream, TablePayloadFormat format) { return new TableServiceException(res.getStatusCode(), res.getStatusMessage(), op, new InputStreamReader(inStream), format); }
@Override public ResultSegment<T> preProcessResponse(TableQuery<T> queryRef, CloudTableClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) { throw TableServiceException.generateTableServiceException(this.getResult(), null, this.getConnection().getErrorStream(), options.getTablePayloadFormat()); } return null; }
cloudTable.create(null, AzureStorageUtils.getTalendOperationContext()); } catch (TableServiceException e) { if (!e.getErrorCode().equals(StorageErrorCodeStrings.TABLE_BEING_DELETED)) { throw e;
@Test public void testBatchOver100Entities() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); TableBatchOperation batch = new TableBatchOperation(); try { for (int m = 0; m < 101; m++) { batch.insert(TableTestHelper.generateRandomEntity("jxscl_odata")); } this.table.execute(batch, options, null); fail("Batch with over 100 entities should fail."); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Bad Request"); String errorAfterSemiColon = ex.getExtendedErrorInformation().getErrorMessage(); errorAfterSemiColon = errorAfterSemiColon.substring(errorAfterSemiColon.indexOf(":") + 1); assertTrue(errorAfterSemiColon.startsWith("The batch request operation exceeds the maximum 100 changes per change set.")); assertEquals(ex.getErrorCode(), StorageErrorCodeStrings.INVALID_INPUT); } }
@Test public void testTableInvalidQuery() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); TableQuery<Class1> query = TableQuery.from(Class1.class).where( String.format("(PartitionKey ) and (RowKey ge '%s')", "000050")); try { table.executeSegmented(query, null, options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Bad Request"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("A binary operator with incompatible types was detected. Found operand types 'Edm.String' and 'Edm.Boolean' for operator kind 'And'.")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "InvalidInput"); } }
@Test public void testBatchInsertFail() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); // insert entity Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(ref), options, null); try { TableBatchOperation batch = new TableBatchOperation(); batch.insert(ref); this.table.execute(batch, options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Conflict"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The specified entity already exists")); assertEquals(ex.getErrorCode(), StorageErrorCodeStrings.ENTITY_ALREADY_EXISTS); } }
@Test public void testInsertEntityWithNumericProperty() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); DynamicTableEntity ref = new DynamicTableEntity(); String propName = ""; for (int m = 0; m < 255; m++) { propName = propName.concat(Integer.toString(m % 9)); } ref.getProperties().put(propName, new EntityProperty("test")); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); try { this.table.execute(TableOperation.insert(ref), options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Bad Request"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage().startsWith("The property name is invalid.")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "PropertyNameInvalid"); } }
assertEquals(ex.getMessage(), "Bad Request"); String errorAfterSemiColon = ex.getExtendedErrorInformation().getErrorMessage(); errorAfterSemiColon = errorAfterSemiColon.substring(errorAfterSemiColon.indexOf(":") + 1); assertTrue(errorAfterSemiColon.startsWith("The property name exceeds the maximum allowed length (255).")); assertEquals(ex.getErrorCode(), "PropertyNameTooLong");
@Override public ResultSegment<T> preProcessResponse(TableQuery<T> queryRef, CloudTableClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) { throw TableServiceException.generateTableServiceException(this.getResult(), null, this.getConnection().getErrorStream(), options.getTablePayloadFormat()); } return null; }
@Test public void testInsertEntityWithPropertyMoreThan255chars() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); DynamicTableEntity ref = new DynamicTableEntity(); String propName = ""; for (int m = 0; m < 256; m++) { propName = propName.concat("a"); } ref.getProperties().put(propName, new EntityProperty("test")); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); try { this.table.execute(TableOperation.insert(ref), options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Bad Request"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The property name exceeds the maximum allowed length (255).")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "PropertyNameTooLong"); } }
/** * Reserved for internal use. A static factory method to create a {@link TableServiceException} instance using * the specified parameters. * @param res * A {@link RequestResult} containing the result of the table storage service operation. * @param op * The {@link TableOperation} representing the table operation that caused the exception. * @param inStream * The <code>java.io.InputStream</code> of the error response from the table operation request. * @param format * The {@link TablePayloadFormat} to use for parsing * * @return * A {@link TableServiceException} instance initialized with values from the input parameters. */ protected static TableServiceException generateTableServiceException(RequestResult res, TableOperation op, InputStream inStream, TablePayloadFormat format) { return new TableServiceException(res.getStatusCode(), res.getStatusMessage(), op, new InputStreamReader(inStream), format); }
cloudTable.create(null, AzureStorageUtils.getTalendOperationContext()); } catch (TableServiceException e) { if (!e.getErrorCode().equals(StorageErrorCodeStrings.TABLE_BEING_DELETED)) { throw e;
assertEquals(ex.getMessage(), "Bad Request"); String errorAfterSemiColon = ex.getExtendedErrorInformation().getErrorMessage(); errorAfterSemiColon = errorAfterSemiColon.substring(errorAfterSemiColon.indexOf(":") + 1); assertTrue(errorAfterSemiColon.startsWith("The entity is larger than the maximum allowed size (1MB).")); assertEquals(ex.getErrorCode(), StorageErrorCodeStrings.ENTITY_TOO_LARGE);
@Override public ResultSegment<R> preProcessResponse(TableQuery<T> queryRef, CloudTableClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) { throw TableServiceException.generateTableServiceException(this.getResult(), null, this.getConnection().getErrorStream(), options.getTablePayloadFormat()); } return null; }
@Test public void testInsertEntityOver1MB() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); Class1 ref = new Class1(); ref.setA("foo_A"); ref.setB("foo_B"); ref.setC("foo_C"); // 1mb right here ref.setD(new byte[1024 * 1024]); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); try { this.table.execute(TableOperation.insert(ref), options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Bad Request"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The entity is larger than the maximum allowed size (1MB).")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "EntityTooLarge"); } }
throw new TableServiceException(currMimePart.httpStatusCode, currMimePart.httpStatusMessage, currOp, new StringReader(currMimePart.payload), options.getTablePayloadFormat());
@Test public void testBatchMergeFail() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); TableBatchOperation batch = new TableBatchOperation(); addInsertBatch(batch); // Insert entity to merge Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(baseEntity), options, null); Class1 updatedEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); updatedEntity.setPartitionKey(baseEntity.getPartitionKey()); updatedEntity.setRowKey(baseEntity.getRowKey()); updatedEntity.setEtag(baseEntity.getEtag()); this.table.execute(TableOperation.replace(updatedEntity), options, null); // add merge to fail addMergeToBatch(baseEntity, batch); try { this.table.execute(batch, options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Precondition Failed"); String errorAfterSemiColon = ex.getExtendedErrorInformation().getErrorMessage(); errorAfterSemiColon = errorAfterSemiColon.substring(errorAfterSemiColon.indexOf(":") + 1); assertTrue(errorAfterSemiColon .startsWith("The update condition specified in the request was not satisfied.")); assertEquals(ex.getErrorCode(), StorageErrorCodeStrings.UPDATE_CONDITION_NOT_SATISFIED); } }
@Override public ResultSegment<R> preProcessResponse(TableQuery<T> queryRef, CloudTableClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) { throw TableServiceException.generateTableServiceException(this.getResult(), null, this.getConnection().getErrorStream(), options.getTablePayloadFormat()); } return null; }
@Test public void testInsertFail() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); Class1 ref = new Class1(); ref.setA("foo_A"); ref.setB("foo_B"); ref.setC("foo_C"); ref.setD(new byte[]{0, 1, 2}); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); TableOperation op = TableOperation.insert(ref); this.table.execute(op, options, null); try { this.table.execute(op, options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Conflict"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The specified entity already exists")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "EntityAlreadyExists"); } }
throw new TableServiceException(currMimePart.httpStatusCode, currMimePart.httpStatusMessage, currOp, new StringReader(currMimePart.payload), options.getTablePayloadFormat());