刚开始java开发并尝试构建一个简单的客户端 - 服务器应用程序。我在服务器端使用JAX-RS,在客户端使用RESTlet。 我想调用服务器端的@GET方法并返回一个Customer对象列表
以下是一些代码:
服务器
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public ArrayList<Customer> showAllCustomers() {
ArrayList<Customer> list = DBAccess.getInstance().getAllCustomers();
return list;
}
客户
package RESTlet;
import java.util.ArrayList;
import org.restlet.resource.Delete;
import org.restlet.resource.Get;
import org.restlet.resource.Put;
import customer.model.Customer;
public interface CustomerResource {
@Get
public ArrayList<Customer> retrieve();
@Put
public void store(Customer contact);
@Delete
public void remove();
}
我尝试接收主类中的列表
public class MainApplication {
public static void main(String[] args) {
ClientResource cr = new ClientResource("http://localhost:8080/CustomerRESTServicex/rest/customer");
// Get the Contact object
CustomerResource resource = cr.wrap(CustomerResource.class);
ArrayList <Customer> customerList = resource.retrieve();
for (Customer customer : customerList) {
System.out.println(customer.getFirstname() + " " + customer.getLastname() + ", " + customer.getStreet() + " " + customer.getStreetnr());
}
}
}
这是我得到的例外
Exception in thread "main" Not Acceptable (406) - Not Acceptable
我很期待收到你的来信。