简体   繁体   中英

After creating web service client with wsdl2java and using it I get Unexpected Attachment type =class

I have a web service that I have deployed on localhost on Tomcat 7.0.54, with following wsdl file:

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="SRW" targetNamespace="http://www.loc.gov/zing/srw/srwabosi/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:srw-bindings="http://www.loc.gov/zing/srw/srw-bindings/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/">
  <import namespace="http://www.loc.gov/zing/srw/srw-bindings/" location="srw-bindings.wsdl">
    </import>
  <service name="SRWABOSI">
    <port name="SRW" binding="srw-bindings:SRW-SoapBinding">
      <soap:address location="http://localhost:8080/abosi/services/SRW"/>
    </port>
  </service>
</definitions>

and srw-bindings.wsdl

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- edited with XMLSpy v2006 sp1 U (http://www.altova.com) by virtual (EMBRACE) --><!-- ZiNG SRU/SRW WSDL Specification                   --><!-- Version 1.1                                       --><!-- 6 October 2004                                    --><definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:srw-interfaces="http://www.loc.gov/zing/srw/interfaces/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SRW" targetNamespace="http://www.loc.gov/zing/srw/srw-bindings/">
    <import location="srw-ports.wsdl" namespace="http://www.loc.gov/zing/srw/interfaces/"/>
    <binding name="SRW-SoapBinding" type="srw-interfaces:SRWPort">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <!-- .... --> 
        <operation name="DownloadOperation">
            <soap:operation style="rpc"/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                  <mime:multipartRelated>
                    <mime:part name="body">
                        <soap:body parts="fileName" use="literal"/>
                    </mime:part>
                    <mime:part name="attach">
                        <mime:content part="file" type="application/octet-stream"/>
                    </mime:part>
                    <mime:part name="sessionKey">
                        <mime:content part="sessionKey" type="application/octet-stream"/>
                    </mime:part>
                </mime:multipartRelated>    
            </output>
        </operation>
    </binding>
    <binding name="Explain-HTTPGetBinding" type="srw-interfaces:ExplainPort">
        <http:binding verb="GET"/>
        <operation name="ExplainOperation">
            <http:operation location="?operation=explain"/>
            <input>
                <http:urlEncoded/>
            </input>
            <output>
                <mime:mimeXml part="body"/>
            </output>
        </operation>
    </binding>
    <binding name="Explain-HTTPGetRootBinding" type="srw-interfaces:ExplainPort">
        <http:binding verb="GET"/>
        <operation name="ExplainOperation">
            <http:operation location="?operation=explain"/>
            <input>
                <http:urlEncoded/>
            </input>
            <output>
                <mime:mimeXml part="body"/>
            </output>
        </operation>
    </binding>
    <binding name="Explain-SoapBinding" type="srw-interfaces:ExplainPort">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="ExplainOperation">
            <soap:operation style="document"/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
    </binding>
</definitions>

After having my app deployed on tomcat I use wsdl2java to generate the client with following command:

wsdl2java -d wsdl2java_test1 -V -client -impl http://localhost:8080/abosi/services/SRW\?wsdl

Then my interface code looks like this (important part is the downloadOperation )

@WebService(targetNamespace = "http://www.loc.gov/zing/srw/interfaces/", name = "SRWPort")
@XmlSeeAlso({gov.loc.zing.srw.ObjectFactory.class, gov.loc.zing.cql.xcql.ObjectFactory.class, gov.loc.zing.srw.diagnostic.ObjectFactory.class, org.w3._2001._04.xmlenc.ObjectFactory.class, org.w3._2000._09.xmldsig.ObjectFactory.class})
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface SRWPort {

    @WebResult(name = "body", targetNamespace = "http://www.loc.gov/zing/srw/interfaces/", partName = "body")
    // ... 

    @WebMethod(operationName = "DownloadOperation")
    public void downloadOperation(
        @WebParam(partName = "recordId", name = "recordId")
        java.lang.String recordId,
        @WebParam(partName = "library", name = "library")
        java.lang.String library,
        @WebParam(partName = "publicKey", name = "publicKey")
        org.w3._2000._09.xmldsig.KeyInfoType publicKey,
        @WebParam(partName = "fileName", mode = WebParam.Mode.OUT, name = "fileName")
        javax.xml.ws.Holder<java.lang.String> fileName,
        @WebParam(partName = "file", mode = WebParam.Mode.OUT, name = "file")
        javax.xml.ws.Holder<org.w3._2001._04.xmlenc.EncryptedDataType> file,
        @WebParam(partName = "sessionKey", mode = WebParam.Mode.OUT, name = "sessionKey")
        javax.xml.ws.Holder<org.w3._2001._04.xmlenc.EncryptedKeyType> sessionKey
    );
}

I try to launch the client with the following code :

package gov.loc.zing.srw.interfaces;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import gov.loc.zing.srw.srwabosi.SRWABOSI;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.bind.annotation.XmlSeeAlso;

public final class SRWPort_SRW_Client {

    private static final QName SERVICE_NAME = new QName("http://www.loc.gov/zing/srw/srwabosi/", "SRWABOSI");

    private SRWPort_SRW_Client() {}

    public static void main(String args[]) throws java.lang.Exception {
        URL wsdlURL = SRWABOSI.WSDL_LOCATION;
        if (args.length > 0 && args[0] != null && !"".equals(args[0])) { 
            File wsdlFile = new File(args[0]);
            try {
                if (wsdlFile.exists()) {
                    wsdlURL = wsdlFile.toURI().toURL();
                } else {
                    wsdlURL = new URL(args[0]);
                }
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        }

        SRWABOSI ss = new SRWABOSI(wsdlURL, SERVICE_NAME);

        SRWPort port = ss.getSRW();  

        {
        System.out.println("Invoking downloadOperation...");
        java.lang.String _downloadOperation_recordId = "";
        java.lang.String _downloadOperation_library = "";
        org.w3._2000._09.xmldsig.KeyInfoType _downloadOperation_publicKey = null;
        javax.xml.ws.Holder<java.lang.String> _downloadOperation_fileName = new javax.xml.ws.Holder<java.lang.String>();
        javax.xml.ws.Holder<org.w3._2001._04.xmlenc.EncryptedDataType> _downloadOperation_file = new javax.xml.ws.Holder<org.w3._2001._04.xmlenc.EncryptedDataType>();
        javax.xml.ws.Holder<org.w3._2001._04.xmlenc.EncryptedKeyType> _downloadOperation_sessionKey = new javax.xml.ws.Holder<org.w3._2001._04.xmlenc.EncryptedKeyType>();
        port.downloadOperation(_downloadOperation_recordId, _downloadOperation_library, _downloadOperation_publicKey, _downloadOperation_fileName, _downloadOperation_file, _downloadOperation_sessionKey);

        System.out.println("downloadOperation._downloadOperation_fileName=" + _downloadOperation_fileName.value);
        System.out.println("downloadOperation._downloadOperation_file=" + _downloadOperation_file.value);
        System.out.println("downloadOperation._downloadOperation_sessionKey=" + _downloadOperation_sessionKey.value);

        }

        System.exit(0);
    }

}

but I get this error :

Exception in thread "main" java.lang.UnsupportedOperationException: Unexpected Attachment type =class org.w3._2001._04.xmlenc.EncryptedDataType
    at com.sun.xml.internal.ws.client.sei.ResponseBuilder$AttachmentBuilder.createAttachmentBuilder(ResponseBuilder.java:237)
    at com.sun.xml.internal.ws.client.sei.SEIMethodHandler.buildResponseBuilder(SEIMethodHandler.java:173)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.<init>(SyncMethodHandler.java:74)
    at com.sun.xml.internal.ws.client.sei.SEIStub.initMethodHandlers(SEIStub.java:88)
    at com.sun.xml.internal.ws.client.sei.SEIStub.<init>(SEIStub.java:78)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.createEndpointIFBaseProxy(WSServiceDelegate.java:590)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:330)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:312)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:294)
    at javax.xml.ws.Service.getPort(Service.java:119)
    at gov.loc.zing.srw.srwabosi.SRWABOSI.getSRW(SRWABOSI.java:79)
    at gov.loc.zing.srw.interfaces.SRWPort_SRW_Client.main(SRWPort_SRW_Client.java:51)

The problem was (I presume because after that I was able to successfully call my web service) having not faceted project without

  • Dynamic Web Module facet (this should be added as first, otherwise I was getting errrors)
  • CXF 2.x Web Service facet

After applying this changes in eclipse I was able to successfully call my service's methods.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM