當我嘗試運行此腳本,以確保Grails的/ CXF客戶端上我的Web服務,我得到的Grails + CXF + secureServiceFactory
上secureServiceFactory
「不能調用方法getInInterceptors()空對象」 是否secureServiceFactory需要在其他地方設置?
任何想法:
代碼:
class BootStrap {
def secureServiceFactory
def init = { servletContext ->
Map<String, Object> inProps = [:]
inProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
inProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
Map<QName, Validator> validatorMap = new HashMap<QName, Validator>();
validatorMap.put(WSSecurityEngine.USERNAME_TOKEN, new UsernameTokenValidator() {
@Override
protected void verifyPlaintextPassword(org.apache.ws.security.message.token.UsernameToken usernameToken, org.apache.ws.security.handler.RequestData data)
throws org.apache.ws.security.WSSecurityException {
if(data.username == "wsuser" && usernameToken.password == "secret") {
println "username and password are correct!"
} else {
println "username and password are NOT correct..."
throw new WSSecurityException("user and/or password mismatch")
}
}
});
inProps.put(WSS4JInInterceptor.VALIDATOR_MAP, validatorMap);
secureServiceFactory.getInInterceptors().add(new WSS4JInInterceptor(inProps))
}
您可能希望包含您的resources.groovy或說明您認爲插件是否讓您注入secureServiceFactory。 – billjamesdev
我只是跟着這個例子: http://www.christianoestreich.com/2012/04/grails-cxf-interceptor-injection/ 所以我的resources.groovy仍然是空的。 – user2672286
再次閱讀文章。 cxf插件將服務工廠連接起來,這些服務工廠將**名爲'secureService'的暴露服務的名稱與名爲'secureServiceFactory'的bean匹配**。你有一個名爲'secureService'的服務嗎? – dmahapatro