wshttpbinding java_WCF自定义用户账号密码之WCF系结模式wsHttpBinding的Java调用
再回到編輯Web服務屬性設定畫面﹐剛剛所點擊的[使用開發默認值]的復選框如果已經有被勾選了﹐請將勾選取消。然后先離開編輯Web服務屬性設定畫面。
1.7. 加入CallbackHandler 檔案
這里需要加入一個繼承CallbackHandler的檔案
TrustStoreCallbackHandler.java
public class TrustStoreCallbackHandler implements CallbackHandler {
KeyStore keyStore = null;
String password = "123456"; // keystore的密碼
public TrustStoreCallbackHandler() {
System.out.println("Truststore CBH.CTOR Called..........");
InputStream is = null;
try {
keyStore = KeyStore.getInstance("JKS");
String keystoreURL = "C:\\Java\\Certificate\\myTrustStore"; //放置憑證檔的keystore
is = new FileInputStream(keystoreURL);
keyStore.load(is, password.toCharArray());
} catch (IOException ex) {
Logger.getLogger(TrustStoreCallbackHandler.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(TrustStoreCallbackHandler.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
} catch (CertificateException ex) {
Logger.getLogger(TrustStoreCallbackHandler.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
} catch (KeyStoreException ex) {
Logger.getLogger(TrustStoreCallbackHandler.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
} finally {
try {
is.close();
} catch (IOException ex) {
Logger.getLogger(TrustStoreCallbackHandler.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
System.out.println("Truststore CBH.handle() Called..........");
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof KeyStoreCallback) {
KeyStoreCallback cb = (KeyStoreCallback) callbacks[i];
print(cb.getRuntimeProperties());
cb.setKeystore(keyStore);
} else {
throw new UnsupportedCallbackException(callbacks[i]);
}
}
}
private void print(Map context) {
Iterator it = context.keySet().iterator();
while (it.hasNext()) {
System.out.println("Prop " + it.next());
}
}
}
1.8. 重回編輯 Web 服務屬性
重新開啟 編輯Web服務屬性
總結
以上是生活随笔為你收集整理的wshttpbinding java_WCF自定义用户账号密码之WCF系结模式wsHttpBinding的Java调用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DOS命令、Java语言开发环境(JVM
- 下一篇: ping端口_干货分享:shell脚本批