Example usage for org.springframework.remoting.httpinvoker HttpInvokerClientConfiguration getServiceUrl

List of usage examples for org.springframework.remoting.httpinvoker HttpInvokerClientConfiguration getServiceUrl

Introduction

In this page you can find the example usage for org.springframework.remoting.httpinvoker HttpInvokerClientConfiguration getServiceUrl.

Prototype

String getServiceUrl();

Source Link

Document

Return the HTTP URL of the target service.

Usage

From source file:gov.nih.nci.system.springframework.remoting.httpinvoker.HttpInvokerRequestExecutor.java

protected HttpURLConnection openConnection(HttpInvokerClientConfiguration config) throws IOException {
    String url = config.getServiceUrl();
    if (url == null)
        throw new IOException("Service URL can not be empty");

    return super.openConnection(config);
}

From source file:gov.nih.nci.system.springframework.remoting.httpinvoker.GSIHttpInvokerRequestExecutor.java

protected boolean globusSecurityNeeded(HttpInvokerClientConfiguration config) {
    String url = config.getServiceUrl();
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();

    if (url != null && url.startsWith("https://") && auth != null && auth instanceof X509AuthenticationToken
            && auth.getDetails() != null && auth.getDetails() instanceof GlobusCredential)
        return true;
    return false;
}

From source file:gov.nih.nci.system.springframework.remoting.httpinvoker.GSIHttpInvokerRequestExecutor.java

protected HttpURLConnection openConnection(HttpInvokerClientConfiguration config) throws IOException {
    String url = config.getServiceUrl();
    if (url == null)
        throw new IOException("Service URL can not be empty");

    if (globusSecurityNeeded(config))
        return openSecuredGlobusConnection(config);
    else/*from  w w  w  . j ava  2 s.c  om*/
        return super.openConnection(config);
}

From source file:org.springframework.remoting.httpinvoker.HttpComponentsHttpInvokerRequestExecutorTests.java

private HttpInvokerClientConfiguration mockHttpInvokerClientConfiguration(String serviceUrl) {
    HttpInvokerClientConfiguration config = mock(HttpInvokerClientConfiguration.class);
    when(config.getServiceUrl()).thenReturn(serviceUrl);
    return config;
}

From source file:de.juwimm.cms.common.http.Server2ServerAuthenticationStreamSupportingHttpInvokerRequestExecutor.java

protected PostMethod createPostMethod(HttpInvokerClientConfiguration config) throws IOException {
    HttpClientWrapper.getInstance().setHostConfiguration(super.getHttpClient(),
            new URL(config.getServiceUrl()));
    PostMethod postMethod = new PostMethod(config.getServiceUrl());
    if (isAcceptGzipEncoding()) {
        postMethod.addRequestHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
    }//from  w  w  w  . ja v  a 2  s.  co m
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if ((auth != null) && (auth.getName() != null) && (auth.getCredentials() != null)) {
        postMethod.setDoAuthentication(true);
        String base64 = auth.getName() + ":" + auth.getCredentials().toString();
        postMethod.addRequestHeader("Authorization",
                "Basic " + new String(Base64.encodeBase64(base64.getBytes())));

        if (log.isDebugEnabled()) {
            // log.debug("HttpInvocation now presenting via BASIC
            // authentication SecurityContextHolder-derived: " +
            // auth.toString());
            log.debug("HttpInvocation now presenting via BASIC authentication SecurityContextHolder-derived: "
                    + auth.getName());
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Unable to set BASIC authentication header as SecurityContext did not provide "
                    + "valid Authentication: " + auth);
        }
    }
    return postMethod;
}

From source file:de.juwimm.cms.common.http.Server2ServerAuthenticationStreamSupportingHttpInvokerRequestExecutor.java

