Package com.alibaba.antx.config.resource.util

Examples of com.alibaba.antx.config.resource.util.ResourceKey


            throw new ConfigException(e);
        }
    }

    protected ChannelSftp getOrCreateChannel(ResourceURI uri) {
        final ResourceKey key = new ResourceKey(uri);
        ChannelSftp channel;

        synchronized (channels) {
            channel = (ChannelSftp) channels.get(key);

            if (channel == null) {
                try {
                    ResourceContext.get().setCurrentURI(uri.getURI());

                    com.jcraft.jsch.Session session = jsch.getSession(key.getUser(), key.getHost(), key.getPort());

                    session.setUserInfo(new UserInfo() {
                        private UsernamePassword up;

                        public String getPassphrase() {
                            return null;
                        }

                        public boolean promptPassphrase(String message) {
                            return true;
                        }

                        public String getPassword() {
                            return up == null ? null : up.getPassword();
                        }

                        public boolean promptPassword(String message) {
                            URI uri = ResourceContext.get().getCurrentURI();
                            String username = ResourceContext.get().getCurrentUsername();
                            Set visitedURIs = ResourceContext.get().getVisitedURIs();

                            message = "\nAuthentication required: \n" + uri + "\n";

                            up = getResourceManager().getAuthenticationHandler().authenticate(message, uri, username,
                                    visitedURIs.contains(key));

                            visitedURIs.add(key);

                            return up != null;
                        }

                        public boolean promptYesNo(String str) {
                            return true;
                        }

                        public void showMessage(String message) {
                        }
                    });

                    session.connect();

                    channel = (ChannelSftp) session.openChannel("sftp");
                    channel.connect();

                    String charset = uri.getOption("charset");

                    if (charset != null) {
                        channel.setFilenameEncoding(charset);
                    }

                    channels.put(key, channel);

                    // �ɹ���������Ա����ظ���ʾ��������
                    ResourceContext.get().getVisitedURIs().remove(new ResourceKey(new ResourceURI(uri.getURI())));
                } catch (RuntimeException e) {
                    throw e;
                } catch (Exception e) {
                    throw new ConfigException(e);
                } finally {
View Full Code Here


            if (httpget.getStatusCode() != 200) {
                throw new ResourceNotFoundException(HttpStatus.getStatusText(httpget.getStatusCode()));
            }

            // �ɹ���������Ա����ظ���ʾ��������
            ResourceContext.get().getVisitedURIs().remove(new ResourceKey(new ResourceURI(getURI().getURI())));

            content = httpget.getResponseBody();
            charset = httpget.getResponseCharSet();

            Header contentTypeHeader = httpget.getResponseHeader("Content-Type");
View Full Code Here

            public Credentials getCredentials(AuthScheme scheme, String host, int port, boolean proxy)
                    throws CredentialsNotAvailableException {
                URI uri = ResourceContext.get().getCurrentURI();
                String username = ResourceContext.get().getCurrentUsername();
                Set visitedURIs = ResourceContext.get().getVisitedURIs();
                ResourceKey key = new ResourceKey(new ResourceURI(uri));
                String message;

                message = "\n";
                message += "Authentication required.\n";
                message += "realm: " + scheme.getRealm() + "\n";
View Full Code Here

            public Credentials getCredentials(AuthScheme scheme, String host, int port, boolean proxy)
                    throws CredentialsNotAvailableException {
                URI uri = ResourceContext.get().getCurrentURI();
                String username = ResourceContext.get().getCurrentUsername();
                Set visitedURIs = ResourceContext.get().getVisitedURIs();
                ResourceKey key = new ResourceKey(new ResourceURI(uri));
                String message;

                message = "\n";
                message += "Authentication required.\n";
                message += "realm: " + scheme.getRealm() + "\n";
View Full Code Here

            throw new ConfigException(e);
        }
    }

    protected ChannelSftp getOrCreateChannel(ResourceURI uri) {
        final ResourceKey key = new ResourceKey(uri);
        ChannelSftp channel;

        synchronized (channels) {
            channel = (ChannelSftp) channels.get(key);

            if (channel == null) {
                try {
                    ResourceContext.get().setCurrentURI(uri.getURI());

                    com.jcraft.jsch.Session session = jsch.getSession(key.getUser(), key.getHost(), key.getPort());

                    session.setUserInfo(new UserInfo() {
                        private UsernamePassword up;

                        public String getPassphrase() {
                            return null;
                        }

                        public boolean promptPassphrase(String message) {
                            return true;
                        }

                        public String getPassword() {
                            return up == null ? null : up.getPassword();
                        }

                        public boolean promptPassword(String message) {
                            URI uri = ResourceContext.get().getCurrentURI();
                            String username = ResourceContext.get().getCurrentUsername();
                            Set visitedURIs = ResourceContext.get().getVisitedURIs();

                            message = "\nAuthentication required: \n" + uri + "\n";

                            up = getResourceManager().getAuthenticationHandler().authenticate(message, uri, username,
                                                                                              visitedURIs.contains(key));

                            visitedURIs.add(key);

                            return up != null;
                        }

                        public boolean promptYesNo(String str) {
                            return true;
                        }

                        public void showMessage(String message) {
                        }
                    });

                    session.connect();

                    channel = (ChannelSftp) session.openChannel("sftp");
                    channel.connect();

                    String charset = uri.getOption("charset");

                    if (charset != null) {
                        channel.setFilenameEncoding(charset);
                    }

                    channels.put(key, channel);

                    // 成功就清除,以避免重复提示输入密码
                    ResourceContext.get().getVisitedURIs().remove(new ResourceKey(new ResourceURI(uri.getURI())));
                } catch (RuntimeException e) {
                    throw e;
                } catch (Exception e) {
                    throw new ConfigException(e);
                } finally {
View Full Code Here

            if (httpget.getStatusCode() != 200) {
                throw new ResourceNotFoundException(HttpStatus.getStatusText(httpget.getStatusCode()));
            }

            // 成功就清除,以避免重复提示输入密码
            ResourceContext.get().getVisitedURIs().remove(new ResourceKey(new ResourceURI(getURI().getURI())));

            content = httpget.getResponseBody();
            charset = httpget.getResponseCharSet();

            Header contentTypeHeader = httpget.getResponseHeader("Content-Type");
View Full Code Here

            if (httpget.getStatusCode() != 200) {
                throw new ResourceNotFoundException(HttpStatus.getStatusText(httpget.getStatusCode()));
            }

            // �ɹ���������Ա����ظ���ʾ��������
            ResourceContext.get().getVisitedURIs().remove(new ResourceKey(new ResourceURI(getURI().getURI())));

            content = httpget.getResponseBody();
            charset = httpget.getResponseCharSet();

            Header contentTypeHeader = httpget.getResponseHeader("Content-Type");
View Full Code Here

            public Credentials getCredentials(AuthScheme scheme, String host, int port, boolean proxy)
                    throws CredentialsNotAvailableException {
                URI uri = ResourceContext.get().getCurrentURI();
                String username = ResourceContext.get().getCurrentUsername();
                Set visitedURIs = ResourceContext.get().getVisitedURIs();
                ResourceKey key = new ResourceKey(new ResourceURI(uri));
                String message;

                message = "\n";
                message += "Authentication required.\n";
                message += "realm: " + scheme.getRealm() + "\n";
View Full Code Here

            throw new ConfigException(e);
        }
    }

    protected ChannelSftp getOrCreateChannel(ResourceURI uri) {
        final ResourceKey key = new ResourceKey(uri);
        ChannelSftp channel;

        synchronized (channels) {
            channel = (ChannelSftp) channels.get(key);

            if (channel == null) {
                try {
                    ResourceContext.get().setCurrentURI(uri.getURI());

                    com.jcraft.jsch.Session session = jsch.getSession(key.getUser(), key.getHost(), key.getPort());

                    session.setUserInfo(new UserInfo() {
                        private UsernamePassword up;

                        public String getPassphrase() {
                            return null;
                        }

                        public boolean promptPassphrase(String message) {
                            return true;
                        }

                        public String getPassword() {
                            return up == null ? null : up.getPassword();
                        }

                        public boolean promptPassword(String message) {
                            URI uri = ResourceContext.get().getCurrentURI();
                            String username = ResourceContext.get().getCurrentUsername();
                            Set visitedURIs = ResourceContext.get().getVisitedURIs();

                            message = "\nAuthentication required: \n" + uri + "\n";

                            up = getResourceManager().getAuthenticationHandler().authenticate(message, uri, username,
                                    visitedURIs.contains(key));

                            visitedURIs.add(key);

                            return up != null;
                        }

                        public boolean promptYesNo(String str) {
                            return true;
                        }

                        public void showMessage(String message) {
                        }
                    });

                    session.connect();

                    channel = (ChannelSftp) session.openChannel("sftp");
                    channel.connect();

                    String charset = uri.getOption("charset");

                    if (charset != null) {
                        channel.setFilenameEncoding(charset);
                    }

                    channels.put(key, channel);

                    // �ɹ���������Ա����ظ���ʾ��������
                    ResourceContext.get().getVisitedURIs().remove(new ResourceKey(new ResourceURI(uri.getURI())));
                } catch (RuntimeException e) {
                    throw e;
                } catch (Exception e) {
                    throw new ConfigException(e);
                } finally {
View Full Code Here

TOP

Related Classes of com.alibaba.antx.config.resource.util.ResourceKey

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.