"java.lang.UnsupportedOperationException:尚不支持."

编程入门 行业动态 更新时间:2024-10-25 14:27:20
本文介绍了"java.lang.UnsupportedOperationException:尚不支持."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试做的事情:

我正在尝试使用Java连接到[使用https]的Web Portal.我已经编写了使用Authenticator类提供用户凭据的代码.运行该程序时,出现异常:

I am trying to connect to Web Portal [that uses https]using Java. I have written code for supplying user credentials using Authenticator class.When I run the program I get an Exception:

"java.lang.UnsupportedOperationException:尚不支持"

"java.lang.UnsupportedOperationException: Not supported yet"

我已经发布了代码:

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("someURL.server/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:目前尚不支持".我的方法正确吗?如果没有,还有其他选择吗?

the exception "java.lang.UnsupportedOperationException: Not supported yet"is raised in the 2nd Try.Is my approach correct ? if not is there any alternative to do so ?

在Web浏览器中打开页面时,会显示登录页面;一旦提供凭据,就会显示Web门户

When I open the page in web browser I get the login page;Once I supply my credentials the web portal is displayed

任何人都可以建议如何访问Webportal并提供我的凭据并检查身份验证是否成功吗?任何示例代码片段都将非常有帮助预先感谢..

Can any one please suggest how to hit the webportal and supply my credentials and check the authentication is success or not ? Any sample code snippets will be really helpful Thanks in advance..

推荐答案

您看过这段代码片段了吗?

Have you seen this code fragment ?

@Override public Result authenticate(HttpExchange he) { throw new UnsupportedOperationException("Not supported yet."); }

恰恰是每次您尝试进行身份验证时都会引发上述异常的人.

It's precisely the one that will throw the aforementionned exception each time you try to authenticate.

因此,在我看来,解决身份验证问题的方法非常简单:实施此方法.

So, to my mind, the solution to your authentication problem is quite simple : implement this method.

更多推荐

"java.lang.UnsupportedOperationException:尚不支持."

本文发布于:2023-11-15 04:38:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1591216.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:尚不   java   quot   UnsupportedOperationException   lang

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!