/** * Create payload to supply with POST to REST API * * @return */ private FormDataMultiPart createParametersForm() { FormDataMultiPart form = new FormDataMultiPart(); if ( verCount != -1 && !purgeRev ) { form.field( VER_COUNT, Integer.toString( verCount ), MediaType.MULTIPART_FORM_DATA_TYPE ); } if ( delFrom != null && !purgeRev ) { form.field( DEL_DATE, delFrom, MediaType.MULTIPART_FORM_DATA_TYPE ); } if ( fileFilter != null ) { form.field( FILE_FILTER, fileFilter, MediaType.MULTIPART_FORM_DATA_TYPE ); } if ( logLevel != null ) { form.field( LOG_LEVEL, logLevel, MediaType.MULTIPART_FORM_DATA_TYPE ); } if ( purgeFiles ) { form.field( PURGE_FILES, Boolean.toString( purgeFiles ), MediaType.MULTIPART_FORM_DATA_TYPE ); } if ( purgeRev ) { form.field( PURGE_REV, Boolean.toString( purgeRev ), MediaType.MULTIPART_FORM_DATA_TYPE ); } if ( purgeShared ) { form.field( PURGE_SHARED, Boolean.toString( purgeShared ), MediaType.MULTIPART_FORM_DATA_TYPE ); } return form; }
@Override public void store( final Project project, final Summary summary, final File resultsFile, final Class<?> testClass ) throws FileNotFoundException, MalformedURLException { Preconditions.checkNotNull( summary, "The summary argument cannot be null." ); // upload the results file InputStream in = new FileInputStream( resultsFile ); FormDataMultiPart part = new FormDataMultiPart(); part.field( FILENAME, resultsFile.getName() ); FormDataBodyPart body = new FormDataBodyPart( CONTENT, in, MediaType.APPLICATION_OCTET_STREAM_TYPE ); part.bodyPart( body ); WebResource resource = Client.create().resource( coordinatorFig.getEndpoint() ); resource = addQueryParameters( resource, project, me ); String result = resource.path( coordinatorFig.getStoreResultsPath() ) .queryParam( RUN_ID, summary.getRunId() ) .queryParam( RUN_NUMBER, "" + summary.getRunNumber() ) .type( MediaType.MULTIPART_FORM_DATA_TYPE ) .post( String.class, part ); LOG.debug( "Got back result from results file store = {}", result ); }
static void testStoreResults( TestParams testParams ) throws Exception { FormDataMultiPart part = new FormDataMultiPart(); File tmpFile = File.createTempFile("results", "tmp"); FileInputStream in = new FileInputStream( tmpFile ); FormDataBodyPart body = new FormDataBodyPart( RestParams.CONTENT, in, MediaType.APPLICATION_OCTET_STREAM_TYPE ); part.bodyPart( body ); ClientResponse response = testParams.addQueryParameters( QUERY_PARAMS ) .setEndpoint( RunManagerResource.ENDPOINT ) .newWebResource() .queryParam( RestParams.RUNNER_HOSTNAME, "localhost" ) .queryParam( RestParams.RUN_ID, "112316437" ) .queryParam( RestParams.RUN_NUMBER, "3" ) .path( "/store" ) .type( MediaType.MULTIPART_FORM_DATA_TYPE ) .accept( MediaType.APPLICATION_JSON ) .post( ClientResponse.class, part ); tmpFile.delete(); assertEquals( Response.Status.CREATED.getStatusCode(), response.getStatus() ); assertEquals( UploadResource.SUCCESSFUL_TEST_MESSAGE, response.getEntity( String.class ) ); }
FormDataMultiPart mp = new FormDataMultiPart(); hasFields = true; if(ids != null) { for(String id:ids) { mp.field("ids[]", id, MediaType.MULTIPART_FORM_DATA_TYPE); } } if(hasFields && !mp.getFields().isEmpty()) postBody = mp;
FormDataMultiPart mp = new FormDataMultiPart(); if(hasFields) postBody = mp;
int responseCode = 504; try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { FormDataMultiPart fdmp = new FormDataMultiPart(); fdmp.bodyPart( new FormDataBodyPart( "properties", baos.toString( "UTF-8" ), APPLICATION_XML_TYPE ) ); fdmp.field( IMPORT_PATH_KEY, pathEncoded, MULTIPART_FORM_DATA_TYPE ); fdmp.field( "fileUpload", fileInputStream, MULTIPART_FORM_DATA_TYPE ); fdmp.getField( "fileUpload" ).setContentDisposition( FormDataContentDisposition.name( "fileUpload" ).fileName( nameEncoded ).build() );
FormDataMultiPart multiPart = new FormDataMultiPart(); String mediaType = artifact.getContentType(); if (description.getTitles() != null) { for (TextValue value : description.getTitles()) { multiPart.field("title", value.getValue()); multiPart.field("description", value.getValue()); multiPart.field("citation", citation.getValue()); multiPart.getBodyParts().add(artifactPart); ClientRequest request = state.createAuthenticatedGedcomxRequest().type(MediaType.MULTIPART_FORM_DATA_TYPE).entity(multiPart).build(link.getHref().toURI(), HttpMethod.POST); return state.stateFactory.newSourceDescriptionState(request, state.invoke(request, options), state.accessToken);
FormDataMultiPart multiPart = new FormDataMultiPart(); String mediaType = artifact.getContentType(); if (mediaType == null) { multiPart.getBodyParts().add(artifactPart); ClientRequest request = createAuthenticatedGedcomxRequest().type(MediaType.MULTIPART_FORM_DATA_TYPE).entity(multiPart).build(link.getHref().toURI(), HttpMethod.POST); return this.stateFactory.newSourceDescriptionState(request, invoke(request, options), this.accessToken);
private void addDeployFormFields(String name, FormDataMultiPart deployform) { // add the name field, the name is the archive filename without extension deployform.field("name", name, MediaType.TEXT_PLAIN_TYPE); // add the target field (the default is "server" - Admin Server) deployform.field("target", this.configuration.getTarget(), MediaType.TEXT_PLAIN_TYPE); // add the libraries field (optional) if (this.configuration.getLibraries() != null) { deployform.field("libraries", this.configuration.getLibraries(), MediaType.TEXT_PLAIN_TYPE); } // add the properties field (optional) if (this.configuration.getProperties() != null) { deployform.field("properties", this.configuration.getProperties(), MediaType.TEXT_PLAIN_TYPE); } // add the type field (optional, the only valid value is "osgi", other values are ommited) if (this.configuration.getType() != null && "osgi".equals(this.configuration.getType())) { deployform.field("type", this.configuration.getType(), MediaType.TEXT_PLAIN_TYPE); } } }
@Test public void testConvertToMailgun() throws Exception { EmailWrapper wrapper = getTypicalEmailWrapper(); try (FormDataMultiPart formData = new MailgunService().parseToEmail(wrapper)) { assertEquals(wrapper.getSenderName() + " <" + wrapper.getSenderEmail() + ">", formData.getField("from").getValue()); assertEquals(wrapper.getRecipient(), formData.getField("to").getValue()); assertEquals(wrapper.getBcc(), formData.getField("bcc").getValue()); assertEquals(wrapper.getReplyTo(), formData.getField("h:Reply-To").getValue()); assertEquals(wrapper.getSubject(), formData.getField("subject").getValue()); assertEquals(wrapper.getContent(), formData.getField("html").getValue()); } }
FormDataMultiPart mp = new FormDataMultiPart(); hasFields = true; if(ids != null) { for(String id:ids) { mp.field("ids[]", id, MediaType.MULTIPART_FORM_DATA_TYPE); } } if(hasFields && !mp.getFields().isEmpty()) postBody = mp;
private AtlasImportResult performImportData(BodyPart requestPart, BodyPart filePart) throws AtlasServiceException { MultiPart multipartEntity = new FormDataMultiPart() .bodyPart(requestPart) .bodyPart(filePart); return callAPI(IMPORT, AtlasImportResult.class, multipartEntity); }
FormDataMultiPart mp = new FormDataMultiPart(); if(hasFields) postBody = mp;
lFormData.add(token.tokenName, token.token); } else { form.field(token.tokenName, token.token);
} else if (body instanceof FormDataMultiPart) { FormDataMultiPart form = (FormDataMultiPart) body; File file = (File) form.getField("file").getEntity(); try { InputStream fileInStream = new FileInputStream(file);
public void undeploy(Archive<?> archive) throws DeploymentException { if (archive == null) { throw new IllegalArgumentException("archive must not be null"); } else { deploymentName = createDeploymentName(archive.getName()); try { // Build up the POST form to send to Glassfish final FormDataMultiPart form = new FormDataMultiPart(); form.field("target", this.configuration.getTarget(), MediaType.TEXT_PLAIN_TYPE); form.field("operation", DELETE_OPERATION, MediaType.TEXT_PLAIN_TYPE); glassFishClient.doUndeploy(this.deploymentName, form); } catch (GlassFishClientException e) { throw new DeploymentException("Could not undeploy " + archive.getName(), e); } } }
static void testUpload(TestParams testParams) throws Exception { FormDataMultiPart part = new FormDataMultiPart(); part.field( RestParams.COMMIT_ID, QUERY_PARAMS.get( RestParams.COMMIT_ID ) ); part.field( RestParams.MODULE_GROUPID, QUERY_PARAMS.get( RestParams.MODULE_GROUPID ) ); part.field( RestParams.MODULE_ARTIFACTID, QUERY_PARAMS.get( RestParams.MODULE_ARTIFACTID ) ); part.field( RestParams.MODULE_VERSION, QUERY_PARAMS.get( RestParams.MODULE_VERSION ) ); part.field( RestParams.USERNAME, QUERY_PARAMS.get( RestParams.USERNAME ) ); part.field( RestParams.VCS_REPO_URL, "ssh://git@stash.safehaus.org:7999/chop/main.git" ); part.field( RestParams.TEST_PACKAGE, QUERY_PARAMS.get( RestParams.TEST_PACKAGE ) ); part.field( RestParams.MD5, "d7d4829506f6cb8c0ab2da9cb1daca02" ); File tmpFile = File.createTempFile("runner", "jar"); FileInputStream in = new FileInputStream( tmpFile ); FormDataBodyPart body = new FormDataBodyPart( RestParams.CONTENT, in, MediaType.APPLICATION_OCTET_STREAM_TYPE ); part.bodyPart( body ); ClientResponse response = testParams.addQueryParameters( QUERY_PARAMS ) .setEndpoint( UploadResource.ENDPOINT ) .newWebResource() .path( "/runner" ) .type( MediaType.MULTIPART_FORM_DATA ) .accept( MediaType.TEXT_PLAIN ) .post( ClientResponse.class, part ); assertEquals( Response.Status.CREATED.getStatusCode(), response.getStatus() ); assertEquals( UploadResource.SUCCESSFUL_TEST_MESSAGE, response.getEntity( String.class ) ); tmpFile.delete(); }
FormDataMultiPart mp = new FormDataMultiPart(); hasFields = true; if(vertexIds != null) { for(String vertexId:vertexIds) { mp.field("vertexIds[]", vertexId, MediaType.MULTIPART_FORM_DATA_TYPE); } } if(hasFields && !mp.getFields().isEmpty()) postBody = mp;
protected ClientResponse multipartPost(final WebResource resource, final Map<String, Object> fields, final Iterable<BodyPart> bodyParts) { final WebResource.Builder builder = resource.type(MediaType.MULTIPART_FORM_DATA_TYPE); final FormDataMultiPart multiPart = new FormDataMultiPart(); for(final Map.Entry<String, Object> fieldEntry : fields.entrySet()) { final FormDataBodyPart bp = new FormDataBodyPart(fieldEntry.getKey(), fieldEntry.getValue(), MediaType.APPLICATION_JSON_TYPE); multiPart.bodyPart(bp); } for(final BodyPart bodyPart : bodyParts) { bodyPart.setMediaType(MediaType.APPLICATION_OCTET_STREAM_TYPE); multiPart.bodyPart(bodyPart); } return builder.post(ClientResponse.class, multiPart); }
FormDataMultiPart mp = new FormDataMultiPart(); if(hasFields) postBody = mp;