Package com.sun.jersey.multipart

Examples of com.sun.jersey.multipart.FormDataMultiPart


        WebResource.Builder builder = client.resource(path).type(MULTIPART_FORM_DATA);
        builder = addApplicationKeyHeader(builder);
        if (platformParameters.requireResponseBody()) {
            builder.accept(mediaType);
        }
        FormDataMultiPart form = new FormDataMultiPart();
        form.bodyPart(new FormDataBodyPart("file", content, MediaType.APPLICATION_OCTET_STREAM_TYPE));
        return parseResponseWithoutId(responseClass, builder.put(ClientResponse.class, form), OK.getStatusCode());
    }
View Full Code Here


            Messages.getInstance().getString(
              "CommandLineProcessor.INFO_OPTION_METADATA_DOMAIN_ID_NAME" ), true, false );

    WebResource resource = client.resource( metadataImportURL );

    FormDataMultiPart part = new FormDataMultiPart();

    final String name = RepositoryFilenameUtils.separatorsToRepository( metadataDatasourceFile.getName() );
    final String ext = RepositoryFilenameUtils.getExtension( name );

    try {
      if ( ext.equals( ZIP_EXT ) ) {
        ZipInputStream zipInputStream = new ZipInputStream( new FileInputStream( metadataDatasourceFile ) );
        ZipEntry entry = zipInputStream.getNextEntry();
        while ( entry != null ) {
          final String entryName = RepositoryFilenameUtils.separatorsToRepository( entry.getName() );
          final String extension = RepositoryFilenameUtils.getExtension( entryName );
          File tempFile = null;
          boolean isDir = entry.getSize() == 0;
          if ( !isDir ) {
            tempFile = File.createTempFile( "zip", null );
            tempFile.deleteOnExit();
            FileOutputStream fos = new FileOutputStream( tempFile );
            IOUtils.copy( zipInputStream, fos );
            fos.close();
          }
          if ( extension.equals( METADATA_DATASOURCE_EXT ) ) {
            if ( metadataFileInZip == null ) {
              metadataFileInZip = new File( entryName );
              metadataFileInZipInputStream = new FileInputStream( metadataFileInZip );
            }
          }

          zipInputStream.closeEntry();
          entry = zipInputStream.getNextEntry();
        }
        zipInputStream.close();

        part.field( "overwrite", "true".equals( overwrite ) ? "true" : "false", MediaType.MULTIPART_FORM_DATA_TYPE );
        part.field( "domainId", domainId, MediaType.MULTIPART_FORM_DATA_TYPE ).field( "metadataFile",
            metadataFileInZipInputStream, MediaType.MULTIPART_FORM_DATA_TYPE );

        // If the import service needs the file name do the following.
        part.getField( "metadataFile" ).setContentDisposition(
            FormDataContentDisposition.name( "metadataFile" ).fileName( metadataFileInZip.getName() ).build() );

        // Response response
        ClientResponse response = resource.type( MediaType.MULTIPART_FORM_DATA ).post( ClientResponse.class, part );
        if ( response != null ) {
          String message = response.getEntity( String.class );
          System.out.println( Messages.getInstance().getString( "CommandLineProcessor.INFO_REST_RESPONSE_RECEIVED",
              message ) );
        }

      } else {
        FileInputStream metadataDatasourceInputStream = new FileInputStream( metadataDatasourceFile );

        part.field( "overwrite", "true".equals( overwrite ) ? "true" : "false", MediaType.MULTIPART_FORM_DATA_TYPE );
        part.field( "domainId", domainId, MediaType.MULTIPART_FORM_DATA_TYPE ).field( "metadataFile",
            metadataDatasourceInputStream, MediaType.MULTIPART_FORM_DATA_TYPE );

        // If the import service needs the file name do the following.
        part.getField( "metadataFile" ).setContentDisposition(
            FormDataContentDisposition.name( "metadataFile" ).fileName( metadataDatasourceFile.getName() ).build() );

        // Response response
        ClientResponse response = resource.type( MediaType.MULTIPART_FORM_DATA ).post( ClientResponse.class, part );
        if ( response != null ) {
          String message = response.getEntity( String.class );
          System.out.println( Messages.getInstance().getString( "CommandLineProcessor.INFO_REST_RESPONSE_RECEIVED",
              message ) );
        }
        metadataDatasourceInputStream.close();
      }
    } finally {
      metadataFileInZipInputStream.close();
      part.cleanup();
    }

  }