protected PostMethod createPostMethodForStreaming(final HttpInvokerClientConfiguration config)
        throws IOException {
    HttpClientWrapper.getInstance().setHostConfiguration(super.getHttpClient(),
            new URL(config.getServiceUrl()));
    final PostMethod postMethod = new PostMethod(config.getServiceUrl());
    postMethod.setRequestHeader(HTTP_HEADER_CONTENT_TYPE, CONTENT_TYPE_SERIALIZED_OBJECT_WITH_STREAM);
    postMethod.setContentChunked(true);// w  w  w.  j  av a 2s  .  c o m

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();

    if ((auth != null) && (auth.getName() != null) && (auth.getCredentials() != null)) {
        postMethod.setDoAuthentication(true);
        String base64 = auth.getName() + ":" + auth.getCredentials().toString();
        postMethod.addRequestHeader("Authorization",
                "Basic " + new String(Base64.encodeBase64(base64.getBytes())));

        if (log.isDebugEnabled()) {
            // log.debug("HttpInvocation now presenting via BASIC
            // authentication SecurityContextHolder-derived: " +
            // auth.toString());
            log.debug(
                    "HttpInvocation now presenting via BASIC authentication SecurityContextHolder-derived. User: "
                            + auth.getName());
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Unable to set BASIC authentication header as SecurityContext did not provide "
                    + "valid Authentication: " + auth);
        }
    }
    return postMethod;
}

From source file:de.juwimm.cms.common.http.Server2ServerAuthenticationStreamSupportingHttpInvokerRequestExecutor.java

@Override
protected void executePostMethod(HttpInvokerClientConfiguration config, HttpClient httpClient,
        PostMethod postMethod) throws IOException {
    HttpClientWrapper.getInstance().setHostConfiguration(super.getHttpClient(),
            new URL(config.getServiceUrl()));
    super.executePostMethod(config, httpClient, postMethod);
}

From source file:de.juwimm.cms.common.http.Server2ServerAuthenticationStreamSupportingHttpInvokerRequestExecutor.java

@Override
protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config,
        ByteArrayOutputStream baos) throws IOException, ClassNotFoundException {
    HttpClientWrapper.getInstance().setHostConfiguration(super.getHttpClient(),
            new URL(config.getServiceUrl()));
    RemoteInvocationResult r = super.doExecuteRequest(config, baos);
    return r;/*from  w  w  w .j  av a  2  s  .c om*/
}

From source file:org.springframework.remoting.httpinvoker.HttpComponentsHttpInvokerRequestExecutor.java

/**
 * Create a HttpPost for the given configuration.
 * <p>The default implementation creates a standard HttpPost with
 * "application/x-java-serialized-object" as "Content-Type" header.
 * @param config the HTTP invoker configuration that specifies the
 * target service//from ww w.j av  a2 s .  co  m
 * @return the HttpPost instance
 * @throws java.io.IOException if thrown by I/O methods
 */
protected HttpPost createHttpPost(HttpInvokerClientConfiguration config) throws IOException {
    HttpPost httpPost = new HttpPost(config.getServiceUrl());
    LocaleContext locale = LocaleContextHolder.getLocaleContext();
    if (locale != null) {
        httpPost.addHeader(HTTP_HEADER_ACCEPT_LANGUAGE, StringUtils.toLanguageTag(locale.getLocale()));
    }
    if (isAcceptGzipEncoding()) {
        httpPost.addHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
    }
    return httpPost;
}

From source file:de.juwimm.cms.http.AuthenticationStreamSupportingHttpInvokerRequestExecutor.java

protected PostMethod createPostMethodForStreaming(final HttpInvokerClientConfiguration config)
        throws IOException {
    HttpClientWrapper.getInstance().setHostConfiguration(super.getHttpClient(),
            new URL(config.getServiceUrl()));
    final PostMethod postMethod = new PostMethod(config.getServiceUrl());
    postMethod.setRequestHeader(HTTP_HEADER_CONTENT_TYPE, CONTENT_TYPE_SERIALIZED_OBJECT_WITH_STREAM);
    //Solution for TIZZIT-282
    //postMethod.setContentChunked(true);

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();

    if ((auth != null) && (auth.getName() != null) && (auth.getCredentials() != null)) {
        postMethod.setDoAuthentication(true);
        String base64 = auth.getName() + ":" + auth.getCredentials().toString();
        postMethod.addRequestHeader("Authorization",
                "Basic " + new String(Base64.encodeBase64(base64.getBytes())));

        if (log.isDebugEnabled()) {
            // log.debug("HttpInvocation now presenting via BASIC
            // authentication SecurityContextHolder-derived: " +
            // auth.toString());
            log.debug(//from   w  ww .java2  s . c  o m
                    "HttpInvocation now presenting via BASIC authentication SecurityContextHolder-derived. User: "
                            + auth.getName());
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Unable to set BASIC authentication header as SecurityContext did not provide "
                    + "valid Authentication: " + auth);
        }
    }
    return postMethod;
}