简体   繁体   English

“java.lang.UnsupportedOperationException:尚不支持。”

[英]“java.lang.UnsupportedOperationException: Not supported yet.”

What I am trying to do :我正在尝试做的事情:

I am trying to connect to Web Portal [that uses https]using Java.我正在尝试使用 Java 连接到 [使用 https] 的 Web 门户。 I have written code for supplying user credentials using Authenticator class.When I run the program I get an Exception:我已经编写了使用 Authenticator 类提供用户凭据的代码。当我运行程序时,出现异常:

"java.lang.UnsupportedOperationException: Not supported yet" “java.lang.UnsupportedOperationException:尚不支持”

I have the code posted :我已经发布了代码:

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());
        }
    }
}

the exception "java.lang.UnsupportedOperationException: Not supported yet"is raised in the 2nd Try.Is my approach correct ?在第二次尝试中引发异常“java.lang.UnsupportedOperationException:尚不支持”。我的方法正确吗? if not is there any alternative to do so ?如果没有,还有其他选择吗?

When I open the page in web browser I get the login page;Once I supply my credentials the web portal is displayed当我在网络浏览器中打开页面时,我会看到登录页面;一旦我提供了我的凭据,就会显示网络门户

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.因此,在我看来,您的身份验证问题的解决方案非常简单:实现此方法。

if you don't want implement this method :如果你不想实现这个方法:

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

take it easy , only delete this line of method :放轻松,只删除这行方法:

throw new UnsupportedOperationException("Not supported yet.");

You've probably used an IDE such as Netbeans to implement an interface / override an abstract class that needs certain methods implementing.您可能使用过诸如 Netbeans 之类的 IDE 来实现接口/覆盖需要实现某些方法的抽象类。 When IDEs do this (Netbeans definitely does) they generate method stubs for you like this so the code still compiles but if you try and call a method you haven't actually implemented you get an unavoidable error.当 IDE 执行此操作时(Netbeans 肯定会这样做),它们会像这样为您生成方法存根,因此代码仍然可以编译,但是如果您尝试调用尚未实际实现的方法,则会出现不可避免的错误。

Usually this means you have to implement the given method, but sometimes an implementation does genuinely call for a blank method stub, in which case just delete the line that's throwing the exception.通常这意味着您必须实现给定的方法,但有时实现确实需要一个空白的方法存根,在这种情况下,只需删除引发异常的行。

This happens when you did not provide implementations for all methods from the interface you've implemented.当您没有为已实现的接口中的所有方法提供实现时,就会发生这种情况。 Check which method you not implemented.检查您未实施的方法。

You don't give a body to your method.你没有给你的方法一个主体。 Check the line where you have the problem and override your method with the code you want.检查出现问题的行并使用所需的代码覆盖您的方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “ java.lang.UnsupportedOperationException:尚不支持。” - “java.lang.UnsupportedOperationException: Not supported yet.” Java Dropbox HttpServletRequest(java.lang.UnsupportedOperationException:尚不支持。) - Java Dropbox HttpServletRequest ( java.lang.UnsupportedOperationException: Not supported yet.) java.lang.UnsupportedOperationException:尚不支持 - java.lang.UnsupportedOperationException: Not supported yet 由于“线程“AWT-EventQueue-0”中的异常java.lang.UnsupportedOperationException:尚不支持,我的程序无法读取密钥。 - my program cant read the keys because of "Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet." Duke Fast Deduplication:java.lang.UnsupportedOperationException:尚不支持操作? - Duke Fast Deduplication: java.lang.UnsupportedOperationException: Operation not yet supported? UnsupportedOperationException:不支持。 在jframe中 - UnsupportedOperationException: Not supported yet. in jframe 由java.lang.UnsupportedOperationException引起:AdapterView不支持addView(View,layoutParams) - Caused by java.lang.UnsupportedOperationException: addView(View,layoutParams) is not supported in the AdapterView DBFit java.lang.UnsupportedOperationException: 不支持类型 İNT - DBFit java.lang.UnsupportedOperationException: Type İNT is not supported java.lang.UnsupportedOperationException:option不是受支持的字段类型 - java.lang.UnsupportedOperationException: option is not a supported field type Tomcat连接池-java.lang.UnsupportedOperationException:BasicDataSource不支持 - Tomcat Connection Pooling - java.lang.UnsupportedOperationException: Not supported by BasicDataSource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM