我正在尝试从两个不同的类(测试类和服务类)发出以下请求-
serviceURL.listContainersSegment(null, new ListContainersOptions()).blockingGet().body().containerItems().forEach(container -> {
System.out.println("createServiceUrl | Container "+container.name());
});
测试类结果:
该请求将按应有的方式执行,并且我正在Azure存储帐户中获取容器的名称。使用Wireshark发出并验证了请求
服务等级结果:
注意: 服务类以jar形式存在,并在另一个应用程序中以Vertx垂直版本进行部署。
代码详细信息::此函数将仅返回ServiceURL对象。从同一类中的另一个方法onRequest(进一步提到)调用此方法。
* Create Service URL
* @param storageAccountName
* @param storageAccountKey
* @param endpointUrl
* @return
* @throws InvalidKeyException
* @throws MalformedURLException
*/
private ServiceURL createServiceUrl(String storageAccountName, String storageAccountKey, String endpointUrl, String endpointProtocol) throws InvalidKeyException, MalformedURLException {
ServiceURL serviceURL = null;
try {
FlintLogger.JOB_LOGGER.info("createServiceUrl | Creating Service URL");
FlintLogger.JOB_LOGGER.debug("createServiceUrl | Creating Service URL with inputs: \n"+storageAccountName+"\n"+storageAccountKey+"\n"+endpointUrl+"\n"+endpointProtocol);
// Use your Storage account's name and key to create a credential object; this is used to access your account.
SharedKeyCredentials credential = new SharedKeyCredentials(storageAccountName, storageAccountKey);
FlintLogger.JOB_LOGGER.info("createServiceUrl | Storage credentials created "+credential.toString());
/*
Create a request pipeline that is used to process HTTP(S) requests and responses. It requires your accont
credentials. In more advanced scenarios, you can configure telemetry, retry policies, logging, and other
options. Also you can configure multiple pipelines for different scenarios.
*/
HttpPipeline pipeline = StorageURL.createPipeline(credential, new PipelineOptions());
FlintLogger.JOB_LOGGER.info("createServiceUrl | Created Http pipeline "+pipeline);
/*
From the Azure portal, get your Storage account blob service URL endpoint.
The URL typically looks like this:
*/
URL url = new URL(String.format(Locale.ROOT, endpointProtocol+"://%s.blob."+endpointUrl, storageAccountName));
FlintLogger.JOB_LOGGER.debug("createServiceUrl | Created Url with specified endpoint "+url.toString());
// Create a ServiceURL object that wraps the service URL and a request pipeline.
serviceURL = new ServiceURL(url, pipeline);
FlintLogger.JOB_LOGGER.debug("createServiceUrl | ServiceUrl structure: "+serviceURL.toURL().toString());
FlintLogger.JOB_LOGGER.info("createServiceUrl | Created service URL");
}catch(Exception e) {
FlintLogger.JOB_LOGGER.error("createServiceUrl | Exception: ",e.getMessage());
}
return serviceURL;
}
onRequest方法:
try {
// Create Service URL
ServiceURL serviceUrl = createServiceUrl(storageAccountName, storageAccountKey, endpointUrl, endpointProtocol);
FlintLogger.JOB_LOGGER.debug("onRequest | serviceUrl "+serviceUrl.toURL());
FlintLogger.JOB_LOGGER.debug("onRequest | serviceUrl Before request"+serviceUrl.toURL());
try {
serviceUrl.listContainersSegment(null, new ListContainersOptions()).blockingGet().body().containerItems().forEach(container -> {
FlintLogger.JOB_LOGGER.debug("onRequest | Blocking get : "+container.name());
});
}catch(Exception e) {
FlintLogger.JOB_LOGGER.error("Error in thread blocking request ", e.getLocalizedMessage());
}