刚刚开始 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
我期待着您的来信。