@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 ); }
FormDataBodyPart body = new FormDataBodyPart( RestParams.CONTENT, in, MediaType.APPLICATION_OCTET_STREAM_TYPE ); multipart.bodyPart( body );
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(); }
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 ) ); }
private FormDataBodyPart getImportRequestBodyPart(AtlasImportRequest request) { return new FormDataBodyPart(IMPORT_REQUEST_PARAMTER, AtlasType.toJson(request), MediaType.APPLICATION_JSON_TYPE); }
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); }
.size(file.length()) .build(); com.sun.jersey.multipart.FormDataBodyPart bodyPart = new com.sun.jersey.multipart.FormDataBodyPart(dispo, file, MediaType.MULTIPART_FORM_DATA_TYPE); mp.bodyPart(bodyPart); if(hasFields)
.size(file.length()) .build(); com.sun.jersey.multipart.FormDataBodyPart bodyPart = new com.sun.jersey.multipart.FormDataBodyPart(dispo, file, MediaType.MULTIPART_FORM_DATA_TYPE); mp.bodyPart(bodyPart); if(hasFields)
.size(file.length()) .build(); com.sun.jersey.multipart.FormDataBodyPart bodyPart = new com.sun.jersey.multipart.FormDataBodyPart(dispo, file, MediaType.MULTIPART_FORM_DATA_TYPE); mp.bodyPart(bodyPart); if(hasFields)
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 );
@Override public IOsKeyResponse unlockKey(WebResource resource, ResourcePath<Key> keyResourcePath, IOsKeyUnlockRequest iOsKeyUnlockRequest) { try { FormDataMultiPart multiPart = new FormDataMultiPart(); multiPart.bodyPart(new FormDataBodyPart("data", iOsKeyUnlockRequest, MediaType.APPLICATION_JSON_TYPE)); return resource.path(keyResourcePath.getPath()).type(MediaType.MULTIPART_FORM_DATA_TYPE).put( IOsKeyResponse.class, multiPart); } catch (UniformInterfaceException e) { throw new ApiException(e.getResponse().getEntity(ErrorResponse.class), e); } }
@Override public AndroidKeyResponse unlockKey(WebResource resource, ResourcePath<Key> keyResourcePath, AndroidKeyUnlockRequest androidKeyUnlockRequest) { try { FormDataMultiPart multiPart = new FormDataMultiPart(); multiPart.bodyPart(new FormDataBodyPart("data", androidKeyUnlockRequest, MediaType.APPLICATION_JSON_TYPE)); return resource.path(keyResourcePath.getPath()).type(MediaType.MULTIPART_FORM_DATA_TYPE).put( AndroidKeyResponse.class, multiPart); } catch (UniformInterfaceException e) { throw new ApiException(e.getResponse().getEntity(ErrorResponse.class), e); } }
@Override public AppResponse updateAppDetails(final WebResource resource, final ResourcePath<App> keyResourcePath, final AppDetailsRequest appDetailsRequest) { try { final FormDataMultiPart multiPart = new FormDataMultiPart(); multiPart.bodyPart(new FormDataBodyPart("data", appDetailsRequest, MediaType.APPLICATION_JSON_TYPE)); return resource.path(keyResourcePath.getPath()).type(MediaType.MULTIPART_FORM_DATA_TYPE).put( AppResponse.class, multiPart); } catch (UniformInterfaceException e) { throw new ApiException(e.getResponse().getEntity(ErrorResponse.class), e); } }
.size(fileForImport.getFile().length()) .build(); FormDataBodyPart bodyPart = new FormDataBodyPart(dispo, fileForImport.getFile(), MediaType.MULTIPART_FORM_DATA_TYPE); mp.bodyPart(bodyPart);
@Override public AppResponse postNewApp(WebResource resource, ResourcePath<Apps> appsResponsePath, AppDetailsRequest appsRequest, File file) { try { FormDataMultiPart multiPart = new FormDataMultiPart(); multiPart.bodyPart(new FileDataBodyPart("file", file)); multiPart.bodyPart(new FormDataBodyPart("data", appsRequest, MediaType.APPLICATION_JSON_TYPE)); return resource.path(appsResponsePath.getPath()).type(MediaType.MULTIPART_FORM_DATA_TYPE).post(AppResponse.class, multiPart); } catch (UniformInterfaceException e) { throw new ApiException(e.getResponse().getEntity(ErrorResponse.class), e); } }
@Override public AndroidKeyResponse postNewKey(WebResource resource, ResourcePath<PlatformKeys> platformResourcePath, AndroidKeyRequest androidKeyRequest, File keystore) { try { FormDataMultiPart multiPart = new FormDataMultiPart(); multiPart.bodyPart(new FileDataBodyPart("keystore", keystore)); multiPart.bodyPart(new FormDataBodyPart("data", androidKeyRequest, MediaType.APPLICATION_JSON_TYPE)); return resource.path(platformResourcePath.getPath()).type(MediaType.MULTIPART_FORM_DATA_TYPE).post( AndroidKeyResponse.class, multiPart); } catch (UniformInterfaceException e) { throw new ApiException(e.getResponse().getEntity(ErrorResponse.class), e); } }
@Override public AppResponse putApp(WebResource resource, ResourcePath<App> appResourcePath, AppDetailsRequest appsRequest, File file) { try { FormDataMultiPart multiPart = new FormDataMultiPart(); multiPart.bodyPart(new FileDataBodyPart("file", file)); if (appsRequest != null) { multiPart.bodyPart(new FormDataBodyPart("data", appsRequest, MediaType.APPLICATION_JSON_TYPE)); } return resource.path(appResourcePath.getPath()).type(MediaType.MULTIPART_FORM_DATA_TYPE).put(AppResponse.class, multiPart); } catch (UniformInterfaceException e) { throw new ApiException(e.getResponse().getEntity(ErrorResponse.class), e); } }
@Override public IOsKeyResponse postNewKey(WebResource resource, ResourcePath<PlatformKeys> platformResourcePath, IOsKeyRequest iOsKeyRequest, File cert, File profile) { try { FormDataMultiPart multiPart = new FormDataMultiPart(); multiPart.bodyPart(new FileDataBodyPart("cert", cert)); multiPart.bodyPart(new FileDataBodyPart("profile", profile)); multiPart.bodyPart(new FormDataBodyPart("data", iOsKeyRequest, MediaType.APPLICATION_JSON_TYPE)); return resource.path(platformResourcePath.getPath()).type(MediaType.MULTIPART_FORM_DATA_TYPE).post( IOsKeyResponse.class, multiPart); } catch (UniformInterfaceException e) { throw new ApiException(e.getResponse().getEntity(ErrorResponse.class), e); } }
FormDataBodyPart artifactPart = new FormDataBodyPart(cd.build(), inputStream, MediaType.valueOf(mediaType)); multiPart.getBodyParts().add(artifactPart); ClientRequest request = createAuthenticatedGedcomxRequest().type(MediaType.MULTIPART_FORM_DATA_TYPE).entity(multiPart).build(link.getHref().toURI(), HttpMethod.POST);
FormDataBodyPart artifactPart = new FormDataBodyPart(cd.build(), inputStream, MediaType.valueOf(mediaType)); multiPart.getBodyParts().add(artifactPart); ClientRequest request = state.createAuthenticatedGedcomxRequest().type(MediaType.MULTIPART_FORM_DATA_TYPE).entity(multiPart).build(link.getHref().toURI(), HttpMethod.POST);