Example usage for javax.net.ssl SSLPeerUnverifiedException getClass

List of usage examples for javax.net.ssl SSLPeerUnverifiedException getClass

Introduction

In this page you can find the example usage for javax.net.ssl SSLPeerUnverifiedException getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:net.sourceforge.subsonic.backend.controller.RedirectionManagementController.java

public void test(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String redirectFrom = StringUtils
            .lowerCase(ServletRequestUtils.getRequiredStringParameter(request, "redirectFrom"));
    PrintWriter writer = response.getWriter();

    Redirection redirection = redirectionDao.getRedirection(redirectFrom);
    String webAddress = redirectFrom + ".subsonic.org";
    if (redirection == null) {
        writer.print("Web address " + webAddress + " not registered.");
        return;//from  w ww.j a  v  a2 s  .c  o  m
    }

    if (redirection.getTrialExpires() != null && redirection.getTrialExpires().before(new Date())) {
        writer.print("Trial period expired. Please upgrade to Subsonic Premium to activate web address.");
        return;
    }

    String url = redirection.getRedirectTo();
    if (!url.endsWith("/")) {
        url += "/";
    }
    url += "index.html";

    HttpClient client = new DefaultHttpClient();
    HttpConnectionParams.setConnectionTimeout(client.getParams(), 15000);
    HttpConnectionParams.setSoTimeout(client.getParams(), 15000);
    HttpGet method = new HttpGet(url);

    try {
        HttpResponse resp = client.execute(method);
        StatusLine status = resp.getStatusLine();

        if (status.getStatusCode() == HttpStatus.SC_OK) {
            String msg = webAddress + " responded successfully.";
            writer.print(msg);
            LOG.info(msg);
        } else {
            String msg = webAddress + " returned HTTP error code " + status.getStatusCode() + " "
                    + status.getReasonPhrase();
            writer.print(msg);
            LOG.info(msg);
        }
    } catch (SSLPeerUnverifiedException x) {
        String msg = webAddress + " responded successfully, but could not authenticate it.";
        writer.print(msg);
        LOG.info(msg);

    } catch (Throwable x) {
        String msg = webAddress + " is registered, but could not connect to it. ("
                + x.getClass().getSimpleName() + ")";
        writer.print(msg);
        LOG.info(msg);
    } finally {
        client.getConnectionManager().shutdown();
    }
}