Link to home
Start Free TrialLog in
Avatar of cgray1223
cgray1223

asked on

JAX-WS SOAP Client Request Class

Hello,

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<String> searchResultDataXML and Holder<String> 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);
    	}
    }

Open in new window



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);

Open in new window


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);
            }
        
        }

Open in new window


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>

Open in new window

Avatar of sweetfa2
sweetfa2
Flag of Australia image

A couple of things to try:

Set the following property when invoking your client.  This should turn debugging on for your http transport layer so you can see what is being sent across
com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true

Open in new window


Try not initialising your response parameters.

Include a copy of your soapui request so we can see what it looks like and work out how it may differ from what your client is generating.
Avatar of cgray1223
cgray1223

ASKER

thanks for the help.  soap request below

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:c1="http://c1.net.corbis.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <c1:Search>
         <!--Optional:-->
         <c1:sessionUID>{d03746d7-aae0-4b47-80fd-e730d10c3d52}</c1:sessionUID>
         <!--Optional:-->
         <c1:eSTok>rd/hgoe9D+8GjhzH2EK/WHIP9YZSP1ikdM04yTrqmcaJZ/myvTQjQt9ipsuq44ZHgyRUsDorTkr2z0DY8fW6BlxrSdfilY5fa78BwHw+nfgOlX62n/fMkEtS/dh35v0nfvzQvxn8PgIUQk7V38J6HeW09MIciUBtuX0nUt1sel4=</c1:eSTok>
         <!--Optional:-->
         <c1:sVTok></c1:sVTok>
         <!--Optional:-->
         <c1:itemsPerPage>20</c1:itemsPerPage>
         <!--Optional:-->
         <c1:startPosition>1</c1:startPosition>
         <!--Optional:-->
         <c1:imageSearchRequestDataXML>&lt;SearchRequest&gt; &lt;KeywordSearch Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;animal&quot; /&gt; &lt;ImageID Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;QueryType Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;Location Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;Photographer Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;MediaDate Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;Collections Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;PointOfView Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;ColorFormat Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;Orientation Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;NoOfPeople Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;DownloadableSize Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;RoyaltyFree Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;RF_TL&quot; /&gt; &lt;ModelRelease Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;MaxHits Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;250&quot; /&gt; &lt;DateAdded Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;DatePublished Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;SearchSegment Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;LanguageCode Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;en-US&quot; /&gt; &lt;MagazineName Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;Categories Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;ContentTypes /&gt; &lt;MediaTypes Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;Source Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;PrimarySubject Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;SecondarySubject Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;Subsection Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;QueryLink Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;AllImages Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;SortOrder Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;ClientIP Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;76.102.97.125&quot; /&gt; &lt;/SearchRequest&gt;</c1:imageSearchRequestDataXML>
         <!--Optional:-->
         <c1:imageFormatDataXML>&lt;ImageFormatData&gt; &lt;IncludeContentWarnings Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;False&quot; /&gt; &lt;IncludeProcessedImages Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;False&quot; /&gt; &lt;IncludeRestrictions Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;False&quot; /&gt; &lt;IncludeTerms Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;False&quot; /&gt; &lt;ImageElementsList Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;ImageUID,CorbisID,Title,URL128,CreditLine,AspectRatio,IsRoyaltyFree&quot; /&gt; &lt;ContentWarningElementsList Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;ProcessedImageElementsList Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;RestrictionElementsList Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;TermElementsList Scope=&quot;Public&quot; Type=&quot;&quot; Value=&quot;&quot; /&gt; &lt;/ImageFormatData&gt;</c1:imageFormatDataXML>
      </c1:Search>
   </soapenv:Body>
</soapenv:Envelope>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of sweetfa2
sweetfa2
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial