0

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

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>
4

0 回答 0