Groovy - 方法的模糊方法重载

时间:2015-06-04 08:52:56

标签: parsing groovy wsdl

我已经检查了论坛,找到了一些关于这个问题的提示,但没有一个与我的完全匹配。

我在调用WSDLParse.parse方法之后就得到了这个异常。 顺便说一下,我正在尝试将我的Groovy 2.2.1更新到2.4.3,我是否会错过什么?

感谢您的建议

Ps:这是异常消息,下面你可以找到所有的堆栈跟踪。

groovy.lang.GroovyRuntimeException:方法com.predic8.schema.Element #setType的模糊方法重载。     由于以下原因重叠原因,无法解析为[null]调用哪个方法:             [class javax.xml.namespace.QName]             [class groovy.xml.QName]

  groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method com.predic8.schema.Element#setType.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
        [class javax.xml.namespace.QName]
        [class groovy.xml.QName]
        at groovy.lang.MetaClassImpl.chooseMostSpecificParams(MetaClassImpl.java:3238)
        at groovy.lang.MetaClassImpl.chooseMethodInternal(MetaClassImpl.java:3191)
        at groovy.lang.MetaClassImpl.chooseMethod(MetaClassImpl.java:3134)
        at groovy.lang.MetaClassImpl.getNormalMethodWithCaching(MetaClassImpl.java:1369)
        at groovy.lang.MetaClassImpl.getMethodWithCaching(MetaClassImpl.java:1284)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1054)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016)
        at org.codehaus.groovy.runtime.metaclass.MultipleSetterProperty.setProperty(MultipleSetterProperty.java:52)
        at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2663)
        at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3746)
        at com.predic8.soamodel.XMLElement.setProperty(XMLElement.groovy)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setGroovyObjectProperty(ScriptBytecodeAdapter.java:530)
        at com.predic8.schema.Element.parseAttributes(Element.groovy:46)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.ja
va:207)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:56)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:171)
        at com.predic8.soamodel.XMLElement.parse(XMLElement.groovy:40)
        at com.predic8.soamodel.XMLElement$parse$0.call(Unknown Source)
        at com.predic8.schema.Schema.parseChildren(Schema.groovy:109)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.ja
va:207)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:56)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:179)
        at com.predic8.soamodel.XMLElement.parse(XMLElement.groovy:45)
        at com.predic8.soamodel.XMLElement$parse$0.call(Unknown Source)
        at com.predic8.wsdl.Types.parseChildren(Types.groovy:41)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.ja
va:207)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:56)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:179)
        at com.predic8.soamodel.XMLElement.parse(XMLElement.groovy:45)
        at com.predic8.soamodel.XMLElement$parse$0.call(Unknown Source)
        at com.predic8.wsdl.Definitions.parseChildren(Definitions.groovy:220)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.ja
va:207)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:56)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:179)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:177)
        at com.predic8.soamodel.XMLElement.parse(XMLElement.groovy:45)
        at com.predic8.soamodel.XMLElement$parse$0.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130)
        at com.predic8.wsdl.WSDLParser.parseLocal(WSDLParser.groovy:44)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.ja
va:207)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:56)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:171)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:169)
        at com.predic8.soamodel.AbstractParser.parse(AbstractParser.groovy:34)
        at com.predic8.wsdl.WSDLParser.super$2$parse(WSDLParser.groovy)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1207)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:130)
        at com.predic8.wsdl.WSDLParser.parse(WSDLParser.groovy:24)
        at com.predic8.wsdl.WSDLParser$parse.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:122)
        at ESBWsdlRequest.<init>(ESBWsdlRequest.groovy:23)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
        at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java
:102)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:232)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:268)
        at YOKSIS_OGRENCI_SIL_in.run(YOKSIS_OGRENCI_SIL_in.groovy:2)
        at groovy.util.GroovyScriptEngine.run(GroovyScriptEngine.java:589)
        at com.fibabanka.esi.xslt.ESBGroovyEngine.execute(ESBGroovyEngine.java:21)
        at com.fibabanka.esi.xslt.Transformer.transformGroovy(Transformer.java:102)
        at com.fibabanka.esi.xslt.Transformer.transformIn(Transformer.java:63)
        at com.fibabanka.esi.xslt.XsltProcessor.processBag(XsltProcessor.java:92)
        at com.fibabanka.esi.common.GenericProcessor.processTypeBag(GenericProcessor.java:27)
        at com.fibabanka.esi.common.GenericProcessor.process(GenericProcessor.java:37)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.camel.component.bean.MethodInfo.invoke(MethodInfo.java:340)
        at org.apache.camel.component.bean.MethodInfo$1.proceed(MethodInfo.java:237)
        at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:168)
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
        at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:71)
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
        at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
        at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
        at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:322)
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:213)
        at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45)
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
        at org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:303)
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:117)
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
        at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45)
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
        at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)
        at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
        at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:71)
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
        at org.apache.camel.component.seda.SedaConsumer.sendToConsumers(SedaConsumer.java:248)
        at org.apache.camel.component.seda.SedaConsumer.doRun(SedaConsumer.java:160)
        at org.apache.camel.component.seda.SedaConsumer.run(SedaConsumer.java:131)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)

