使用Jersey解组XML元素

时间:2013-01-31 15:04:01

标签: java rest jersey

我正在为一个宁静的客户工作。我从restful webservice获得了这个xml标签:

<ProductRegistration pf:urn="urn:nipf:product-registration:IB:NIC:9472693" pf:url="http://immix-dev.natinst.com/cpr-rest/1/en/product-registration/IB:NIC:9472693.xml?dataset=full" pf:locale="en">

....

此元素包含我需要存储的几件事。我有这个java对象来存储标签和我需要的所有信息。

@XmlRootElement(name ="ProductRegistration")
public class ProductRegistration {

    private ProductItem productItem;    
    private InstalledProduct installedProduct;

    @XmlElement(name = "productItem")
    public ProductItem getProductItem() {
        return productItem;
    }
    public void setProductItem(ProductItem productItem) {
        this.productItem = productItem;
    }

    @XmlElement(name = "installedProduct")
    public InstalledProduct getInstalledProduct() {
        return installedProduct;
    }
    public void setInstalledProduct(InstalledProduct installedProduct) {
        this.installedProduct = installedProduct;
    }
}

我正在做这样的连接:

public Collection<ProductRegistration> get(String url){
        GenericType<Collection<ProductRegistration>> productRegistrationType = new GenericType<Collection<ProductRegistration>>(){};

        WebResource webResource = getWebResource(url);      

        return webResource.get(productRegistrationType);
}

它发送一个集合,因为WS返回一个productRegistration对象列表。但是当我尝试将WS的结果存储在Java对象中时,我收到“错误请求”错误。有任何想法吗? --edit -

信封看起来像这样:

<ProductRegistrations xmlns:pdi="http://www.mywebpage.com/schemas/provider-framework/pdi/2" xmlns:contact="http://www.mywebpage.com/schemas/provider-framework/contact/1" xmlns:pf="http://www.mywebpage.com/schemas/provider-framework/1/providers" xmlns:ib="http://www.mywebpage.com/schemas/provider-framework/ib/2" xmlns="http://www.mywebpage.com/schemas/provider-framework/cpr/1" xmlns:tca="http://www.mywebpage.com/schemas/provider-framework/tca/1" xmlns:up="http://www.mywebpage.com/schemas/provider-framework/up/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" pf:url="http://immix-dev.mywebpage.com/cpr-rest/1/en/product-registration/byContact.xml?contactRepresentation=urn:nipf:up-contact-address:2061817&dataset=full" retrieved="true" xsi:schemaLocation="http://www.mywebpage.com/schemas/provider-framework/cpr/1 http://immix-dev.mywebpage.com/cpr-rest/1/meta/schema.xsd">

1 个答案:

答案 0 :(得分:-1)

将名称空间注释添加到ProductRegistration类:

@XmlType(namespace="..wherever pf comes from..")