2016-07-13 3 views
0

Jersey(2.22.2)& JaxRsを使用してfileuploadのサポートを構築したいと考えています。JerseyとJaxRで動作しないマルチフォームフォームデータ

これは私のアプリケーションです:

@ApplicationPath("rest") 
public class DsmJaxRsApplication extends Application { 

    @Override 
    public Set<Class<?>> getClasses() { 
     Set<Class<?>> classes = new HashSet<>(); 

     classes.add(FileUploadResource.class); 
     classes.add(MultiPartFeature.class); 

     return classes; 
    } 
} 

これは、POSTリクエストインターセプトするために私のリソースの方法である:

@POST 
@Consumes(MediaType.MULTIPART_FORM_DATA) 
@Produces(MediaType.TEXT_PLAIN) 
@Path("upload") 
public Response uploadImportFile(@FormDataParam("reason") String reason, 
           @FormDataParam("fileName") String fileName, 
           @FormDataParam("file") InputStream fileContent) { 
    checkCreateBulkChangeAllowed(); 

    return Response.ok().build(); 
} 

を、これは私の要求ペイロードである:

------WebKitFormBoundaryAh9J98cKgsOv6WCr 
Content-Disposition: form-data; name="reason" 

wwwww 
------WebKitFormBoundaryAh9J98cKgsOv6WCr 
Content-Disposition: form-data; name="fileName" 

DSM_CH_Bulk_new.xlsx 
------WebKitFormBoundaryAh9J98cKgsOv6WCr 
Content-Disposition: form-data; name="file"; filename="DSM_CH_Bulk_new.xlsx" 
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet 


------WebKitFormBoundaryAh9J98cKgsOv6WCr-- 

問題その方法の中では、fileContentreason co理由となるべき「wwww」があり、fileNameは常にnullです。誰に何が間違っているのか、私はここで何が分からないのか分かりませんか?

答えて

0

構成はweb.xmlファイルに基づいています。ここで FormDataContentDisposition

@POST 
@Path("upload/file") 
@Consumes(MediaType.MULTIPART_FORM_DATA) 
@Produces(MediaType.APPLICATION_JSON) 
public Response uploadInspectionFile(@FormDataParam("file") InputStream inputStream, 
     @FormDataParam("file") FormDataContentDisposition content, 
     @FormDataParam("path") String path) 

UPDATE

を追加しようとすると、私のweb.xmlファイル内の私のサーブレットです:

<servlet> 
    <servlet-name>servlet_inspector</servlet-name> 
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> 
    <init-param> 
     <param-name>jersey.config.server.provider.packages</param-name> 
     <param-value>io.swagger.jaxrs.listing,com.sagasoftware.service;com.sagasoftware.custom.filter</param-value> 
    </init-param> 
    <init-param> 
     <param-name>jersey.config.server.provider.classnames</param-name> 
     <param-value> 
      org.glassfish.jersey.media.multipart.MultiPartFeature , 
      io.swagger.jaxrs.listing.ApiListingResource, 
      io.swagger.jaxrs.listing.SwaggerSerializers, 
    </param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

、ここでは私の依存関係です:

<properties> 
    <jersey.version>2.22.1</jersey.version> 
    <jackson.version>2.6.1</jackson.version> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties> 
<version>1</version> 

<dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>org.glassfish.jersey</groupId> 
      <artifactId>jersey-bom</artifactId> 
      <version>${jersey.version}</version> 
      <type>pom</type> 
      <scope>import</scope> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 

<dependencies> 

    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>5.0.4.Final</version> 
    </dependency> 

    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-c3p0</artifactId> 
     <version>5.0.7.Final</version> 
    </dependency> 

    <dependency> 
     <groupId>javax.transaction</groupId> 
     <artifactId>jta</artifactId> 
     <version>1.1</version> 
    </dependency> 

    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.9</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.39</version> 
    </dependency> 

    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.17</version> 
    </dependency> 

    <dependency> 
     <groupId>com.google.code.gson</groupId> 
     <artifactId>gson</artifactId> 
     <version>2.4</version> 
    </dependency> 

    <dependency> 
     <groupId>org.glassfish.jersey.containers</groupId> 
     <artifactId>jersey-container-servlet-core</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.glassfish.jersey.media</groupId> 
     <artifactId>jersey-media-json-jackson</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.glassfish.jersey.core</groupId> 
     <artifactId>jersey-common</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     <version>2.5</version> 
    </dependency> 

    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>javax.servlet-api</artifactId> 
     <version>3.1.0</version> 
    </dependency> 

    <dependency> 
     <groupId>javax.mail</groupId> 
     <artifactId>mail</artifactId> 
     <version>1.5.0-b01</version> 
    </dependency> 

    <dependency> 
     <groupId>org.glassfish.jersey.media</groupId> 
     <artifactId>jersey-media-multipart</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>commons-io</groupId> 
     <artifactId>commons-io</artifactId> 
     <version>2.4</version> 
    </dependency> 

    <dependency> 
     <groupId>org.quartz-scheduler</groupId> 
     <artifactId>quartz</artifactId> 
     <version>2.2.2</version> 
    </dependency> 

    <dependency> 
     <groupId>com.fasterxml.jackson.core</groupId> 
     <artifactId>jackson-annotations</artifactId> 
     <version>${jackson.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>com.fasterxml.jackson.core</groupId> 
     <artifactId>jackson-core</artifactId> 
     <version>${jackson.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>io.swagger</groupId> 
     <artifactId>swagger-jersey2-jaxrs</artifactId> 
     <version>1.5.9</version> 
    </dependency> 

    <dependency> 
     <groupId>io.swagger</groupId> 
     <artifactId>swagger-annotations</artifactId> 
     <version>1.5.9</version> 
    </dependency> 

</dependencies> 
+0

' FormDataContentDisposition'とそのオブジェクトもnullです、web.xml設定を私に提供することはできますか、多分私はそれを理解することができます。 – Marius

+0

@マリアス私は私の答えを更新しました。また、私は最終的なFormDataMultiPartエンティティを使用している人々を見てきました。あなたのリソースメソッドは次のようになります:public Response uploadImportFile(final FormDataMultiPart entity){....} –

関連する問題