JAX-WS 客户端请求类

发布于 2024-11-28 13:10:43 字数 8371 浏览 1 评论 0原文

我正在尝试创建一个基于soap的java客户端来使用基于soap web服务的 http:// /api2.corbis.com/WSCorbisOne/CorbisImage.asmx?WSDL。 CorbisImageSoap.java 和 CorbisImage.java 是从 wsimport 自动生成的。我可以在 SOAPUI 中提交请求,但我无法让我的 java 客户端 (CorbisClient.java) 工作。我不确定需要如何处理 Holder searchResultDataXML 和 Holder imagesXML。它们看起来与响应相关,但我不确定如何处理请求,因为它们是搜索 api 中的参数。有什么想法吗?当我执行 CorbisClient.java 时,我得到“长度不能小于零。参数名称:长度”。

Soap 客户端执行下面的 Search 方法

public class CorbisClient {
    public static void main(String[] args){
        CorbisImage service = new CorbisImage();
        CorbisImageSoap port = service.getCorbisImageSoap();
        String sessionUID="valid id";
        String eSTok="valid param";
        String sVTok="";
        String itemsPerPage="20";
        String startPosition="1";
        String imageSearchRequestDataXML="xml here";
        String imageFormatDataXML="xml here";
        Holder<String> searchResultDataXML=new Holder<String>();
        Holder<String> imagesXML=new Holder<String>();
        port.search(sessionUID, eSTok, sVTok, itemsPerPage, startPosition, imageSearchRequestDataXML, imageFormatDataXML, searchResultDataXML, imagesXML);
    }
}

CorbisImageSoap.java 是我想要从 执行的生成方法http://api2.corbis.com/WSCorbisOne/CorbisImage.asmx?WSDL

@WebService(name = "CorbisImageSoap", targetNamespace = "http://c1.net.corbis.com/")
@XmlSeeAlso({
    ObjectFactory.class
})
public interface CorbisImageSoap {