我没有设置元素也没有设置权利。我也没有在我的脚本中使用任何QName类。 这是我的groovy脚本文件 - &gt;

import groovy.time.BaseDuration.From;
import groovy.util.XmlParser;
import groovy.util.XmlSlurper;
import groovy.xml.MarkupBuilder;
import groovy.xml.XmlUtil;

import java.io.StringWriter;

import com.predic8.wsdl.Definitions;
import com.predic8.wsdl.WSDLParser;
import com.predic8.wstool.creator.RequestTemplateCreator;
import com.predic8.wstool.creator.SOARequestCreator;

class ESBWsdlParser {
    String formTemplate;
    String requestSoapXml;
    public ESBWsdlRequest(String wsdlFile,String operationName) {
        File file = new File(wsdlFile);
        println file.getAbsolutePath();

        WSDLParser parser = new WSDLParser();
        Definitions wsdl = parser.parse(wsdlFile);
        StringWriter writer = new StringWriter();
        SOARequestCreator creator = new SOARequestCreator(wsdl, new RequestTemplateCreator(), new MarkupBuilder(writer));
        //creator.createRequest(PortType name, Operation name, Binding name);
        creator.createRequest(null, operationName, null);
        formTemplate = writer.toString();

    }
    public String resolveName(c){
        String[] arParts = c.name().toString().split("}");
        if(arParts.length > 1){
            return  arParts[1];
        }
        return c.name;
    }

3 个答案:

答案 0 :(得分:2)

问题是有两个对象兼容和单参数的setType方法,你可以用null来调用它。或者更准确地说,您不需要调用该方法,您可以设置属性,从而调用方法。

现在在Groovy 2.4之前,我们不支持重载案例。调用哪种方法实际上是随机的。换句话说,如果它总是为您的案例调用正确的方法,那么您很幸运。从Groovy 2.4开始,Groovy支持重载setter,但这可能会导致setter重载引起异常,例如上面的异常。我认为好的东西,因为它显示了过去可能导致神秘错误的东西。

修复不是很好...... setType((QName) qname))而不是属性赋值....当然还有你选择的QName类。您可以使用Keegan的建议来支持您

编辑:将setElement更改为setType

答案 1 :(得分:1)

您应该ask SOA Membrane来编辑Element

type = getTypeQName(token.getAttributeValue( null , 'type'))

类似

type = (QName) getTypeQName(token.getAttributeValue( null , 'type'))

解决歧义。与此同时,您可以手动覆盖自己,如此

@Grab(group='ch.qos.logback', module='logback-classic', version='1.1.3')
@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.5')

// for some reason, this isn't able to resolve in my GroovyConsole -- I had to download into my .groovy/lib
//@GrabResolver(name='membrane', root='http://repository.membrane-soa.org/content/repositories/releases')
//@Grab(group='com.predic8', module='soa-model-core', version='1.5.3')

// for some reason, I'm getting "java.lang.NoClassDefFoundError: Unable to load class com.predic8.schema.SchemaComponent due to missing dependency Lorg/slf4j/Logger;" in my GroovyConsole when I don't have this
@GrabConfig(systemClassLoader=true, initContextClassLoader=true)

import com.predic8.wsdl.Definitions
import com.predic8.wsdl.Operation
import com.predic8.wsdl.PortType
import com.predic8.wsdl.WSDLParser

import com.predic8.schema.Declaration
import javax.xml.namespace.QName as JQName
import groovy.xml.QName

// the fix
MetaMethod originalSetType = Declaration.metaClass.getMetaMethod("setType", [Object])
Declaration.metaClass.setType = { Object obj ->
   if (obj)
       originalSetType.invoke((QName) obj)
}

// an example usage, demonstrating fix works
Definitions defs = new WSDLParser().parse("http://www.w3schools.com/webservices/tempconvert.asmx?WSDL")
for (PortType pt : defs.portTypes) {
    println pt.name
    for (Operation op : pt.operations)
      println "  -${op.name}"
}

由于您正在使用类(我假设在已编译的项目中),您可能会将修复程序放在静态块中。

答案 2 :(得分:0)

升级到1.6.0。例如。对于Gradle构建脚本:

compile "com.predic8:soa-model-core:1.6.0"