Cde*_*eez 1 web-services jersey postman
我使用 Jersey Restful API 创建了一个网络服务,我有以下内容:
@POST
@Path("/process/")
@Consumes({MediaType.MULTIPART_FORM_DATA})
@Produces({MediaType.APPLICATION_JSON})
public Response process(@FormDataParam("upload") InputStream is, @FormDataParam("upload") FormDataContentDisposition formData);
Run Code Online (Sandbox Code Playgroud)
我使用了以下依赖项:
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1-m01</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.jersey.contribs/jersey-multipart -->
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>1.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-server -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.ws.rs/jsr311-api -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
Web.xml 中的配置:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/ws-context.xml</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)
在 ws-context.xml 中,我有这部分:
<bean id="restManagerService" class="com.rs.service.impl.RestManagerServiceImpl">
<property name="restRequestService" ref="restRequestService" />
</bean>
<bean id="jsonProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="100000" />
</bean>
<jaxrs:server id="userManagerREST" address="/rest/v1">
<jaxrs:serviceBeans>
<ref bean="restManagerService" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean='jsonProvider' />
<ref bean='multipartResolver' />
<bean class="com.rs.exception.ExceptionHandler" />
</jaxrs:providers>
</jaxrs:server>
Run Code Online (Sandbox Code Playgroud)
现在为了测试这一点,我使用 Postman 应用程序发送 Post 请求。以下是代码窗口中的内容:
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryxxxxxxxxx
------WebKitFormBoundaryxxxxxxxxx
Content-Disposition: form-data; name="upload"; filename="test.json"
Run Code Online (Sandbox Code Playgroud)
我已经在 google 上参考了几个示例,例如this、this和this,我看到我已经正确提供了参数,但在 Postman 中仍然出现 415 Unsupported Media Type 错误。我在这个项目中有几个其他的 Web 服务,它们使用 MediaType 应用程序/json,所以项目配置应该不是问题。
有人可以解释一下这里出了什么问题。
更新:添加了与使用的所有球衣和 WS 相关依赖项以及 web.xml 文件中的重要内容相关的其他详细信息
| 归档时间: |
|
| 查看次数: |
6915 次 |
| 最近记录: |