    /**
     * 
     * @param sVTok
     * @param sessionUID
     * @param searchResultDataXML
     * @param eSTok
     * @param imageSearchRequestDataXML
     * @param imagesXML
     * @param itemsPerPage
     * @param imageFormatDataXML
     * @param startPosition
     */
    @WebMethod(operationName = "Search", action = "http://c1.net.corbis.com/Search")
    @RequestWrapper(localName = "Search", targetNamespace = "http://c1.net.corbis.com/", className = "com.corbis.net.c1.Search")
    @ResponseWrapper(localName = "SearchResponse", targetNamespace = "http://c1.net.corbis.com/", className = "com.corbis.net.c1.SearchResponse")
    public void search(
        @WebParam(name = "sessionUID", targetNamespace = "http://c1.net.corbis.com/")
        String sessionUID,
        @WebParam(name = "eSTok", targetNamespace = "http://c1.net.corbis.com/")
        String eSTok,
        @WebParam(name = "sVTok", targetNamespace = "http://c1.net.corbis.com/")
        String sVTok,
        @WebParam(name = "itemsPerPage", targetNamespace = "http://c1.net.corbis.com/")
        String itemsPerPage,
        @WebParam(name = "startPosition", targetNamespace = "http://c1.net.corbis.com/")
        String startPosition,
        @WebParam(name = "imageSearchRequestDataXML", targetNamespace = "http://c1.net.corbis.com/")
        String imageSearchRequestDataXML,
        @WebParam(name = "imageFormatDataXML", targetNamespace = "http://c1.net.corbis.com/")
        String imageFormatDataXML,
        @WebParam(name = "searchResultDataXML", targetNamespace = "http://c1.net.corbis.com/", mode = WebParam.Mode.OUT)
        Holder<String> searchResultDataXML,
        @WebParam(name = "imagesXML", targetNamespace = "http://c1.net.corbis.com/", mode = WebParam.Mode.OUT)
        Holder<String> imagesXML);

CorbisImage.java

@WebServiceClient(name = "CorbisImage", targetNamespace = "http://c1.net.corbis.com/", wsdlLocation = "http://api2.corbis.com/WSCorbisOne/CorbisImage.asmx?WSDL")
    public class CorbisImage
        extends Service
    {

        private final static URL CORBISIMAGE_WSDL_LOCATION;
        private final static Logger logger = Logger.getLogger(com.corbis.net.c1.CorbisImage.class.getName());

        static {
            URL url = null;
            try {
                URL baseUrl;
                baseUrl = com.corbis.net.c1.CorbisImage.class.getResource(".");
                url = new URL(baseUrl, "http://api2.corbis.com/WSCorbisOne/CorbisImage.asmx?WSDL");
            } catch (MalformedURLException e) {
                logger.warning("Failed to create URL for the wsdl Location: 'http://api2.corbis.com/WSCorbisOne/CorbisImage.asmx?WSDL', retrying as a local file");
                logger.warning(e.getMessage());
            }
            CORBISIMAGE_WSDL_LOCATION = url;
        }

        public CorbisImage(URL wsdlLocation, QName serviceName) {
            super(wsdlLocation, serviceName);
        }

        public CorbisImage() {
            super(CORBISIMAGE_WSDL_LOCATION, new QName("http://c1.net.corbis.com/", "CorbisImage"));
        }

        /**
         * 
         * @return
         *     returns CorbisImageSoap
         */
        @WebEndpoint(name = "CorbisImageSoap")
        public CorbisImageSoap getCorbisImageSoap() {
            return super.getPort(new QName("http://c1.net.corbis.com/", "CorbisImageSoap"), CorbisImageSoap.class);
        }

        /**
         * 
         * @param features
         *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
         * @return
         *     returns CorbisImageSoap
         */
        @WebEndpoint(name = "CorbisImageSoap")
        public CorbisImageSoap getCorbisImageSoap(WebServiceFeature... features) {
            return super.getPort(new QName("http://c1.net.corbis.com/", "CorbisImageSoap"), CorbisImageSoap.class, features);
        }

        /**
         * 
         * @return
         *     returns CorbisImageSoap
         */
        @WebEndpoint(name = "CorbisImageSoap12")
        public CorbisImageSoap getCorbisImageSoap12() {
            return super.getPort(new QName("http://c1.net.corbis.com/", "CorbisImageSoap12"), CorbisImageSoap.class);
        }

        /**
         * 
         * @param features
         *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
         * @return
         *     returns CorbisImageSoap
         */
        @WebEndpoint(name = "CorbisImageSoap12")
        public CorbisImageSoap getCorbisImageSoap12(WebServiceFeature... features) {
            return super.getPort(new QName("http://c1.net.corbis.com/", "CorbisImageSoap12"), CorbisImageSoap.class, features);
        }

    }

SOAPUI 响应:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Header>
      <wsu:Timestamp xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility">
         <wsu:Created>2011-08-10T05:04:00Z</wsu:Created>
         <wsu:Expires>2011-08-10T05:09:00Z</wsu:Expires>
      </wsu:Timestamp>
   </soap:Header>
   <soap:Body>
      <SearchResponse xmlns="http://c1.net.corbis.com/">
         <searchResultDataXML><![CDATA[<SearchResultData><SearchRequestUID Scope="Public" Type="Guid" Value="{34a38c64-5dbc-48df-8874-74d789a0dacd}"/><StartPosition Scope="Public" Type="Long" Value="1"/><EndPosition Scope="Public" Type="Long" Value="20"/><TotalHits Scope="Public" Type="Long" Value="323516"/></SearchResultData>]]></searchResultDataXML>
         <imagesXML><![CDATA[<Images><Image><ImageUID Scope="Public" Type="Guid" Value="{7f2535d0-9a41-4997-9694-0a4de569e6d9}"/><CorbisID Scope="Public" Type="String" Value="42-15534232"/><Title Scope="Public" Type="String" Value="Animal"/><CreditLine Scope="Public" Type="String" Value="© Robert Llewellyn/Corbis"/><IsRoyaltyFree Scope="Public" Type="Boolean" Value="False"/><AspectRatio Scope="Public" Type="String" Value="1.500000"/><URL128 Scope="Public" Type="String" Value="http://cachens.corbis.com/CorbisImage/thumb/15/53/42/15534232/42-15534232.jpg"/></Image></Images>]]></imagesXML>
      </SearchResponse>
   </soap:Body>
</soap:Envelope>

I'm trying to create a soap based java client to consume a soap web service based http://api2.corbis.com/WSCorbisOne/CorbisImage.asmx?WSDL. CorbisImageSoap.java and CorbisImage.java were automatically generated from wsimport. I'm able to submit the request in the SOAPUI just fine but I'm unable to get my java client (CorbisClient.java) to work. I'm unsure what I need to do with Holder searchResultDataXML and Holder imagesXML. They look related to the response, but I'm unsure what do with these for the request as they're parameters in the Search api. Any ideas? I get "Length cannot be less than zero. Parameter name: length" when I execute my CorbisClient.java.

soap client to execute the Search method below

public class CorbisClient {
    public static void main(String[] args){
        CorbisImage service = new CorbisImage();
        CorbisImageSoap port = service.getCorbisImageSoap();
        String sessionUID="valid id";
        String eSTok="valid param";
        String sVTok="";
        String itemsPerPage="20";
        String startPosition="1";
        String imageSearchRequestDataXML="xml here";
        String imageFormatDataXML="xml here";
        Holder<String> searchResultDataXML=new Holder<String>();
        Holder<String> imagesXML=new Holder<String>();
        port.search(sessionUID, eSTok, sVTok, itemsPerPage, startPosition, imageSearchRequestDataXML, imageFormatDataXML, searchResultDataXML, imagesXML);
    }
}

CorbisImageSoap.java is the generated method that I want to execute from http://api2.corbis.com/WSCorbisOne/CorbisImage.asmx?WSDL

@WebService(name = "CorbisImageSoap", targetNamespace = "http://c1.net.corbis.com/")
@XmlSeeAlso({
    ObjectFactory.class
})
public interface CorbisImageSoap {


