ManiVI
ManiVI

Reputation: 592

"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. I have written code for supplying user credentials using Authenticator class.When I run the program I get an Exception:

"java.lang.UnsupportedOperationException: Not supported yet"

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 ? 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..

Upvotes: 6

Views: 106151

Answers (5)

bart-khalid
bart-khalid

Reputation: 348

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.

Upvotes: 0

KM_Saravanan
KM_Saravanan

Reputation: 33

This happens when you did not provide implementations for all methods from the interface you've implemented. Check which method you not implemented.

Upvotes: 0

Michael Berry
Michael Berry

Reputation: 72254

You've probably used an IDE such as Netbeans to implement an interface / override an abstract class that needs certain methods implementing. 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.

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.

Upvotes: 4

mehdi shahdoost
mehdi shahdoost

Reputation: 1489

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.");

Upvotes: 9

Riduidel
Riduidel

Reputation: 22292

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.

Upvotes: 11

Related Questions