它无法使用以下服务:
XML返回
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<order>
<id>
<![CDATA[ 1 ]]>
</id>
<date_add>
<![CDATA[ 2014-08-22 16:26:15 ]]>
</date_add>
</order>
</prestashop>
Class VO
import org.eclipse.persistence.oxm.annotations.XmlCDATA;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name="prestashop")
public class Pedido {
@XmlCDATA public Integer id=null;
@XmlCDATA public String date_add=null; //Fecha creación
}
Java客户端
import java.net.URI;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
public class ClienteRest {
public static void main(String[] args) {
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
Pedido pedido = new Pedido();
client.addFilter(new HTTPBasicAuthFilter("WZWVR59997VL4BMKDV99C7GA1RBYGGBF", ""));
WebResource service = client.resource(getBaseURI());
// Get XML
System.out.println(service.path("orders").path("1").accept(MediaType.TEXT_XML).get(ClientResponse.class));
ClientResponse response = service.path("orders").path("1").accept(MediaType.TEXT_XML).get(ClientResponse.class);
// Get XML for application
Pedido oPedido = response.getEntity(pedido.getClass());
System.out.println(oPedido.total_paid);
}
private static URI getBaseURI() {
return UriBuilder.fromUri("http://WZWVR59997VL4BMKDV99C7GA1RBYGGBF@example.com/api").build();
}
}
这是java程序的输出
GET http://WZWVR59997VL4BMKDV99C7GA1RBYGGBF@example.com/api/orders/1返回的响应状态为200 OK 空
我想恢复对象类当getEntity始终返回null
时,Order of XML不起作用答案 0 :(得分:0)
VO类似乎与xml不匹配,xml似乎代表以下VO:
@XmlRootElement(name="prestashop")
public class Pedido {
private Order order;
public Order getOrder(){
return order;
}
public void setOrder(Order o){
order = o;
}
}
public class Order {
@XmlCDATA public Integer id=null;
@XmlCDATA public String date_add=null;
}