Java Code Examples for org.springframework.cloud.servicebroker.model.binding.GetServiceInstanceBindingResponse

The following examples show how to use org.springframework.cloud.servicebroker.model.binding.GetServiceInstanceBindingResponse. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(GetServiceInstanceBindingRequest request) {
	String serviceInstanceId = request.getServiceInstanceId();
	String bindingId = request.getBindingId();

	//
	// retrieve the details of the specified service binding
	//

	String url = new String(/* retrieved URL */);
	String bindingUsername = new String(/* retrieved user */);
	String bindingPassword = new String(/* retrieved password */);

	GetServiceInstanceBindingResponse response = GetServiceInstanceAppBindingResponse.builder()
			.credentials("username", bindingUsername)
			.credentials("password", bindingPassword)
			.credentials("url", url)
			.build();

	return Mono.just(response);
}
 
Example 2
private void validateGetServiceBindingResponseStatus(GetServiceInstanceBindingResponse response,
		HttpStatus httpStatus) {
	Mono<GetServiceInstanceBindingResponse> responseMono;
	if (response == null) {
		responseMono = Mono.empty();
	}
	else {
		responseMono = Mono.just(response);
	}
	given(bindingService.getServiceInstanceBinding(any(GetServiceInstanceBindingRequest.class)))
			.willReturn(responseMono);

	ResponseEntity<GetServiceInstanceBindingResponse> responseEntity = controller
			.getServiceInstanceBinding(pathVariables, null, null, null, null, null)
			.block();

	assertThat(responseEntity).isNotNull();
	assertThat(responseEntity.getStatusCode()).isEqualTo(httpStatus);
	assertThat(responseEntity.getBody()).isEqualTo(response);
}
 
Example 3
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(GetServiceInstanceBindingRequest request) {
	return Mono.just(request.getBindingId())
			.flatMap(bindingId -> bindingRepository.findById(bindingId)
					.flatMap(Mono::justOrEmpty)
					.switchIfEmpty(Mono.error(new ServiceInstanceBindingDoesNotExistException(bindingId)))
					.flatMap(serviceBinding -> Mono.just(GetServiceInstanceAppBindingResponse.builder()
							.parameters(serviceBinding.getParameters())
							.credentials(serviceBinding.getCredentials())
							.build())));
}
 
Example 4
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(GetServiceInstanceBindingRequest request) {
	if (IN_PROGRESS_SERVICE_INSTANCE_ID.equals(request.getServiceInstanceId())) {
		return Mono.error(new ServiceBrokerOperationInProgressException("task_10"));
	}
	return Mono.just(GetServiceInstanceAppBindingResponse.builder()
			.build());
}
 
Example 5
/**
 * REST controller for getting a service instance binding
 *
 * @param pathVariables the path variables
 * @param serviceInstanceId the service instance ID
 * @param bindingId the service binding ID
 * @param apiInfoLocation location of the API info endpoint of the platform instance
 * @param originatingIdentityString identity of the user that initiated the request from the platform
 * @param requestIdentity identity of the request sent from the platform
 * @return the response
 */
@GetMapping({PLATFORM_PATH_MAPPING, PATH_MAPPING})
public Mono<ResponseEntity<GetServiceInstanceBindingResponse>> getServiceInstanceBinding(
		@PathVariable Map<String, String> pathVariables,
		@PathVariable(ServiceBrokerRequest.INSTANCE_ID_PATH_VARIABLE) String serviceInstanceId,
		@PathVariable(ServiceBrokerRequest.BINDING_ID_PATH_VARIABLE) String bindingId,
		@RequestHeader(value = ServiceBrokerRequest.API_INFO_LOCATION_HEADER, required = false) String apiInfoLocation,
		@RequestHeader(value = ServiceBrokerRequest.ORIGINATING_IDENTITY_HEADER, required = false) String originatingIdentityString,
		@RequestHeader(value = ServiceBrokerRequest.REQUEST_IDENTITY_HEADER, required = false) String requestIdentity) {
	return Mono.just(GetServiceInstanceBindingRequest.builder()
			.serviceInstanceId(serviceInstanceId)
			.bindingId(bindingId)
			.platformInstanceId(pathVariables.get(ServiceBrokerRequest.PLATFORM_INSTANCE_ID_VARIABLE))
			.apiInfoLocation(apiInfoLocation)
			.originatingIdentity(parseOriginatingIdentity(originatingIdentityString))
			.requestIdentity(requestIdentity)
			.build())
			.flatMap(req -> service.getServiceInstanceBinding(req)
					.doOnRequest(v -> {
						LOG.info("Getting a service instance binding");
						LOG.debug(DEBUG_REQUEST, req);
					})
					.doOnSuccess(response -> {
						LOG.info("Getting a service instance binding succeeded");
						LOG.debug("bindingId={}", bindingId);
					})
					.doOnError(e -> LOG.error("Error getting service instance binding. error=" +
							e.getMessage(), e)))
			.map(response -> new ResponseEntity<>(response, HttpStatus.OK))
			.switchIfEmpty(Mono.just(new ResponseEntity<>(HttpStatus.OK)))
			.onErrorResume(e -> {
				if (e instanceof ServiceInstanceBindingDoesNotExistException ||
						e instanceof ServiceInstanceDoesNotExistException) {
					return Mono.just(new ResponseEntity<>(HttpStatus.NOT_FOUND));
				}
				else {
					return Mono.error(e);
				}
			});
}
 
