/** * 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()); } }
/** * 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(); }
/** * 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); } }
/** * Removes the resource from connection. * * @param type the type * @param resourcePath the resource path * @return the API result */ public APIResult removeResourceFromConnection(String type, String resourcePath) { WebTarget target = getSessionWebTarget(); FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), this.sessionHandle, MediaType.APPLICATION_XML_TYPE)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("type").build(), type)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("path").build(), resourcePath)); return target.path("resources/delete").request() .put(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), APIResult.class); }
private static FormDataBodyPart getFormDataBodyPart(final String fdContentDispName, final Object entity, final MediaType mt) { return new FormDataBodyPart(FormDataContentDisposition.name(fdContentDispName).build(), entity, mt); }
private static FormDataBodyPart getFormDataBodyPart(final String fdContentDispName, final String value, final MediaType mt) { return new FormDataBodyPart(FormDataContentDisposition.name(fdContentDispName).build(), value, mt); }
/** * 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(); }
/** * 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(); }
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); }
public static FormDataMultiPart createFormDataMultiPartForSession( final Optional<String> username, final Optional<String> password, final Optional<LensConf> lensConf, final MediaType mt) { final FormDataMultiPart mp = new FormDataMultiPart(); if (username.isPresent()) { mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("username").build(), username.get())); } if (password.isPresent()) { mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("password").build(), password.get())); } if (lensConf.isPresent()) { mp.bodyPart(getFormDataBodyPart("sessionconf", "sessionconf", lensConf.get(), mt)); } return mp; }
private void setParams(LensSessionHandle lensSessionHandle) { FormDataMultiPart setpart = new FormDataMultiPart(); setpart.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionHandle, defaultMT)); setpart .bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("key").build(), "lens.session.testRestartKey")); setpart.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("value").build(), "myvalue")); APIResult result = target().path("session").path("params").request(defaultMT) .put(Entity.entity(setpart, MediaType.MULTIPART_FORM_DATA_TYPE), APIResult.class); assertEquals(result.getStatus(), APIResult.Status.SUCCEEDED); }
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); }
/** * 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); }
public static void addResource(WebTarget target, final LensSessionHandle lensSessionHandle, final String resourceType, final String resourcePath, MediaType mt) { final WebTarget resourceTarget = target.path("session/resources"); final FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionHandle, mt)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("type").build(), resourceType)); mp.bodyPart( new FormDataBodyPart(FormDataContentDisposition.name("path").build(), resourcePath)); APIResult result = resourceTarget.path("add").request(mt) .put(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), APIResult.class); if (!result.getStatus().equals(APIResult.Status.SUCCEEDED)) { throw new RuntimeException("Could not add resource:" + result); } }
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); }
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>>(){}); }
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; }