View Full Code Here

    WebResource resource = client.resource( analysisImportURL );
    FileInputStream inputStream = new FileInputStream( analysisDatasourceFile );
    String parms = "Datasource=" + datasourceName + ";overwrite=" + overwrite;

    FormDataMultiPart part = new FormDataMultiPart();
    part.field( "overwrite", "true".equals( overwrite ) ? "true" : "false", MediaType.MULTIPART_FORM_DATA_TYPE );

    if ( catalogName != null ) {
      part.field( "catalogName", catalogName, MediaType.MULTIPART_FORM_DATA_TYPE );
    }
    if ( datasourceName != null ) {
      part.field( "datasourceName", datasourceName, MediaType.MULTIPART_FORM_DATA_TYPE );
    }
    part.field( "parameters", parms, MediaType.MULTIPART_FORM_DATA_TYPE );

    part.field( "xmlaEnabledFlag", "true".equals( xmlaEnabledFlag ) ? "true" : "false",
        MediaType.MULTIPART_FORM_DATA_TYPE );
    part.field( "uploadAnalysis", inputStream, MediaType.MULTIPART_FORM_DATA_TYPE );

    // If the import service needs the file name do the following.
    part.getField( "uploadAnalysis" ).setContentDisposition(
        FormDataContentDisposition.name( "uploadAnalysis" ).fileName( analysisDatasourceFile.getName() ).build() );

    // Response response
    ClientResponse response = resource.type( MediaType.MULTIPART_FORM_DATA ).post( ClientResponse.class, part );
    if ( response != null ) {
      String message = response.getEntity( String.class );
      response.close();
      System.out.println( Messages.getInstance()
          .getString( "CommandLineProcessor.INFO_REST_RESPONSE_RECEIVED", message ) );
    }
    inputStream.close();
    part.cleanup();
  }
View Full Code Here

              .getInstance().getString( "CommandLineProcessor.INFO_OPTION_PATH_NAME" ), true, false );

      String importURL = contextURL + API_REPO_FILES_IMPORT;
      File fileIS = new File( filePath );
      InputStream in = new FileInputStream( fileIS );
      FormDataMultiPart part = new FormDataMultiPart();

      /*
       * wrap in a try/finally to ensure input stream is closed properly
       */
      try {
        initRestService();
        WebResource resource = client.resource( importURL );

        String overwrite =
            getOptionValue( Messages.getInstance().getString( "CommandLineProcessor.INFO_OPTION_OVERWRITE_KEY" ),
                Messages.getInstance().getString( "CommandLineProcessor.INFO_OPTION_OVERWRITE_NAME" ), true, false );
        String retainOwnership =
            getOptionValue(
                Messages.getInstance().getString( "CommandLineProcessor.INFO_OPTION_RETAIN_OWNERSHIP_KEY" ), Messages
                    .getInstance().getString( "CommandLineProcessor.INFO_OPTION_RETAIN_OWNERSHIP_NAME" ), true, false );
        String permission =
            getOptionValue( Messages.getInstance().getString( "CommandLineProcessor.INFO_OPTION_PERMISSION_KEY" ),
                Messages.getInstance().getString( "CommandLineProcessor.INFO_OPTION_PERMISSION_NAME" ), true, false );

        part.field( "importDir", path, MediaType.MULTIPART_FORM_DATA_TYPE );
        part.field( "overwriteAclPermissions", "true".equals( overwrite ) ? "true" : "false",
            MediaType.MULTIPART_FORM_DATA_TYPE );
        part.field( "retainOwnership", "true".equals( retainOwnership ) ? "true" : "false",
            MediaType.MULTIPART_FORM_DATA_TYPE );
        part.field( "charSet", charSet == null ? "UTF-8" : charSet );
        part.field( "applyAclPermissions", "true".equals( permission ) ? "true" : "false",
            MediaType.MULTIPART_FORM_DATA_TYPE ).field( "fileUpload", in, MediaType.MULTIPART_FORM_DATA_TYPE );

        // If the import service needs the file name do the following.
        part.field( "fileNameOverride", fileIS.getName(), MediaType.MULTIPART_FORM_DATA_TYPE );
        part.getField( "fileUpload" ).setContentDisposition(
            FormDataContentDisposition.name( "fileUpload" ).fileName( fileIS.getName() ).build() );

        // Response response
        ClientResponse response = resource.type( MediaType.MULTIPART_FORM_DATA ).post( ClientResponse.class, part );
        if ( response != null ) {
          String message = response.getEntity( String.class );
          System.out.println( Messages.getInstance().getString( "CommandLineProcessor.INFO_REST_RESPONSE_RECEIVED",
              message ) );
          if ( logFile != null && !"".equals( logFile ) ) {
            writeFile( message, logFile );
          }
          response.close();
        }
      } catch ( Exception e ) {
        System.err.println( e.getMessage() );
        log.error( e.getMessage() );
        writeFile( e.getMessage(), logFile );
      } finally {
        // close input stream and cleanup the jersey resources
        client.destroy();
        part.cleanup();
        in.close();
      }
    }
  }
