我在做什麼:「java.lang.UnsupportedOperationException:尚不支持。」
我想連接到Web門戶[使用https]使用Java。 供應使用驗證器class.When我運行該程序的用戶憑據我寫的代碼,我得到一個異常:「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());
}
@Override
public Result authenticate(HttpExchange he) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
public static void main(String[] args) {
// TODO code application logic here
TrustManager[] 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());
}
}
}
異常「java.lang.UnsupportedOperationException:不支持」在第二次嘗試中引發。我的方法是否正確?如果沒有,有沒有其他辦法可以這樣做?
當我打開網絡瀏覽器,我得到了登錄頁面的頁面;一旦我提供我的憑據的門戶網站顯示
任何一個可以請建議如何打webportal並提供我的憑據,並檢查認證成功與否? 任何示例代碼片段將真正有幫助 在此先感謝..
OOppss !!這是由Netbeans產生的!我注意到這一點!我會實現這一點,並嘗試非常感謝。 – ManiVI 2011-02-03 16:25:40