Example usage for org.apache.commons.httpclient Header Header

List of usage examples for org.apache.commons.httpclient Header Header

Introduction

In this page you can find the example usage for org.apache.commons.httpclient Header Header.

Prototype

public Header(String paramString1, String paramString2) 

Source Link

Usage

From source file:org.wso2.carbon.axis2.handler.CookieHandler.java

@Override
public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {

    // TODO: invoke Cookie API. If success return InvocationResponse.CONTINUE, else InvocationResponse.ABORT

    // get OUT message context
    MessageContext outMessageContext = msgContext.getOperationContext().getMessageContext("Out");
    // here, a dummy cookie named MyCookie is set
    if (outMessageContext != null) {
        List<Header> headers = new ArrayList<Header>();
        headers.add(new Header(HTTPConstants.HEADER_SET_COOKIE, "MyCookie=DJFIASNB143VNJA453JKFS86FDSA"));
        outMessageContext.setProperty(HTTPConstants.HTTP_HEADERS, headers);
    }/* w ww  . jav a2s  .c  om*/

    return InvocationResponse.CONTINUE;
}

From source file:org.wso2.carbon.bpel.core.ode.integration.utils.AxisServiceUtils.java

public static void addCustomHeadersToMessageContext(MessageContext mctx) {

    List<Header> headers = null;

    BPELServerConfiguration bpelServerConfiguration = BPELServiceComponent.getBPELServer()
            .getBpelServerConfiguration();

    if (!bpelServerConfiguration.isKeepAlive()) {

        headers = new ArrayList();
        headers.add(new Header(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE));
    }//from   w  w  w  . j a  v  a2s . co  m

    //Add more custom header values in the future
    if ((headers != null) && (headers.size() > 0)) {
        mctx.setProperty(HTTPConstants.HTTP_HEADERS, headers);
    }
}

From source file:org.wso2.carbon.humantask.coordination.module.utils.ServiceUtils.java

public static void setBasicAccessSecurityHeaders(String userName, String password, boolean rememberMe,
        Options options) throws AxisFault {

    String userNamePassword = userName + ":" + password;
    String encodedString = Base64Utils.encode(userNamePassword.getBytes());

    String authorizationHeader = "Basic " + encodedString;

    List<Header> headers = new ArrayList<Header>();

    Header authHeader = new Header("Authorization", authorizationHeader);
    headers.add(authHeader);/* w ww .j  ava  2 s .com*/

    if (rememberMe) {
        Header rememberMeHeader = new Header("RememberMe", "true");
        headers.add(rememberMeHeader);
    }

    options.setProperty(HTTPConstants.HTTP_HEADERS, headers);
}

From source file:org.wso2.carbon.ui.util.CarbonUIAuthenticationUtil.java

/**
 * Sets the cookie information, i.e. whether remember me cookie is enabled of disabled. If enabled
 * we will send that information in a HTTP header.
 * @param cookie  The remember me cookie.
 * @param serviceClient The service client used in communication.
 *//*from   w ww .java 2 s.c om*/
public static void setCookieHeaders(Cookie cookie, ServiceClient serviceClient) {

    List<Header> headers = new ArrayList<Header>();
    Header rememberMeHeader = new Header("RememberMeCookieData", cookie.getValue());
    headers.add(rememberMeHeader);

    serviceClient.getOptions().setProperty(HTTPConstants.HTTP_HEADERS, headers);
}

From source file:org.wso2.carbon.utils.CarbonUtils.java

/**
* This is a utility method which can be used to set security headers in a service client. This method
* will create authorization header according to basic security protocol. i.e. encodeBase64(username:password)
* and put it in a HTTP header with name "Authorization".
* @param userName User calling the service.
* @param password Password of the user.// w w  w  . j  a va 2s. com
* @param rememberMe <code>true</code> if UI asks to persist remember me cookie.
* @param serviceClient The service client used in the communication.
*/
public static void setBasicAccessSecurityHeaders(String userName, String password, boolean rememberMe,
        ServiceClient serviceClient) {

    String userNamePassword = userName + ":" + password;
    String encodedString = Base64Utils.encode(userNamePassword.getBytes());

    String authorizationHeader = "Basic " + encodedString;

    List<Header> headers = new ArrayList<Header>();

    Header authHeader = new Header("Authorization", authorizationHeader);
    headers.add(authHeader);

    if (rememberMe) {
        Header rememberMeHeader = new Header("RememberMe", TRUE);
        headers.add(rememberMeHeader);
    }

    serviceClient.getOptions().setProperty(HTTPConstants.HTTP_HEADERS, headers);
}

