2 回答
TA贡献1856条经验 获得超11个赞
试试这个init()方法,你可能需要添加一个WebLogic凭证提供者:
private void init() {
AddressingFeature feature = new AddressingFeature(true, false);
MyService proxy = service.getMyService(feature);
List<Handler> handlerChain = new ArrayList<>();
// Add a handler to the handler chain
handlerChain.add(new PasswordDigestHeaderHandler());
BindingProvider bindingProvider = (BindingProvider) proxy;
Binding binding = bindingProvider.getBinding();
binding.setHandlerChain(handlerChain);
// weblogic.xml.crypto.wss.provider.CredentialProvider
// weblogic.wsee.security.unt.ClientUNTCredentialProvider
List<CredentialProvider> credProviders = new ArrayList<>();
credProviders.add(new ClientUNTCredentialProvider(USERNAME.getBytes(), PASSWORD.getBytes()));
Map<String, Object> context = bindingProvider.getRequestContext();
// weblogic.xml.crypto.wss.WSSecurityContext
context.put(WSSecurityContext.CREDENTIAL_PROVIDER_LIST, credProviders);
// weblogic.security.SSL.TrustManager
context.put(
WSSecurityContext.TRUST_MANAGER,
new TrustManager() {
public boolean certificateCallback(X509Certificate[] chain, int validateErr) {
return true;
}
}
);
threadLocalClient.set(proxy);
}
TA贡献1794条经验 获得超7个赞
试试这个。
下载描述您的服务的 WSDL 文件并通过注释掉定义wsp:PolicyReference:的行来修改它。
将它放在一个文件夹中,该文件夹将包含在您的 jar/war/ear 文件中(例如 META-INF/wsdl)。
在您的 Web 服务客户端中,更改您的 @WebServiceRef 注入以引用此本地/捆绑版本的 WSDL:
@WebServiceRef(wsdlLocation = "META-INF/wsdl/MyService.wsdl")
private MyServiceInterface service;
将您的客户端初始化代码修改为如下所示:
AddressingFeature feature = new AddressingFeature(true, false);
MyService proxy = service.getMyService(feature);
BindingProvider bindingProvider = (BindingProvider) proxy;
List<Handler> handlerChain = new ArrayList<Handler>();
//Add a handler to the handler chain
handlerChain.add( new PasswordDigestHeaderHandler() );
Binding binding = bindingProvider.getBinding();
binding.setHandlerChain(handlerChain);
// Add these two lines, to point to the remote service
Map<String, Object> context = bindingProvider.getRequestContext();
context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, REMOTE_SERVICE_ENDPOINT);
threadLocalClient.set(proxy);
... 其中 REMOTE_SERVICE_ENDPOINT 是您正在访问的远程 Web 服务的 URL。
那应该这样做。您不必修改 PasswordDigestHeaderHandler 实现。
我在完全相同的问题上花了相当多的时间,但这个线程让我走上了正确的道路:https ://community.oracle.com/thread/2485783 。
祝你好运。
添加回答
举报