use of com.bluenimble.platform.http.HttpEndpoint in project serverless by bluenimble.
the class OAuthHttpRequestVisitor method visit.
@Override
public void visit(HttpRequest request, HttpURLConnection connection) throws HttpRequestWriteException {
HttpEndpoint endpoint = ((AbstractHttpRequest) request).getEndpoint();
OAuthConsumer consumer = new DefaultOAuthConsumer(key, secret);
HttpParameters encodedParams = new HttpParameters();
List<HttpParameter> params = request.getParameters();
if (params != null && !params.isEmpty()) {
for (HttpParameter p : params) {
if (p.getValue() != null) {
encodedParams.put(p.getName(), OAuth.percentEncode(String.valueOf(p.getValue())));
}
}
}
encodedParams.put("realm", endpoint.getScheme() + "://" + endpoint.getHost() + endpoint.getPath());
consumer.setAdditionalParameters(encodedParams);
try {
consumer.sign(connection);
} catch (Exception e) {
throw new HttpRequestWriteException(e.getMessage(), e);
}
}
use of com.bluenimble.platform.http.HttpEndpoint in project serverless by bluenimble.
the class HttpUtils method createEndpoint.
public static HttpEndpoint createEndpoint(final URI uri) {
if (uri == null) {
return null;
}
HttpEndpoint target = null;
if (uri.isAbsolute()) {
// may be overridden later
int port = uri.getPort();
String host = uri.getHost();
if (host == null) {
// normal parse failed;
// authority does not seem to care about the valid charset
// for host names
host = uri.getAuthority();
if (host != null) {
// Strip off any leading user credentials
int at = host.indexOf('@');
if (at >= 0) {
if (host.length() > at + 1) {
host = host.substring(at + 1);
} else {
// @ on its own
host = null;
}
}
// Extract the port suffix, if present
if (host != null) {
int colon = host.indexOf(':');
if (colon >= 0) {
if (colon + 1 < host.length()) {
port = Integer.parseInt(host.substring(colon + 1));
}
host = host.substring(0, colon);
}
}
}
}
if (host != null) {
target = new HttpEndpoint(uri.getScheme(), host, port, uri.getPath(), uri.getQuery());
}
}
return target;
}
Aggregations