Package com.sun.enterprise.admin.util

Examples of com.sun.enterprise.admin.util.HttpConnectorAddress


         * and password, is used for process-to-process authentication.
         */
        try {
            final String certAlias = SecureAdmin.Util.isUsingUsernamePasswordAuth(secureAdmin) ?
                    null : getCertAlias();
            return new HttpConnectorAddress(host, port,
                    sslUtils().getAdminSocketFactory(certAlias, SSL_SOCKET_PROTOCOL));
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
View Full Code Here


       
        /*
         * Note: HttpConnectorAddress will set up SSL/TLS client cert
         * handling if the current configuration calls for it.
         */
        HttpConnectorAddress url = getHttpConnectorAddress(
                                host, port, shouldUseSecure);
        url.setInteractive(interactive);

        do {
            /*
             * Any code that wants to trigger a retry will say so explicitly.
             */
            shouldTryCommandAgain = false;
            try {
                if (logger.isLoggable(Level.FINER)) {
                    logger.log(Level.FINER, "URI: {0}", uriString);
                    logger.log(Level.FINER, "URL: {0}", url.toString());
                    logger.log(Level.FINER, "URL: {0}", url.toURL(uriString).toString());
                    logger.log(Level.FINER, "Password options: {0}", passwordOptions);
                    logger.log(Level.FINER, "Using auth info: User: {0}, Password: {1}",
                            new Object[]{user, ok(password) ? "<non-null>" : "<null>"});
                }
                final AuthenticationInfo authInfo = authenticationInfo();
                if (authInfo != null) {
                    url.setAuthenticationInfo(authInfo);
                }
                urlConnection = (HttpURLConnection) url.openConnection(uriString);
                urlConnection.setRequestProperty("User-Agent", responseFormatType);
                if (passwordOptions != null) {
                    urlConnection.setRequestProperty("X-passwords", passwordOptions.toString());
                }
                urlConnection.addRequestProperty("Cache-Control", "no-cache");
                urlConnection.addRequestProperty("Pragma", "no-cache");

                if (authToken != null) {
                    /*
                     * If this request is for metadata then we expect to reuse
                     * the auth token.  
                     */
                    urlConnection.setRequestProperty(
                            SecureAdmin.Util.ADMIN_ONE_TIME_AUTH_TOKEN_HEADER_NAME,
                            (isForMetadata ? AuthTokenManager.markTokenForReuse(authToken) : authToken));
                }
                if (commandModel != null && isCommandModelFromCache() && commandModel instanceof CachedCommandModel) {
                    urlConnection.setRequestProperty(COMMAND_MODEL_MATCH_HEADER, ((CachedCommandModel) commandModel).getETag());
                    if (logger.isLoggable(Level.FINER)) {
                        logger.log(Level.FINER, "CommandModel ETag: {0}", ((CachedCommandModel) commandModel).getETag());
                    }
                }
                urlConnection.setRequestMethod(httpMethod);
                urlConnection.setReadTimeout(readTimeout);
                if (connectTimeout >= 0) {
                    urlConnection.setConnectTimeout(connectTimeout);
                }
                addAdditionalHeaders(urlConnection);
                urlConnection.addRequestProperty("X-Requested-By", "cli");
                cmd.prepareConnection(urlConnection);
                urlConnection.connect();
                /*
                 * We must handle redirection from http to https explicitly
                 * because, even if the HttpURLConnection's followRedirect is
                 * set to true, the Java SE implementation does not do so if the
                 * procotols are different.
                 */
                String redirection = checkConnect(urlConnection);
                if (redirection != null) {
                    /*
                     * Log at FINER; at FINE it would appear routinely when used from
                     * asadmin.
                     */
                    logger.log(Level.FINER, "Following redirection to " + redirection);
                    url = followRedirection(url, redirection);
                    shouldTryCommandAgain = true;
                    /*
                     * Record that, during the retry of this request, we should
                     * use https.
                     */
                    shouldUseSecure = url.isSecure();

                    /*
                     * Record that, if this is a metadata request, the real
                     * request should use https also.
                     */
 
View Full Code Here

    private HttpConnectorAddress followRedirection(
            final HttpConnectorAddress originalAddr,
            final String redirection) throws MalformedURLException {
        final URL url = new URL(redirection);
        final boolean useSecure = (url.getProtocol().equalsIgnoreCase("https"));
        HttpConnectorAddress hca = new HttpConnectorAddress(
                url.getHost(),
                url.getPort(),
                useSecure,
                originalAddr.getPath(),
                originalAddr.getSSLSocketFactory());
        hca.setInteractive(interactive);
        return hca;
    }
View Full Code Here

     * @param shouldUseSecure whether SSL should be used to connect or not
     * @return
     */
    protected HttpConnectorAddress getHttpConnectorAddress(
            final String host, final int port, final boolean shouldUseSecure) {
        HttpConnectorAddress hca = new HttpConnectorAddress(
                                host, port, shouldUseSecure);
        hca.setInteractive(interactive);
        return hca;
    }
View Full Code Here

       
        /*
         * Note: HttpConnectorAddress will set up SSL/TLS client cert
         * handling if the current configuration calls for it.
         */
        HttpConnectorAddress url = getHttpConnectorAddress(
                                host, port, shouldUseSecure);
        url.setInteractive(interactive);
        do {
            /*
             * Any code that wants to trigger a retry will say so explicitly.
             */
            shouldTryCommandAgain = false;
            try {
                logger.log(Level.FINER, "URI: {0}", uriString);
                logger.log(Level.FINER, "URL: {0}", url.toString());
                logger.log(Level.FINER, "URL: {0}", url.toURL(uriString).toString());
                logger.log(Level.FINER, "Password options: {0}", passwordOptions);
                logger.log(Level.FINER, "Using auth info: User: {0}, Password: {1}",
                        new Object[]{user, ok(password) ? "<non-null>" : "<null>"});

                final AuthenticationInfo authInfo = authenticationInfo();
                if (authInfo != null) {
                    url.setAuthenticationInfo(authInfo);
                }
                urlConnection = (HttpURLConnection)
                        url.openConnection(uriString.toString());
                urlConnection.setRequestProperty("User-Agent", responseFormatType);
                if (passwordOptions != null) {
                    urlConnection.setRequestProperty("X-passwords", passwordOptions.toString());
                }

                if (shouldSendCredentials) {
                    urlConnection.setRequestProperty(
                            HttpConnectorAddress.AUTHORIZATION_KEY,
                            url.getBasicAuthString());
                }
                if (authToken != null) {
                    /*
                     * If this request is for metadata then we expect to reuse
                     * the auth token.  
                     */
                    urlConnection.setRequestProperty(
                            SecureAdmin.Util.ADMIN_ONE_TIME_AUTH_TOKEN_HEADER_NAME,
                            (isForMetadata ? AuthTokenManager.markTokenForReuse(authToken) : authToken));
                }
                urlConnection.setRequestMethod(httpMethod);
                urlConnection.setReadTimeout(readTimeout);
                if (connectTimeout >= 0)
                    urlConnection.setConnectTimeout(connectTimeout);
                addAdditionalHeaders(urlConnection);
               
                cmd.prepareConnection(urlConnection);
                urlConnection.connect();
                /*
                 * We must handle redirection from http to https explicitly
                 * because, even if the HttpURLConnection's followRedirect is
                 * set to true, the Java SE implementation does not do so if the
                 * procotols are different.
                 */
                String redirection = checkConnect(urlConnection);
                if (redirection != null) {
                    /*
                     * Log at FINER; at FINE it would appear routinely when used from
                     * asadmin.
                     */
                    logger.log(Level.FINER, "Following redirection to " + redirection);
                    url = followRedirection(url, redirection);
                    shouldTryCommandAgain = true;
                    /*
                     * Record that, during the retry of this request, we should
                     * use https.
                     */
                    shouldUseSecure = url.isSecure();

                    /*
                     * Record that, if this is a metadata request, the real
                     * request should use https also.
                     */
 
View Full Code Here

    private HttpConnectorAddress followRedirection(
            final HttpConnectorAddress originalAddr,
            final String redirection) throws MalformedURLException {
        final URL url = new URL(redirection);
        final boolean useSecure = (url.getProtocol().equalsIgnoreCase("https"));
        HttpConnectorAddress hca = new HttpConnectorAddress(
                url.getHost(),
                url.getPort(),
                useSecure,
                originalAddr.getPath(),
                originalAddr.getSSLSocketFactory());
        hca.setInteractive(interactive);
        return hca;
    }
View Full Code Here

     * @param shouldUseSecure whether SSL should be used to connect or not
     * @return
     */
    protected HttpConnectorAddress getHttpConnectorAddress(
            final String host, final int port, final boolean shouldUseSecure) {
        HttpConnectorAddress hca = new HttpConnectorAddress(
                                host, port, shouldUseSecure);
        hca.setInteractive(interactive);
        return hca;
    }
View Full Code Here

         * and password, is used for process-to-process authentication.
         */
        try {
            final String certAlias = SecureAdmin.Util.isUsingUsernamePasswordAuth(secureAdmin) ?
                    null : getCertAlias();
            return new HttpConnectorAddress(host, port,
                    sslUtils().getAdminSocketFactory(certAlias, SSL_SOCKET_PROTOCOL));
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
View Full Code Here

        @Override
        public HttpURLConnection getHttpURLConnection(URL url) throws IOException {
            final Domain domain = habitat.getComponent(Domain.class);
            SecureAdmin secureAdmin = domain.getSecureAdmin();
            final String certAlias = SecureAdmin.Util.isUsingUsernamePasswordAuth(secureAdmin) ? null : SecureAdmin.Util.DASAlias(secureAdmin);
            HttpConnectorAddress httpConnectorAddress = new HttpConnectorAddress(habitat.getComponent(SSLUtils.class).getAdminSocketFactory(certAlias, "TLS"));
            AuthenticationInfo authenticationInfo = authenticationInfo(habitat, secureAdmin);
            if (authenticationInfo != null) {
                httpConnectorAddress.setAuthenticationInfo(authenticationInfo);
            }
            HttpURLConnection httpURLConnection = (HttpURLConnection) httpConnectorAddress.openConnection(url); // The URL constructed for REST will always be Http(s) so, it is ok to cast here.
            //TODO following code is copied from ServerRemoteAdminCommand.addAdditionalHeaders. When the clean up happens on trunk. this code needs to be accounted for.
            // Here are comments copied from javadoc of the method
            //* Adds the admin indicator header to the request so. Do this whether
            //* secure admin is enabled or not, because the indicator is unique among
            //* domains to help make sure only processes in the same domain talk to
View Full Code Here

        @Override
        public HttpURLConnection getHttpURLConnection(URL url) throws IOException {
            final Domain domain = habitat.getComponent(Domain.class);
            SecureAdmin secureAdmin = domain.getSecureAdmin();
            final String certAlias = SecureAdmin.Util.isUsingUsernamePasswordAuth(secureAdmin) ? null : SecureAdmin.Util.DASAlias(secureAdmin);
            HttpConnectorAddress httpConnectorAddress = new HttpConnectorAddress(habitat.getComponent(SSLUtils.class).getAdminSocketFactory(certAlias, "TLS"));
            AuthenticationInfo authenticationInfo = authenticationInfo(habitat, secureAdmin);
            if (authenticationInfo != null) {
                httpConnectorAddress.setAuthenticationInfo(authenticationInfo);
            }
            HttpURLConnection httpURLConnection = (HttpURLConnection) httpConnectorAddress.openConnection(url); // The URL constructed for REST will always be Http(s) so, it is ok to cast here.
            //Hack - httpConnectorAddress calls httpURLConnection.setRequestProperty("Content-type", "application/octet-stream"); before returning connection above
            //Our resources are only capable of accepting xml, json and form. Override here to apploication/json (randomly picked one of the three). This should not be required after HttpConnectorAddress refactoring in trunk.
            httpURLConnection.setRequestProperty("Content-type", "application/json");
            return httpURLConnection;
        }
View Full Code Here

TOP

Related Classes of com.sun.enterprise.admin.util.HttpConnectorAddress

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.