View Full Code Here

   * @param pool AppThwackDevicePool which represents collection of devices to test on (native only)
   * @param optionalParams Map of optional parameters to configure this run
   * @return AppThwackRun which represents the scheduled run
   */
  private AppThwackRun scheduleRun(String name, String app, AppThwackDevicePool pool, HashMap<String, String> optionalParams) {
    FormDataMultiPart form = new FormDataMultiPart();
    form.field("project", Integer.toString(id));
    form.field("name", name);
    form.field("app", app);
   
    if(pool != null) {
      form.field("pool", Integer.toString(pool.id));
    }
   
    if(optionalParams != null) {
      for(Map.Entry<String, String> entry : optionalParams.entrySet()) {
        form.field(entry.getKey(), entry.getValue());
      }
    }
   
    AppThwackRun run = root.path("run").type(MediaType.MULTIPART_FORM_DATA).post(AppThwackRun.class, form);
    run.setRoot(root);
View Full Code Here

        }
        if(!file.isFile()) {
            throw new AppThwackException("file cannot be a directory");
        }

        FormDataMultiPart form = new FormDataMultiPart();
        form.field("name", name);
        form.bodyPart(new FileDataBodyPart("file", file, MediaType.APPLICATION_OCTET_STREAM_TYPE));

        return root.path("file").type(MediaType.MULTIPART_FORM_DATA).post(AppThwackFile.class, form);
    }
View Full Code Here

    {
        final WebResource.Builder builder = client.resource(soda2ifyUri(uri))
                                                  .accept(acceptType)
                                                  .type(MediaType.MULTIPART_FORM_DATA_TYPE);

        FormDataMultiPart form = new FormDataMultiPart();
        form.bodyPart(new FileDataBodyPart(file.getName(), file, mediaType));

        final ClientResponse response = builder.post(ClientResponse.class, form);
        return processErrors(response);
    }
View Full Code Here

    {
        final WebResource.Builder builder = client.resource(soda2ifyUri(uri))
                                                  .accept(acceptType)
                                                  .type(MediaType.MULTIPART_FORM_DATA_TYPE);

        FormDataMultiPart form = new FormDataMultiPart();
        form.bodyPart(new FileDataBodyPart(file.getName(), file, mediaType));

        final ClientResponse response = builder.put(ClientResponse.class, form);
        return processErrors(response);
    }
View Full Code Here

    @Test
    public void testPart() {
        WebResource webResource = resource().path("form/part");

        FormDataMultiPart mp = new FormDataMultiPart();
        FormDataBodyPart p = new FormDataBodyPart(FormDataContentDisposition.name("part").build(), "CONTENT");
        mp.bodyPart(p);

        String s = webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(String.class, mp);
        Assert.assertEquals("CONTENT", s);
    }
View Full Code Here

    @Test
    public void testPartWithFileName() {
        WebResource webResource = resource().path("form/part-file-name");

        FormDataMultiPart mp = new FormDataMultiPart();
        FormDataBodyPart p = new FormDataBodyPart(FormDataContentDisposition.name("part").fileName("file").build(), "CONTENT");
        mp.bodyPart(p);

        String s = webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(String.class, mp);
        Assert.assertEquals("CONTENT:file", s);
    }
View Full Code Here

TOP

Related Classes of com.sun.jersey.multipart.FormDataMultiPart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.