Example 6
@Test
void getServiceBindingWithMissingBindingGivesExpectedStatus() {
	given(bindingService.getServiceInstanceBinding(any(GetServiceInstanceBindingRequest.class)))
			.willThrow(new ServiceInstanceBindingDoesNotExistException("binding-id"));

	ResponseEntity<GetServiceInstanceBindingResponse> responseEntity = controller
			.getServiceInstanceBinding(pathVariables, null, null, null, null, null)
			.block();

	assertThat(responseEntity).isNotNull();
	assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
 
Example 7
@Test
void getServiceBindingWithMissingServiceInstanceGivesExpectedStatus() {
	given(bindingService.getServiceInstanceBinding(any(GetServiceInstanceBindingRequest.class)))
			.willThrow(new ServiceInstanceDoesNotExistException("nonexistent-service-id"));

	ResponseEntity<GetServiceInstanceBindingResponse> responseEntity = controller
			.getServiceInstanceBinding(pathVariables, "nonexistent-service-id", "nonexistent-binding-id", null,
					null, null)
			.block();

	assertThat(responseEntity).isNotNull();
	assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
 
Example 8
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(
		GetServiceInstanceBindingRequest request) {
	if (request.getBindingId() == null) {
		return Mono.error(new ServiceInstanceDoesNotExistException("service-instance-id"));
	}
	return Mono.just(GetServiceInstanceAppBindingResponse.builder().build());
}
 
Example 9
Source Project: tutorials   Source File: MailServiceInstanceBindingService.java    License: MIT License 5 votes vote down vote up
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(GetServiceInstanceBindingRequest request) {
    return mailService.getServiceBinding(request.getServiceInstanceId(), request.getBindingId())
        .switchIfEmpty(Mono.error(new ServiceInstanceBindingDoesNotExistException(request.getBindingId())))
        .flatMap(mailServiceBinding -> Mono.just(GetServiceInstanceAppBindingResponse.builder()
            .credentials(mailServiceBinding.getCredentials())
            .build()));
}
 
Example 10
protected void setupServiceInstanceBindingService(GetServiceInstanceBindingResponse getResponse) {
	given(serviceInstanceBindingService.getServiceInstanceBinding(any(GetServiceInstanceBindingRequest.class)))
			.willReturn(Mono.just(getResponse));
}
 
Example 11
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(GetServiceInstanceBindingRequest request) {
	return service.getServiceInstanceBinding(request);
}
 
Example 12
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(
		GetServiceInstanceBindingRequest request) {
	assertThat(request).isEqualTo(expectedRequest);
	return Mono.empty();
}
 
Example 13
@Test
void getServiceBindingWithResponseGivesExpectedStatus2() {
	GetServiceInstanceBindingResponse response = GetServiceInstanceAppBindingResponse.builder()
			.build();
	validateGetServiceBindingResponseStatus(response, HttpStatus.OK);
}
 
Example 14
/**
 * Get the details of a binding to a service instance.
 *
 * @param request containing the details of the request
 * @return a {@link GetServiceInstanceBindingResponse} on successful processing of the request
 * @throws ServiceInstanceDoesNotExistException if a service instance with the given ID is not known to the
 * 		broker
 * @throws ServiceInstanceBindingDoesNotExistException if a binding with the given ID is not known to the broker
 * @throws ServiceBrokerOperationInProgressException if a an operation is in progress for the service binding
 */
default Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(
		GetServiceInstanceBindingRequest request) {
	return Mono.error(new UnsupportedOperationException(
			"This service broker does not support retrieving service bindings. " +
					"The service broker should set 'bindings_retrievable:false' in the service catalog, " +
					"or provide an implementation of the fetch binding API."));
}