Web Services WSDL Web服务基本验证解析器

eivgtgni  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(217)

我正在使用soa-model-core从wsdl wenservice url获取定义。如果没有身份验证,WSDLParser工作正常。但是如果url包含基本身份验证,则会引发401错误。
我尝试与BasicAuthenticationResolver也不工作以下错误我得到错误。我需要定义从Web服务是他们的任何改变原生方式。通过使用Httpclient我得到响应字符串。从字符串任何方式转换为绑定的定义。

import java.io.IOException;
import com.predic8.wsdl.Definitions;
import com.predic8.wsdl.WSDLParser;
import com.predic8.xml.util.BasicAuthenticationResolver;

public class Test {

    public static void main(String[] args) throws ClientProtocolException, IOException {
        String str="http://localhost:7005/OrderManagement/wsapi?WSDL";
        WSDLParser ws=new WSDLParser();
        BasicAuthenticationResolver bs=new BasicAuthenticationResolver();
        bs.setBaseDir("http");
        bs.setUsername("osm");
        bs.setPassword("osmadmin1");
        ws.setResourceResolver(bs);
        Definitions df=ws.parse(str);
        System.out.println(df.toString());

    }
}

错误:

Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: com.predic8.xml.util.BasicAuthenticationResolver.resolve() 
is applicable for argument types: (java.lang.String, java.lang.String) values: [http://192.168.1.105:7005/OrderManagement/wsapi?WSDL, ]
Possible solutions: resolve(java.lang.Object)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:54)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
    at com.predic8.soamodel.AbstractParser.getResourceToken(AbstractParser.groovy:47)
    at com.predic8.soamodel.AbstractParser.this$2$getResourceToken(AbstractParser.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
    at com.predic8.soamodel.AbstractParser.parse(AbstractParser.groovy:35)
    at com.predic8.wsdl.WSDLParser.super$2$parse(WSDLParser.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1215)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:132)
    at com.predic8.wsdl.WSDLParser.parse(WSDLParser.groovy:24)
    at test.Test.main(Test.java:21)
fxnxkyjh

fxnxkyjh1#

the predict8 don't support basic authentication
我解决办法是:用于获取受保护的WSDL服务,并将其保存到 *.wsdl文件中。我使用了HttpURLConnection和基本身份验证https://www.baeldung.com/java-http-url-connection,现在我有了一个WSDL文件,可以轻松地将其与predict8库一起使用

相关问题