Example usage for org.apache.http.protocol HTTP TARGET_HOST

List of usage examples for org.apache.http.protocol HTTP TARGET_HOST

Introduction

In this page you can find the example usage for org.apache.http.protocol HTTP TARGET_HOST.

Prototype

String TARGET_HOST

To view the source code for org.apache.http.protocol HTTP TARGET_HOST.

Click Source Link

Usage

From source file:org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscaleUtil.java

/**
 * TODO These methods should use to common place since these are using endpoints and mediators
 *///  ww w . j  av  a 2  s.c o m
@SuppressWarnings("unchecked")
public static String getTargetHost(MessageContext synCtx) {
    org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) synCtx)
            .getAxis2MessageContext();
    Map<String, String> headers = (Map<String, String>) axis2MessageContext
            .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
    String address = headers.get(HTTP.TARGET_HOST);
    if (address.contains(":")) {
        address = address.substring(0, address.indexOf(":"));
    }
    return address;
}

From source file:org.apache.synapse.endpoints.ServiceDynamicLoadbalanceEndpoint.java

private String getTargetHost(MessageContext synCtx) {
    org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) synCtx)
            .getAxis2MessageContext();
    Map<String, String> headers = (Map<String, String>) axis2MessageContext
            .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
    String address = headers.get(HTTP.TARGET_HOST);
    synCtx.setProperty("LB_REQUEST_HOST", address); // Need to set with the port
    if (address.contains(":")) {
        address = address.substring(0, address.indexOf(":"));
    }//from ww w.j a va  2  s. c o m
    return address;
}

From source file:org.apache.synapse.rest.API.java

private String getHostHeader(org.apache.axis2.context.MessageContext msgCtx) {
    Map transportHeaders = (Map) msgCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
    String hostHeader = null;//from   ww  w  .  ja v a  2s .c o  m
    if (transportHeaders != null) {
        hostHeader = (String) transportHeaders.get(HTTP.TARGET_HOST);
    }

    if (hostHeader == null) {
        hostHeader = (String) msgCtx.getProperty(NhttpConstants.SERVICE_PREFIX);
    }
    return hostHeader;
}

From source file:org.apache.synapse.endpoints.DynamicLoadbalanceEndpoint.java

private String extractHost(MessageContext synCtx) {
    org.apache.axis2.context.MessageContext msgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();

    Map headerMap = (Map) msgCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
    String hostName = null;/*w  ww .ja  v a2s .  c o m*/
    if (headerMap != null) {
        Object hostObj = headerMap.get(HTTP.TARGET_HOST);
        hostName = (String) hostObj;
        if (hostName.contains(":")) {
            hostName = hostName.substring(0, hostName.indexOf(":"));
        }
    }
    return hostName;
}

From source file:org.apache.synapse.endpoints.DynamicLoadbalanceEndpoint.java

private int extractPort(MessageContext synCtx, String transport) {
    org.apache.axis2.context.MessageContext msgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();

    Map headerMap = (Map) msgCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
    int port = -1;
    if (headerMap != null) {
        String hostHeader = (String) headerMap.get(HTTP.TARGET_HOST);
        int preIndex = hostHeader.indexOf(":");
        int postIndex = hostHeader.indexOf("/");
        if (preIndex != -1 && postIndex != -1) {
            port = Integer.parseInt(hostHeader.trim().substring(preIndex + 1, postIndex));
        } else if (preIndex != -1) {
            port = Integer.parseInt(hostHeader.trim().substring(preIndex + 1));
        } else {/*from   w  ww.j a v a 2s .  c  o  m*/
            if ("http".equals(transport)) {
                port = 80;
            } else if ("https".equals(transport)) {
                port = 443;
            }
        }
    }
    return port;
}

From source file:org.apache.stratos.load.balancer.endpoint.TenantAwareLoadBalanceEndpoint.java

private String extractTargetHost(MessageContext synCtx) {
    org.apache.axis2.context.MessageContext msgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();

    Map headerMap = (Map) msgCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
    String hostName = null;//from  w ww .  j  av  a2 s .c o  m
    if (headerMap != null) {
        Object hostObj = headerMap.get(HTTP.TARGET_HOST);
        hostName = (String) hostObj;
        if (hostName.contains(":")) {
            hostName = hostName.substring(0, hostName.indexOf(":"));
        }
    }
    return hostName;
}

From source file:net.yacy.cora.protocol.http.HTTPClient.java

private void setHeaders(final HttpUriRequest httpUriRequest) {
    if (this.headers != null) {
        for (final Entry<String, String> entry : this.headers) {
            httpUriRequest.setHeader(entry.getKey(), entry.getValue());
        }//from w  w w.  ja v  a2  s  .  c  o  m
    }
    if (this.host != null)
        httpUriRequest.setHeader(HTTP.TARGET_HOST, this.host);
    httpUriRequest.setHeader(HTTP.CONN_DIRECTIVE, "close"); // don't keep alive, prevent CLOSE_WAIT state
}