in iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/hsm/HttpsHsmClient.java [166:233]
private HttpsResponse sendRequestBasedOnScheme(HttpsMethod httpsMethod, byte[] body, String baseUri, String path, String queryString) throws TransportException, IOException
{
URL requestUrl;
if (this.scheme.equalsIgnoreCase(HTTPS_SCHEME) || this.scheme.equalsIgnoreCase(HTTP_SCHEME))
{
if (queryString != null && !queryString.isEmpty())
{
requestUrl = new URL(baseUri + path + "?" + queryString);
}
else
{
requestUrl = new URL(baseUri + path);
}
}
else if (this.scheme.equalsIgnoreCase(UNIX_SCHEME))
{
//leave the url null, for unix flow, there is no need to build a URL instance
requestUrl = null;
}
else
{
throw new UnsupportedOperationException("unrecognized URI scheme. Only HTTPS, HTTP and UNIX are supported");
}
// requestUrl will be null, if unix socket is used, but HttpsRequest won't null check it until we send the request.
// In the unix case, we don't build the https request to send it, we just build it to hold all the information that
// will go into the unix socket request later, such as headers, method, etc.
HttpsRequest httpsRequest = new HttpsRequest(requestUrl, httpsMethod, body, "");
httpsRequest.setHeaderField("Accept", "application/json");
if (body.length > 0)
{
httpsRequest.setHeaderField("Content-Type", "application/json");
}
HttpsResponse response;
if (this.scheme.equalsIgnoreCase(HTTPS_SCHEME))
{
response = httpsRequest.send();
}
else if (this.scheme.equalsIgnoreCase(HTTP_SCHEME))
{
response = httpsRequest.sendAsHttpRequest();
}
else if (this.scheme.equalsIgnoreCase(UNIX_SCHEME))
{
if (this.unixDomainSocketChannel == null)
{
throw new IllegalArgumentException("Must provide an implementation of the UnixDomainSocketChannel interface since this edge runtime setup requires communicating over unix domain sockets.");
}
else
{
log.trace("User provided UnixDomainSocketChannel will be used for setup.");
}
String unixAddressPrefix = UNIX_SCHEME + "://";
String localUnixSocketPath = baseUri.substring(baseUri.indexOf(unixAddressPrefix) + unixAddressPrefix.length());
response = sendHttpRequestUsingUnixSocket(httpsRequest, path, queryString, localUnixSocketPath);
}
else
{
throw new UnsupportedOperationException("unrecognized URI scheme \"" + this.scheme + "\". Only HTTPS, HTTP and UNIX are supported");
}
return response;
}