    /**
     * 
     * @param sVTok
     * @param sessionUID
     * @param searchResultDataXML
     * @param eSTok
     * @param imageSearchRequestDataXML
     * @param imagesXML
     * @param itemsPerPage
     * @param imageFormatDataXML
     * @param startPosition
     */
    @WebMethod(operationName = "Search", action = "http://c1.net.corbis.com/Search")
    @RequestWrapper(localName = "Search", targetNamespace = "http://c1.net.corbis.com/", className = "com.corbis.net.c1.Search")
    @ResponseWrapper(localName = "SearchResponse", targetNamespace = "http://c1.net.corbis.com/", className = "com.corbis.net.c1.SearchResponse")
    public void search(
        @WebParam(name = "sessionUID", targetNamespace = "http://c1.net.corbis.com/")
        String sessionUID,
        @WebParam(name = "eSTok", targetNamespace = "http://c1.net.corbis.com/")
        String eSTok,
        @WebParam(name = "sVTok", targetNamespace = "http://c1.net.corbis.com/")
        String sVTok,
        @WebParam(name = "itemsPerPage", targetNamespace = "http://c1.net.corbis.com/")
        String itemsPerPage,
        @WebParam(name = "startPosition", targetNamespace = "http://c1.net.corbis.com/")
        String startPosition,
        @WebParam(name = "imageSearchRequestDataXML", targetNamespace = "http://c1.net.corbis.com/")
        String imageSearchRequestDataXML,
        @WebParam(name = "imageFormatDataXML", targetNamespace = "http://c1.net.corbis.com/")
        String imageFormatDataXML,
        @WebParam(name = "searchResultDataXML", targetNamespace = "http://c1.net.corbis.com/", mode = WebParam.Mode.OUT)
        Holder<String> searchResultDataXML,
        @WebParam(name = "imagesXML", targetNamespace = "http://c1.net.corbis.com/", mode = WebParam.Mode.OUT)
        Holder<String> imagesXML);

CorbisImage.java

@WebServiceClient(name = "CorbisImage", targetNamespace = "http://c1.net.corbis.com/", wsdlLocation = "http://api2.corbis.com/WSCorbisOne/CorbisImage.asmx?WSDL")
    public class CorbisImage
        extends Service
    {

        private final static URL CORBISIMAGE_WSDL_LOCATION;
        private final static Logger logger = Logger.getLogger(com.corbis.net.c1.CorbisImage.class.getName());

        static {
            URL url = null;
            try {
                URL baseUrl;
                baseUrl = com.corbis.net.c1.CorbisImage.class.getResource(".");
                url = new URL(baseUrl, "http://api2.corbis.com/WSCorbisOne/CorbisImage.asmx?WSDL");
            } catch (MalformedURLException e) {
                logger.warning("Failed to create URL for the wsdl Location: 'http://api2.corbis.com/WSCorbisOne/CorbisImage.asmx?WSDL', retrying as a local file");
                logger.warning(e.getMessage());
            }
            CORBISIMAGE_WSDL_LOCATION = url;
        }

        public CorbisImage(URL wsdlLocation, QName serviceName) {
            super(wsdlLocation, serviceName);
        }

        public CorbisImage() {
            super(CORBISIMAGE_WSDL_LOCATION, new QName("http://c1.net.corbis.com/", "CorbisImage"));
        }

        /**
         * 
         * @return
         *     returns CorbisImageSoap
         */
        @WebEndpoint(name = "CorbisImageSoap")
        public CorbisImageSoap getCorbisImageSoap() {
            return super.getPort(new QName("http://c1.net.corbis.com/", "CorbisImageSoap"), CorbisImageSoap.class);
        }

        /**
         * 
         * @param features
         *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
         * @return
         *     returns CorbisImageSoap
         */
        @WebEndpoint(name = "CorbisImageSoap")
        public CorbisImageSoap getCorbisImageSoap(WebServiceFeature... features) {
            return super.getPort(new QName("http://c1.net.corbis.com/", "CorbisImageSoap"), CorbisImageSoap.class, features);
        }

        /**
         * 
         * @return
         *     returns CorbisImageSoap
         */
        @WebEndpoint(name = "CorbisImageSoap12")
        public CorbisImageSoap getCorbisImageSoap12() {
            return super.getPort(new QName("http://c1.net.corbis.com/", "CorbisImageSoap12"), CorbisImageSoap.class);
        }

        /**
         * 
         * @param features
         *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
         * @return
         *     returns CorbisImageSoap
         */
        @WebEndpoint(name = "CorbisImageSoap12")
        public CorbisImageSoap getCorbisImageSoap12(WebServiceFeature... features) {
            return super.getPort(new QName("http://c1.net.corbis.com/", "CorbisImageSoap12"), CorbisImageSoap.class, features);
        }

    }

SOAPUI Response:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Header>
      <wsu:Timestamp xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility">
         <wsu:Created>2011-08-10T05:04:00Z</wsu:Created>
         <wsu:Expires>2011-08-10T05:09:00Z</wsu:Expires>
      </wsu:Timestamp>
   </soap:Header>
   <soap:Body>
      <SearchResponse xmlns="http://c1.net.corbis.com/">
         <searchResultDataXML><![CDATA[<SearchResultData><SearchRequestUID Scope="Public" Type="Guid" Value="{34a38c64-5dbc-48df-8874-74d789a0dacd}"/><StartPosition Scope="Public" Type="Long" Value="1"/><EndPosition Scope="Public" Type="Long" Value="20"/><TotalHits Scope="Public" Type="Long" Value="323516"/></SearchResultData>]]></searchResultDataXML>
         <imagesXML><![CDATA[<Images><Image><ImageUID Scope="Public" Type="Guid" Value="{7f2535d0-9a41-4997-9694-0a4de569e6d9}"/><CorbisID Scope="Public" Type="String" Value="42-15534232"/><Title Scope="Public" Type="String" Value="Animal"/><CreditLine Scope="Public" Type="String" Value="© Robert Llewellyn/Corbis"/><IsRoyaltyFree Scope="Public" Type="Boolean" Value="False"/><AspectRatio Scope="Public" Type="String" Value="1.500000"/><URL128 Scope="Public" Type="String" Value="http://cachens.corbis.com/CorbisImage/thumb/15/53/42/15534232/42-15534232.jpg"/></Image></Images>]]></imagesXML>
      </SearchResponse>
   </soap:Body>
</soap:Envelope>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文