From source file:org.wso2.carbon.utils.CarbonUtils.java

/**
 * This is a utility method which can be used to set security headers in the message context. This method
 * will create authorization header according to basic security protocol. i.e. encodeBase64(username:password)
 * and put it in a HTTP header with name "Authorization".
 * @param userName User calling the service.
 * @param password Password of the user.
 * @param rememberMe <code>true</code> if UI asks to persist remember me cookie.
 * @param msgContext The MessageContext of the message.
 *//*from   ww w .  ja  v a 2s  .  com*/

public static void setBasicAccessSecurityHeaders(String userName, String password, boolean rememberMe,
        MessageContext msgContext) throws AxisFault {

    String userNamePassword = userName + ":" + password;
    String encodedString = Base64Utils.encode(userNamePassword.getBytes());

    String authorizationHeader = "Basic " + encodedString;

    List<Header> headers = new ArrayList<Header>();

    Header authHeader = new Header("Authorization", authorizationHeader);
    headers.add(authHeader);

    if (rememberMe) {
        Header rememberMeHeader = new Header("RememberMe", TRUE);
        headers.add(rememberMeHeader);
    }

    msgContext.getOptions().setProperty(HTTPConstants.HTTP_HEADERS, headers);
}

From source file:org.wso2.dss.integration.test.util.ParallelRequestHelper.java

/**
 * constructor for parallel request helper
 * we can use this for the initial begin boxcarring request as well.(sending sessionCookie null)
 *
 * @param sessionCookie/*from   www .  j  a v a 2  s . c  o m*/
 * @param operation
 * @param payload
 * @param serviceEndPoint
 * @throws org.apache.axis2.AxisFault
 */
public ParallelRequestHelper(String sessionCookie, String operation, OMElement payload, String serviceEndPoint)
        throws AxisFault {
    this.payload = payload;
    sender = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(serviceEndPoint));
    options.setProperty("__CHUNKED__", Boolean.FALSE);
    options.setTimeOutInMilliSeconds(45000L);
    options.setAction("urn:" + operation);
    sender.setOptions(options);
    if (sessionCookie != null && !sessionCookie.isEmpty()) {
        Header header = new Header("Cookie", sessionCookie);
        ArrayList headers = new ArrayList();
        headers.add(header);
        sender.getOptions().setProperty(HTTPConstants.HTTP_HEADERS, headers);
    }
}

From source file:org.wso2.esb.integration.common.utils.clients.stockquoteclient.StockQuoteClient.java

public void addHttpHeader(String name, String value) {
    httpHeaders.add(new Header(name, value));
}

From source file:org.zaproxy.zap.network.ZapHttpParser.java

@SuppressWarnings({ "rawtypes", "unchecked", "null" })
public static Header[] parseHeaders(InputStream is, String charset) throws IOException, HttpException {
    ArrayList headers = new ArrayList();
    String name = null;//w  w w  .j a va2 s .c o  m
    StringBuffer value = null;
    for (;;) {
        String line = HttpParser.readLine(is, charset);
        if ((line == null) || (line.trim().length() < 1)) {
            break;
        }

        // Parse the header name and value
        // Check for folded headers first
        // Detect LWS-char see HTTP/1.0 or HTTP/1.1 Section 2.2
        // discussion on folded headers
        if ((line.charAt(0) == ' ') || (line.charAt(0) == '\t')) {
            // we have continuation folded header
            // so append value
            if (value != null) {
                value.append(' ');
                value.append(line.trim());
            }
        } else {
            // make sure we save the previous name,value pair if present
            if (name != null) {
                headers.add(new Header(name, value.toString()));
            }

            // Otherwise we should have normal HTTP header line
            // Parse the header name and value
            int colon = line.indexOf(":");
            if (colon < 0) {
                // Do not thrown the exception ignore it instead
                // throw new ProtocolException("Unable to parse header: " + line);
                logger.warn("Ignoring malformed HTTP header line: \"" + line + "\"");
                name = null;
                value = null;
            } else {
                name = line.substring(0, colon).trim();
                value = new StringBuffer(line.substring(colon + 1).trim());
            }
        }

    }

    // make sure we save the last name,value pair if present
    if (name != null) {
        headers.add(new Header(name, value.toString()));
    }

    return (Header[]) headers.toArray(new Header[headers.size()]);
}

From source file:smartrics.rest.client.MockHttpMethod.java

public Header[] getResponseHeaders() {
    Header h1 = new Header("name1", "value1");
    Header h2 = new Header("name1", "value1");
    return new Header[] { h1, h2 };
}