使用JAXB的CXF 3.1 RESTful客户端错误:严重:未找到类的消息正文阅读器

时间:2015-08-05 19:24:12

标签: jaxb cxf unmarshalling

我是CXF和JAXB的新手。我在调用外部Web服务的RESTful客户端时遇到问题。我想我已经按照必要的步骤执行此操作但执行客户端时出现以下错误:

严重:找不到类com.jaxb.AcXML,ContentType:text / html的邮件正文阅读器 线程“main”中的异常javax.ws.rs.client.ResponseProcessingException:未找到类com.jaxb.AcXML,ContentType:text / html的消息正文阅读器     at org.apache.cxf.jaxrs.impl.ResponseImpl.reportMessageHandlerProblem(ResponseImpl.java:433)     at org.apache.cxf.jaxrs.impl.ResponseImpl.doReadEntity(ResponseImpl.java:384)     在org.apache.cxf.jaxrs.client.AbstractClient.readBody(AbstractClient.java:512)     在org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1173)     在org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1156)     在org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1092)     在org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:894)     在org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:865)     在org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:428)     在org.apache.cxf.jaxrs.client.WebClient.get(WebClient.java:611)     在com.ws.GetOpenPO.getOpenPOO(GetOpenPO.java:58)     在com.ws.GetOpenPO.main(GetOpenPO.java:79)

我的IDE是Eclipse Indigo。我创建了一个动态Web项目,包括CXF 2.x Web服务,JAX-RS和JAXB方面。以下是我正在测试的课程:

package com.ws;

import java.text.MessageFormat;

import javax.ws.rs.core.MediaType;

import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

import com.jaxb.AcXML;

 public class GetOpenPO {

 private String baseUrl;

 public AcXML getOpenPOs(  )
    {
        // Create a WebClient pointing to the base URL of the RESTful web service

        WebClient client = WebClient.create( baseUrl ).path("GetOpenPOs");          
        HTTPConduit http = WebClient.getConfig(client).getHttpConduit();
        HTTPClientPolicy httpClientPolicy=new HTTPClientPolicy();
        httpClientPolicy.setReceiveTimeout(1000000);
        httpClientPolicy.setConnectionTimeout(1000000);
        httpClientPolicy.setProxyServer("proxy1.global.mycompany.com");
        httpClientPolicy.setProxyServerPort(8080);
        http.setClient(httpClientPolicy);

        // Set the path from which we wish to get the object, request XML, and use JAXB

       AcXML POs= client.accept(MediaType.APPLICATION_XML)
                                            .query("U", "parm1")
                                            .query("P", "parm2")
                                            .query("N", "parm3")
                                            .query("Processed", "parm4")
                                            .query("StationEnd", "")
                                            .get( AcXML.class);

        return POs;
    }

    public String getBaseUrl()
    {
        return baseUrl;
    }

    public void setBaseUrl( String baseUrl )
    {
        this.baseUrl = baseUrl;
    }


    public static void main(String args[]){

        GetOpenPO  x = new GetOpenPO ();
        x.setBaseUrl("http://www24.externalws.net/webservices/webservices.asmx");

        AcXML openPOs = x.getOpenPOs(); 
    }
}

我能够通过我的浏览器调用webservice,它返回一个XML文档。使用此XML我创建了一个模式,然后使用Eclipse中的“来自模式的JAXB类”向导生成JAXB对象。下面是我试图通过客户端检索的AcXML实体的源文件:

//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2015.08.05 at 10:18:48 AM EDT 
//


package com.jaxb;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;


/**
 * <p>Java class for anonymous complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType>
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element ref="{https://www.externalws.net/acXMLSchema.xsd}Header"/>
 *         &lt;element ref="{https://www.externalws.net/acXMLSchema.xsd}Request"/>
 *       &lt;/sequence>
 *       &lt;attribute name="lang" use="required">
 *         &lt;simpleType>
 *           &lt;restriction base="{http://www.w3.org/2001/XMLSchema}    string">
 *           &lt;/restriction>
 *         &lt;/simpleType>
 *       &lt;/attribute>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
  * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "header",
    "request"
})
@XmlRootElement(name = "acXML")
public class AcXML {

@XmlElement(name = "Header", required = true)
protected Header header;
@XmlElement(name = "Request", required = true)
protected Request request;
@XmlAttribute(name = "lang", required = true)
protected String lang;

/**
 * Gets the value of the header property.
 * 
 * @return
 *     possible object is
 *     {@link Header }
 *     
 */
public Header getHeader() {
    return header;
}

/**
 * Sets the value of the header property.
 * 
 * @param value
 *     allowed object is
 *     {@link Header }
 *     
 */
public void setHeader(Header value) {
    this.header = value;
}

/**
 * Gets the value of the request property.
 * 
 * @return
 *     possible object is
 *     {@link Request }
 *     
 */
public Request getRequest() {
    return request;
}

/**
 * Sets the value of the request property.
 * 
 * @param value
 *     allowed object is
 *     {@link Request }
 *     
 */
public void setRequest(Request value) {
    this.request = value;
}

/**
 * Gets the value of the lang property.
 * 
 * @return
 *     possible object is
 *     {@link String }
 *     
 */
public String getLang() {
    return lang;
}

/**
 * Sets the value of the lang property.
 * 
 * @param value
 *     allowed object is
 *     {@link String }
 *     
 */
public void setLang(String value) {
    this.lang = value;
}

}

有人能告诉我我做错了什么或者我错过了什么导致客户失败?

谢谢。

1 个答案:

答案 0 :(得分:1)

添加JAXBProvider

                    img.attr("id", "imgUserDisplay");