Resteasy + Maven,REST调用返回Server 415响应代码

时间:2012-12-05 20:38:39

标签: java spring resteasy

我正在使用maven开发一个java项目,我想使用RESTeasy来构建RESTful Web服务。我写了一个测试来检查RESTeasy的功能,但我总是得到HTTP Error 415 Unsupported媒体类型。我认为问题是我没有将Content-Type标头定义为JSON所以它会变成kaput,但我不知道该怎么做。怎么办?

BoardingPassProxy.java:

package com.boardingpass.clients.rest;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

import com.BoardingPassRequest;

public interface BoardingPassProxy {

@POST
@Produces("application/json")
@Consumes("application/json")
public Response getBoardingPassImage(BoardingPassRequest boardingPassRequest);

} 

BoardingPassService.java:

package com.boardingpass.clients.rest;

import org.jboss.resteasy.client.ProxyFactory;
import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
import org.jboss.resteasy.spi.ResteasyProviderFactory;

public class BoardingPassService {

public BoardingPassService() {
    RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
}

public BoardingPassProxy getProxy(String endpoint) {
        BoardingPassProxy proxy = ProxyFactory.create(BoardingPassProxy.class, endpoint);
        return proxy;
    }
}

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
    <groupId>boardingpass</groupId>
    <artifactId>boardingpass-parent</artifactId>
    <version>2.1-SNAPSHOT</version>
</parent>
<packaging>jar</packaging>
<artifactId>boardingpass-client</artifactId>
<name>Boarding Pass Client</name>

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
    <repository>
        <id>JBoss repository</id>
        <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
    </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20080701</version>
  </dependency>

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

      <dependency>
          <groupId>boardingpass</groupId>
          <artifactId>boardingpass-core</artifactId>
      </dependency>

      <dependency>
          <groupId>org.jboss.resteasy</groupId>
          <artifactId>resteasy-jaxrs</artifactId>
          <version>2.3.3.Final</version>
       </dependency>

       <dependency>
           <groupId>org.mockito</groupId>
           <artifactId>mockito-all</artifactId>
           <version>1.8.5</version>
           <scope>test</scope>
       </dependency>

       <dependency> 
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jackson-provider</artifactId>
            <version>2.2.1.GA</version>
        </dependency>
    </dependencies>

</project>

0 个答案:

没有答案