Search in sources :

Example 6 with HttpParameter

use of com.bluenimble.platform.http.HttpParameter in project serverless by bluenimble.

the class AccessSecretKeysBasedHttpRequestSigner method sign.

@Override
public void sign(HttpRequest request) throws HttpRequestSignerException {
    List<HttpParameter> params = request.getParameters();
    String signature = null;
    try {
        URI uri = request.getURI();
        signature = generate(params, uri.getScheme() + "://" + uri.getHost(), uri.getPort(), uri.getPath(), request.getName());
    } catch (Throwable th) {
        throw new HttpRequestSignerException(th);
    }
    if (SignaturePlaceHolder.Headers.equals(signatureParameterPlace)) {
        List<HttpHeader> headers = request.getHeaders();
        if (headers == null) {
            headers = new ArrayList<HttpHeader>();
            request.setHeaders(headers);
        }
        headers.add(new HttpHeaderImpl(HttpHeaders.AUTHORIZATION, scheme + " " + accessKey + ":" + signature));
    } else {
        if (signatureParameterName == null) {
            signatureParameterName = "signature";
        }
        params.add(new HttpParameterImpl(signatureParameterName, encode(signature)));
    }
}
Also used : HttpParameterImpl(com.bluenimble.platform.http.impls.HttpParameterImpl) HttpHeader(com.bluenimble.platform.http.HttpHeader) HttpRequestSignerException(com.bluenimble.platform.http.auth.HttpRequestSignerException) HttpParameter(com.bluenimble.platform.http.HttpParameter) URI(java.net.URI) HttpHeaderImpl(com.bluenimble.platform.http.impls.HttpHeaderImpl)

Example 7 with HttpParameter

use of com.bluenimble.platform.http.HttpParameter in project serverless by bluenimble.

the class AbstractHttpRequest method dumpParameters.

protected String dumpParameters() throws UnsupportedEncodingException {
    if (parameters == null || parameters.isEmpty()) {
        return null;
    }
    StringBuilder sb = new StringBuilder();
    for (HttpParameter p : parameters) {
        p.dump(sb, charset);
        if (parameters.indexOf(p) < (parameters.size() - 1)) {
            sb.append("&");
        }
    }
    String s = sb.toString();
    sb.setLength(0);
    sb = null;
    return s;
}
Also used : HttpParameter(com.bluenimble.platform.http.HttpParameter)

Aggregations

HttpParameter (com.bluenimble.platform.http.HttpParameter)7 HttpEndpoint (com.bluenimble.platform.http.HttpEndpoint)3 HttpHeader (com.bluenimble.platform.http.HttpHeader)3 HttpHeaderImpl (com.bluenimble.platform.http.impls.HttpHeaderImpl)3 HttpParameterImpl (com.bluenimble.platform.http.impls.HttpParameterImpl)3 URI (java.net.URI)3 HttpMessageBody (com.bluenimble.platform.http.HttpMessageBody)2 HttpMessageBodyImpl (com.bluenimble.platform.http.impls.HttpMessageBodyImpl)2 StringHttpMessageBodyPart (com.bluenimble.platform.http.impls.StringHttpMessageBodyPart)2 HttpRequestWriteException (com.bluenimble.platform.http.request.HttpRequestWriteException)2 AbstractHttpRequest (com.bluenimble.platform.http.request.impls.AbstractHttpRequest)2 JsonObject (com.bluenimble.platform.json.JsonObject)2 IOException (java.io.IOException)2 CommandExecutionException (com.bluenimble.platform.cli.command.CommandExecutionException)1 StreamPointer (com.bluenimble.platform.cli.command.parser.converters.StreamPointer)1 YamlObject (com.bluenimble.platform.cli.impls.YamlObject)1 HttpClientException (com.bluenimble.platform.http.HttpClientException)1 HttpRequestSignerException (com.bluenimble.platform.http.auth.HttpRequestSignerException)1 AccessSecretKeysBasedHttpRequestSigner (com.bluenimble.platform.http.auth.impls.AccessSecretKeysBasedHttpRequestSigner)1 InputStreamHttpMessageBodyPart (com.bluenimble.platform.http.impls.InputStreamHttpMessageBodyPart)1