/** * Sets the {@link MediaType} and fileEntity for this {@link FormDataBodyPart}. * * @param fileEntity the entity of this body part. * @param mediaType the media type. */ public void setFileEntity(final File fileEntity, final MediaType mediaType) { super.setMediaType(mediaType); super.setEntity(fileEntity); this.fileEntity = fileEntity; if (fileEntity != null) { FormDataContentDisposition.FormDataContentDispositionBuilder builder = FormDataContentDisposition.name(getName()); builder.fileName(fileEntity.getName()); if (fileEntity.exists()) { builder.size(fileEntity.length()); builder.modificationDate(new Date(fileEntity.lastModified())); } setFormDataContentDisposition(builder.build()); } }
/** * Sets the control name. * * @param name the control name. */ public void setName(String name) { if (name == null) { throw new IllegalArgumentException(LocalizationMessages.CONTROL_NAME_CANNOT_BE_NULL()); } if (getFormDataContentDisposition() == null) { FormDataContentDisposition contentDisposition; contentDisposition = FormDataContentDisposition.name(name).build(); super.setContentDisposition(contentDisposition); } else { FormDataContentDisposition formDataContentDisposition = FormDataContentDisposition.name(name) .fileName(contentDisposition.getFileName()) .creationDate(contentDisposition.getCreationDate()) .modificationDate(contentDisposition.getModificationDate()) .readDate(contentDisposition.getReadDate()) .size(contentDisposition.getSize()).build(); super.setContentDisposition(formDataContentDisposition); } }
/** * Sets the {@link MediaType} and fileEntity for this {@link FormDataBodyPart}. * * @param fileEntity the entity of this body part. * @param mediaType the media type. */ public void setFileEntity(final File fileEntity, final MediaType mediaType) { super.setMediaType(mediaType); super.setEntity(fileEntity); this.fileEntity = fileEntity; if (fileEntity != null) { FormDataContentDisposition.FormDataContentDispositionBuilder builder = FormDataContentDisposition.name(getName()); builder.fileName(fileEntity.getName()); if (fileEntity.exists()) { builder.size(fileEntity.length()); builder.modificationDate(new Date(fileEntity.lastModified())); } setFormDataContentDisposition(builder.build()); } }
/** * Test execute with timeout query. * * @throws IOException Signals that an I/O exception has occurred. * @throws InterruptedException the interrupted exception */ @Test(dataProvider = "mediaTypeData") public void testExecuteWithTimeoutFailingQuery(MediaType mt) throws IOException, InterruptedException { final WebTarget target = target().path("queryapi/queries"); final FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId, mt)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID from nonexist")); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute_with_timeout")); // set a timeout value enough for tests mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("timeoutmillis").build(), "300000")); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(), mt)); Response response = target.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE)); assertEquals(response.getStatus(), BAD_REQUEST.getStatusCode()); }
/** * Prepare form. * * @param sql the sql * @param op the op * @param queryName the query name * @param conf config to be used for the query * @return the form data multi part */ private FormDataMultiPart prepareForm(String sql, String op, String queryName, LensConf conf) { FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), connection .getSessionHandle(), MediaType.APPLICATION_XML_TYPE)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), sql)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), op)); if (!StringUtils.isBlank(queryName)) { mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("queryName").build(), queryName)); } mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf, MediaType.APPLICATION_XML_TYPE)); return mp; }
@Test(dataProvider = "mediaTypeData") public void testRewriteFailure(MediaType mt) { final WebTarget target = target().path("queryapi/queries"); // estimate cube query which fails semantic analysis final FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId, mt)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "sdfelect ID from cube_nonexist")); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "estimate")); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(), mt)); final Response response = target.request(mt) .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE)); LensErrorTO expectedLensErrorTO = LensErrorTO.composedOf( LensCubeErrorCode.SYNTAX_ERROR.getLensErrorInfo().getErrorCode(), "Syntax Error: line 1:0 cannot recognize input near 'sdfelect' 'ID' 'from'", TestDataUtils.MOCK_STACK_TRACE); ErrorResponseExpectedData expectedData = new ErrorResponseExpectedData(BAD_REQUEST, expectedLensErrorTO); expectedData.verify(response); }
/** * Test rewrite failure in execute operation. * * @throws InterruptedException the interrupted exception */ @Test(dataProvider = "mediaTypeData") public void testRewriteFailureInExecute(MediaType mt) throws InterruptedException { final WebTarget target = target().path("queryapi/queries"); LensConf conf = new LensConf(); final FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId, mt)); mp.bodyPart( new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID from non_exist_table")); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute")); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf, mt)); final Response response = target.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE)); assertEquals(response.getStatus(), BAD_REQUEST.getStatusCode()); }
@Test public void testDefaultResponseType() { final WebTarget target = target().path("session"); final FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("username").build(), "foo")); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("password").build(), "bar")); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionconf").fileName("sessionconf").build(), new LensConf(), defaultMT)); final String handle = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), String.class); Assert.assertNotNull(handle); Assert.assertTrue(handle.contains("xml"), "Handle is " + handle); Assert.assertTrue(handle.contains("publicId"), "Handle is " + handle); Assert.assertTrue(handle.contains("secretId"), "Handle is " + handle); String result = target.queryParam("sessionid", handle).request().delete(String.class); Assert.assertNotNull(result); Assert.assertTrue(result.contains("xml"), "Result is " + result); Assert.assertTrue(result.contains("succeeded"), "Result is " + result); }
/** * Builds the body part content-disposition header which the specified * filename (or the default one if unspecified). * * @return ready to use content-disposition header. */ protected FormDataContentDisposition buildContentDisposition() { FormDataContentDisposition.FormDataContentDispositionBuilder builder = FormDataContentDisposition.name(getName()); if (filename != null) { builder.fileName(filename); } else { // Default is to set the name of the file as a form-field name. builder.fileName(getName()); } return builder.build(); }
public LensAPIResult<QueryHandle> runSavedQuery(Long queryId, String sessionHandleString, String conf, HashMap<String, String> params) throws JAXBException { MapBuilder map = new MapBuilder(params); FormBuilder formData = new FormBuilder("sessionid", sessionHandleString); if (conf == null) { conf = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><conf />"; } formData.getForm().bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf") .build(), conf, MediaType.APPLICATION_XML_TYPE)); Response response = this.exec("post", SAVED_QUERY_BASE_URL + "/" + queryId, servLens, null, map, MediaType.MULTIPART_FORM_DATA_TYPE, MediaType.APPLICATION_XML, formData.getForm()); AssertUtil.assertSucceededResponse(response); return response.readEntity(new GenericType<LensAPIResult<QueryHandle>>(){}); }
/** * Builds the body part content-disposition header which the specified * filename (or the default one if unspecified). * * @return ready to use content-disposition header. */ protected FormDataContentDisposition buildContentDisposition() { FormDataContentDisposition.FormDataContentDispositionBuilder builder = FormDataContentDisposition.name(getName()); if (filename != null) { builder.fileName(filename); } else { // Default is to set the name of the file as a form-field name. builder.fileName(getName()); } return builder.build(); }
/** * Test wrong auth. */ @Test(dataProvider = "mediaTypeData") public void testWrongAuth(MediaType mt) { final WebTarget target = target().path("session"); final FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("username").build(), "a")); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("password").build(), "b")); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionconf").fileName("sessionconf").build(), new LensConf(), mt)); final Response handle = target.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE)); Assert.assertEquals(handle.getStatus(), 401); }
@Test(dataProvider = "mediaTypeData") public void testQueryRejection(MediaType mt) throws InterruptedException, IOException { final WebTarget target = target().path("queryapi/queries"); final FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId, mt)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "blah select ID from " + TEST_TABLE)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute")); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(), mt)); Response response = target.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE)); assertEquals(response.getStatus(), 400); }
/** * Builds the body part content-disposition header which the specified * filename (or the default one if unspecified). * * @return ready to use content-disposition header. */ protected FormDataContentDisposition buildContentDisposition() { FormDataContentDisposition.FormDataContentDispositionBuilder builder = FormDataContentDisposition.name(getName()); if (filename != null) { builder.fileName(filename); } else { // Default is to set the name of the file as a form-field name. builder.fileName(getName()); } return builder.build(); }
/** * Builds the body part content-disposition header which the specified * filename (or the default one if unspecified). * * @return ready to use content-disposition header. */ protected FormDataContentDisposition buildContentDisposition() { FormDataContentDisposition.FormDataContentDispositionBuilder builder = FormDataContentDisposition.name(getName()); if (filename != null) { builder.fileName(filename); } else { // Default is to set the name of the file as a form-field name. builder.fileName(getName()); } return builder.build(); }
private void executeAsync() { final WebTarget target = target().path("queryapi/queries"); final FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId, MediaType.APPLICATION_XML_TYPE)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID, IDSTR from " + TestQueryService.TEST_TABLE)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute")); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(), MediaType.APPLICATION_XML_TYPE)); final QueryHandle handle = target.request(mediaType).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), new GenericType<LensAPIResult<QueryHandle>>() {}).getData(); Assert.assertNotNull(handle); }
private static FormDataBodyPart getFormDataBodyPart(final String fdContentDispName, final String fileName, final Object entity, final MediaType mt) { return new FormDataBodyPart(FormDataContentDisposition.name(fdContentDispName).fileName(fileName).build(), entity, mt); }
public static LensSessionHandle openSession(WebTarget target, final String userName, final String passwd, final LensConf conf, MediaType mt) { final WebTarget sessionTarget = target.path("session"); final FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("username").build(), userName)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("password").build(), passwd)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionconf").fileName("sessionconf").build(), conf, mt)); return sessionTarget.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), LensSessionHandle.class); }
private FormDataMultiPart getMultiFormData(String username, String password, MediaType mt) { final FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("username").build(), username)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("password").build(), password)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionconf").fileName("sessionconf").build(), new LensConf(), mt)); return mp; }
/** * Builds the body part content-disposition header which the specified * filename (or the default one if unspecified). * * @return ready to use content-disposition header. */ protected FormDataContentDisposition buildContentDisposition() { FormDataContentDisposition.FormDataContentDispositionBuilder builder = FormDataContentDisposition.name(getName()); if (filename != null) { builder.fileName(filename); } else { // Default is to set the name of the file as a form-field name. builder.fileName(getName()); } return builder.build(); }