Package org.restlet.ext.ssl

Examples of org.restlet.ext.ssl.SslContextFactory


    /** Starts the Restlet. */
    @Override
    public void start() throws Exception {
        // Initialize the SSL context
        SslContextFactory sslContextFactory = SslUtils
                .getSslContextFactory(this);
        SSLContext sslContext = sslContextFactory.createSslContext();
        String addr = getHelped().getAddress();

        if (addr != null) {
            // This call may throw UnknownHostException and otherwise always
            // returns an instance of INetAddress.
View Full Code Here


     *            The helper to use.
     *
     * @return The SSL context factory.
     */
    public static SslContextFactory getSslContextFactory(RestletHelper<?> helper) {
        SslContextFactory result = (SslContextFactory) ((helper.getContext() == null) ? null
                : helper.getContext().getAttributes().get("sslContextFactory"));

        if (result == null) {
            String[] sslContextFactoryNames = helper.getHelpedParameters()
                    .getValuesArray("sslContextFactory");

            if (sslContextFactoryNames != null) {
                for (String sslContextFactoryName : sslContextFactoryNames) {
                    if ((result == null) && (sslContextFactoryName != null)) {
                        try {
                            Class<? extends SslContextFactory> sslContextFactoryClass = Class
                                    .forName(sslContextFactoryName).asSubclass(
                                            SslContextFactory.class);
                            result = sslContextFactoryClass.newInstance();
                            result.init(helper.getHelpedParameters());
                        } catch (ClassNotFoundException e) {
                            Context.getCurrentLogger().log(
                                    Level.WARNING,
                                    "Unable to find SslContextFactory class: "
                                            + sslContextFactoryName, e);
                        } catch (ClassCastException e) {
                            Context.getCurrentLogger()
                                    .log(Level.WARNING,
                                            "Class "
                                                    + sslContextFactoryName
                                                    + " does not implement SslContextFactory.",
                                            e);
                        } catch (InstantiationException e) {
                            Context.getCurrentLogger().log(
                                    Level.WARNING,
                                    "Could not instantiate class "
                                            + sslContextFactoryName
                                            + " with default constructor.", e);
                        } catch (IllegalAccessException e) {
                            Context.getCurrentLogger().log(
                                    Level.WARNING,
                                    "Illegal access when instantiating class "
                                            + sslContextFactoryName + ".", e);
                        }
                    }
                }
            }
        }

        if (result == null) {
            result = new DefaultSslContextFactory();
            result.init(helper.getHelpedParameters());
        }

        return result;
    }
View Full Code Here

        new Thread() {
            @Override
            public void run() {
                try {
                    // Creates the server socket
                    SslContextFactory contextFactory = SslUtils
                            .getSslContextFactory(SdcClientHelper.this);
                    SSLServerSocketFactory ssf = contextFactory
                            .createSslContext().getServerSocketFactory();
                    SSLServerSocket serverSocket = (SSLServerSocket) ssf
                            .createServerSocket(getServerPort());

                    // Accept the next socket
View Full Code Here

    protected void configure(SchemeRegistry schemeRegistry) {
        schemeRegistry.register(new Scheme("http", PlainSocketFactory
                .getSocketFactory(), 80));

        SSLSocketFactory sslSocketFactory = null;
        SslContextFactory sslContextFactory = SslUtils
                .getSslContextFactory(this);

        if (sslContextFactory != null) {
            try {
                SSLContext sslContext = sslContextFactory.createSslContext();
                sslSocketFactory = new SSLSocketFactory(sslContext);
            } catch (Exception e) {
                throw new RuntimeException("Unable to create SSLContext.", e);
            }
        } else {
View Full Code Here

TOP

Related Classes of org.restlet.ext.ssl.SslContextFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.