“ java.lang.UnsupportedOperationException:尚不支持。”
您看過這段代碼片段了嗎?
@Override public Result authenticate(HttpExchange he) {throw new UnsupportedOperationException('Not supported yet.'); }
正是這種情況會在您每次嘗試進行身份驗證時引發上述異常。
因此,在我看來,解決身份驗證問題的方法非常簡單:實施此方法。
解決方法我正在嘗試做的是:
我正在嘗試使用Java連接到[使用https]的Web Portal。我已經編寫了使用Authenticator類提供用戶憑據的代碼。運行程序時出現異常:
“ java.lang.UnsupportedOperationException:尚不支持”
我有張貼的代碼:
public class Main { public class MyAuthenticator extends Authenticator {protected PasswordAuthentication getpasswordAuthentication() { String username = 'username'; String password = 'password'; // Return the information return new PasswordAuthentication(username,password.toCharArray());}@Overridepublic Result authenticate(HttpExchange he) { throw new UnsupportedOperationException('Not supported yet.');} } public static void main(String[] args) {// TODO code application logic hereTrustManager[] trustClients = new TrustManager[]{ new X509TrustManager() {public void checkClientTrusted(X509Certificate[] xcs,String string) throws CertificateException { throw new UnsupportedOperationException('Not supported yet.');}public void checkServerTrusted(X509Certificate[] xcs,String string) throws CertificateException { throw new UnsupportedOperationException('Not supported yet.');}public X509Certificate[] getAcceptedIssuers() { return null; //throw new UnsupportedOperationException('Not supported yet.');} }};try { SSLContext sslcontext = SSLContext.getInstance('SSL'); sslcontext.init(null,trustClients,new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sslcontext.getSocketFactory());} catch (Exception e) { System.out.println('in 1st catch ' + e);}try { URL url = new URL('https://someURL.server.com/fmk/jsp/ltpaLogin.jsp'); URLConnection urlconnection = url.openConnection(); System.out.println(urlconnection); System.out.print(urlconnection.getInputStream().toString());} catch (Exception e) { System.out.println('in 2ndcatch ' + e.getMessage());} }}
第二次Try中引發了異常“java.lang.UnsupportedOperationException:不支持”。我的方法正確嗎?如果沒有,還有其他選擇嗎?
當我在Web瀏覽器中打開頁面時,我得到登錄頁面;一旦提供了憑據,就會顯示Web門戶
有人可以建議如何訪問Webportal并提供我的憑據并檢查身份驗證是否成功嗎?任何示例代碼片段都將對您有所幫助。
相關文章:
