本文整理汇总了Java中com.vmware.xenon.common.Operation.setBody方法的典型用法代码示例。如果您正苦于以下问题:Java Operation.setBody方法的具体用法?Java Operation.setBody怎么用?Java Operation.setBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vmware.xenon.common.Operation
的用法示例。
在下文中一共展示了Operation.setBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleGet
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@RouteDocumentation(description = "@CAR_ENGINE",
path = "?engine",
produces = { "application/json" },
responses = {
@ApiResponse(statusCode = Operation.STATUS_CODE_OK, description = "OK", response = EngineInfo.class)
})
@RouteDocumentation(description = "@CAR",
produces = { "application/json" },
responses = {
@ApiResponse(statusCode = Operation.STATUS_CODE_OK, description = "OK", response = Car.class),
@ApiResponse(statusCode = Operation.STATUS_CODE_NOT_FOUND, description = "Not Found"),
})
@Override
public void handleGet(Operation get) {
Map<String,String> queryParams = UriUtils.parseUriQueryParams(get.getUri());
boolean engineInfo = Boolean.parseBoolean(queryParams.get("engine"));
if (engineInfo) {
Car car = this.getState(get);
get.setBody(car.engineInfo);
get.complete();
} else {
super.handleGet(get);
}
}
示例2: handleIdempotentPut
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
public static void handleIdempotentPut(StatefulService s, Operation put) {
if (put.hasPragmaDirective(Operation.PRAGMA_DIRECTIVE_POST_TO_PUT)) {
// converted PUT due to IDEMPOTENT_POST option
s.logFine(() -> String.format("Task %s has already started. Ignoring converted PUT.",
put.getUri()));
put.setBody(s.getState(put));
put.addPragmaDirective(Operation.PRAGMA_DIRECTIVE_STATE_NOT_MODIFIED);
put.setStatusCode(Operation.STATUS_CODE_OK);
put.complete();
return;
}
// normal PUT is not supported
put.fail(Operation.STATUS_CODE_BAD_METHOD);
}
示例3: handlePut
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handlePut(Operation put) {
if (!checkForBody(put)) {
return;
}
try {
SslTrustCertificateState body = put.getBody(SslTrustCertificateState.class);
SslTrustCertificateState state = getState(put);
// these properties can't be modified once set:
body.subscriptionLink = state.subscriptionLink;
boolean validated = validate(put, () -> validateStateOnStart(body));
if (!validated) {
return;
}
this.setState(put, body);
put.setBody(body);
put.complete();
} catch (Throwable t) {
put.fail(t);
}
}
示例4: handlePatch
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handlePatch(Operation patch) {
if (!checkForBody(patch)) {
return;
}
SslTrustCertificateState body = patch.getBody(SslTrustCertificateState.class);
SslTrustCertificateState state = getState(patch);
String stateCert = state.certificate;
state.certificate = body.certificate != null ? body.certificate : state.certificate;
boolean validated = validate(patch, () -> validateStateOnStart(state));
if (!validated) {
return;
}
patch.setBody(state);
if (isModified(stateCert, body.certificate)) {
patch.complete();
} else {
patch.complete();
}
}
示例5: handleGet
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handleGet(Operation get) {
Map<String, String> params = UriUtils.parseUriQueryParams(get.getUri());
String deviceType = params.get(DEVICE_TYPE);
if (deviceType == null || deviceType.isEmpty()) {
get.fail(new IllegalArgumentException("No deviceType provided."));
return;
}
if (!deviceType.equals(AWSConstants.AWSStorageType.EBS.name().toLowerCase())) {
get.fail(new IllegalArgumentException("Unsupported device Type"));
return;
}
VolumeTypeList volumeTypeList = new VolumeTypeList();
for (VolumeType volumeType : VolumeType.values()) {
volumeTypeList.volumeTypes.add(volumeType.toString());
}
get.setBody(volumeTypeList);
get.complete();
}
示例6: testGetAvailableRegions
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Test
public void testGetAvailableRegions() {
URI uri = UriUtils.buildUri(
ServiceHost.LOCAL_HOST,
host.getPort(),
UriPaths.AdapterTypePath.REGION_ENUMERATION_ADAPTER.adapterLink(
PhotonModelConstants.EndpointType.aws.toString().toLowerCase()), null);
Operation post = Operation.createPost(uri);
post.setBody(new AuthCredentialsServiceState());
Operation operation = host.getTestRequestSender().sendAndWait(post);
RegionEnumerationResponse result = operation.getBody(RegionEnumerationResponse.class);
assertEquals(Regions.values().length, result.regions.size());
}
示例7: testGetAvailableRegions
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Test
public void testGetAvailableRegions() throws Throwable {
Assume.assumeFalse(isMock());
startAdditionalServices();
this.host.waitForServiceAvailable(VSphereUriPaths.VSPHERE_REGION_ENUMERATION_ADAPTER_SERVICE);
URI uri = UriUtils.buildUri(
ServiceHost.LOCAL_HOST,
host.getPort(),
UriPaths.AdapterTypePath.REGION_ENUMERATION_ADAPTER.adapterLink(
PhotonModelConstants.EndpointType.vsphere.toString().toLowerCase()), null);
Operation post = Operation.createPost(uri);
post.setBody(createEndpoint((a) -> { }, (b) -> { }));
Operation operation = host.getTestRequestSender().sendAndWait(post);
RegionEnumerationResponse result = operation.getBody(RegionEnumerationResponse.class);
assertTrue(!result.regions.isEmpty());
}
示例8: testGetAvailableRegions
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Test
public void testGetAvailableRegions() {
Assume.assumeFalse(this.isMock);
URI uri = UriUtils.buildUri(
ServiceHost.LOCAL_HOST,
host.getPort(),
UriPaths.AdapterTypePath.REGION_ENUMERATION_ADAPTER.adapterLink(
PhotonModelConstants.EndpointType.azure.toString().toLowerCase()), null);
Operation post = Operation.createPost(uri);
post.setBody(endpointState);
Operation operation = host.getTestRequestSender().sendAndWait(post);
RegionEnumerationResponse result = operation.getBody(RegionEnumerationResponse.class);
assertTrue(!result.regions.isEmpty());
}
示例9: handlePost
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
/**
* Override the handlePost method to set the documentSelfLink. We don't want to have multiple
* certificate states with the same certificate, so we build the documentSelfLink ourselves
*
* @param op
*/
@Override
public void handlePost(Operation op) {
if (op.isSynchronize()) {
op.complete();
return;
}
if (op.hasBody()) {
SslTrustCertificateState body = (SslTrustCertificateState) op.getBody(this.stateType);
if (body == null) {
op.fail(new IllegalArgumentException("structured body is required"));
return;
}
if (body.documentSourceLink != null) {
op.fail(new IllegalArgumentException("clone request not supported"));
return;
}
body.documentSelfLink = generateSelfLink(body);
op.setBody(body);
op.complete();
} else {
op.fail(new IllegalArgumentException("body is required"));
}
}
示例10: handleStart
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handleStart(Operation start) {
State state = validateStartState(start);
if (state == null) {
return;
}
start.setBody(state);
start.complete();
}
示例11: handlePatch
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handlePatch(Operation patch) {
State body = validateUpdateState(patch);
if (body == null) {
return;
}
State currentState = getState(patch);
updateState(currentState, body);
patch.setBody(currentState);
patch.complete();
}
示例12: handleStart
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handleStart(Operation start) {
State state = validateStartState(start);
if (state == null) {
return;
}
start.setBody(state);
start.complete();
}
示例13: handleValidationException
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
private static void handleValidationException(Operation op, Throwable e) {
Throwable ex = e;
if (!(e instanceof IllegalArgumentException)
&& !(e instanceof LocalizableValidationException)) {
ex = new IllegalArgumentException(e.getMessage());
}
op.setStatusCode(Operation.STATUS_CODE_BAD_REQUEST);
// with body = null fail(ex) will populate it with the proper ServiceErrorResponse content
op.setBody(null);
op.fail(ex);
}
示例14: handlePatch
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handlePatch(Operation patch) {
StatsAggregationTaskState currentState = getState(patch);
StatsAggregationTaskState patchState = getTaskBody(patch);
validateTransition(patch, currentState, patchState);
updateState(currentState, patchState);
patch.setBody(currentState);
patch.complete();
switch (currentState.taskInfo.stage) {
case STARTED:
// TODO: https://jira-hzn.eng.vmware.com/browse/VSYM-3111
logFine(() -> String.format("Started stats aggregation. Stage [%s], PageLink [%s]",
currentState.taskSubStage, currentState.queryResultLink));
handleStagePatch(currentState);
break;
case FINISHED:
case FAILED:
case CANCELLED:
if (TaskState.isFailed(currentState.taskInfo) ||
TaskState.isCancelled(currentState.taskInfo)) {
if (currentState.failureMessage != null) {
logWarning(currentState.failureMessage);
}
}
logInfo(() -> "Finished stats aggregation");
sendRequest(Operation
.createDelete(getUri()));
break;
default:
break;
}
}
示例15: handleGet
import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handleGet(Operation get) {
if (get.getContentType().equalsIgnoreCase(MEDIA_TYPE_APPLICATION_OCTET_STREAM)) {
ContentState state = this.getState(get);
get.setBody(state.binaryData);
get.complete();
} else {
super.handleGet(get);
}
}