import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.BodyInserters;
+import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientRequestException;
import org.springframework.web.reactive.function.client.WebClientResponseException;
.get()
.uri(urlTemplateParameters.urlTemplate(), urlTemplateParameters.urlVariables())
.headers(httpHeaders -> configureHttpHeaders(httpHeaders, NO_AUTHORIZATION))
- .retrieve()
- .toEntity(Object.class)
+ .exchangeToMono(this::createIdenticalResponseForClient)
.block();
}
.uri(urlTemplateParameters.urlTemplate(), urlTemplateParameters.urlVariables())
.headers(httpHeaders -> configureHttpHeaders(httpHeaders, NO_AUTHORIZATION))
.bodyValue(body)
- .retrieve()
- .toEntity(Object.class)
+ .exchangeToMono(this::createIdenticalResponseForClient)
.block();
}
.headers(httpHeaders -> configureHttpHeaders(httpHeaders, NO_AUTHORIZATION))
.contentType(MediaType.parseMediaType(contentType))
.bodyValue(body)
- .retrieve()
- .toEntity(Object.class)
+ .exchangeToMono(this::createIdenticalResponseForClient)
.block();
}
}
/**
- * Sends a synchronous (blocking) DELETE operation to the DMI with a JSON body without error mapping.
+ * Sends a synchronous (blocking) DELETE operation to the DMI without error mapping.
*
* @param requiredDmiService Determines if the required service is for a data or model operation.
* @param urlTemplateParameters The DMI resource URL template with variables.
- * @return ResponseEntity from the DMI Plugin
- * @throws DmiClientRequestException If there is an error during the DMI request.
+ * @return ResponseEntity containing the response from the DMI.
*
*/
public ResponseEntity<Object> synchronousDeleteOperation(final RequiredDmiService requiredDmiService,
.delete()
.uri(urlTemplateParameters.urlTemplate(), urlTemplateParameters.urlVariables())
.headers(httpHeaders -> configureHttpHeaders(httpHeaders, NO_AUTHORIZATION))
- .retrieve()
- .toEntity(Object.class)
+ .exchangeToMono(this::createIdenticalResponseForClient)
.block();
}
UNKNOWN_ERROR);
}
+ private Mono<ResponseEntity<Object>> createIdenticalResponseForClient(final ClientResponse clientResponse) {
+ final HttpStatus status = (HttpStatus) clientResponse.statusCode();
+ return clientResponse.bodyToMono(String.class)
+ .defaultIfEmpty("")
+ .map(body -> {
+ return ResponseEntity
+ .status(status)
+ .headers(clientResponse.headers().asHttpHeaders())
+ .body(body);
+ });
+ }
+
}
given: 'a registered cm handle'
dmiDispatcher1.moduleNamesPerCmHandleId['ch-1'] = ['M1', 'M2']
registerCmHandle(DMI1_URL, 'ch-1', NO_MODULE_SET_TAG, '/A=1/B=2/C=3')
- expect: 'not implemented response on GET endpoint'
- mvc.perform(get("/ProvMnS/v1/A=1/B=2/C=3"))
- .andExpect(status().is2xxSuccessful())
+ expect: 'an OK response on GET endpoint'
+ mvc.perform(get("/ProvMnS/v1/A=1/B=2/C=3")).andExpect(status().isOk())
cleanup: 'deregister CM handles'
deregisterCmHandle(DMI1_URL, 'ch-1')
}
dmiDispatcher1.moduleNamesPerCmHandleId['ch-1'] = ['M1', 'M2']
registerCmHandle(DMI1_URL, 'ch-1', NO_MODULE_SET_TAG, '/A=1/B=2/C=3')
def jsonBody = jsonObjectMapper.asJsonString(new ResourceOneOf('test'))
- expect: 'not implemented response on PUT endpoint'
+ expect: 'an OK response on PUT endpoint'
mvc.perform(put("/ProvMnS/v1/A=1/B=2/C=3")
.contentType(MediaType.APPLICATION_JSON)
.content(jsonBody))
dmiDispatcher1.moduleNamesPerCmHandleId['ch-1'] = ['M1', 'M2']
registerCmHandle(DMI1_URL, 'ch-1', NO_MODULE_SET_TAG, '/A=1/B=2/C=3')
def jsonBody = jsonObjectMapper.asJsonString([new PatchItem(op: 'REMOVE', path: 'someUriLdnFirstPart')])
- expect: 'not implemented response on PATCH endpoint'
+ expect: 'an OK response on PATCH endpoint'
mvc.perform(patch("/ProvMnS/v1/A=1/B=2/C=3")
.contentType(new MediaType('application', 'json-patch+json'))
.content(jsonBody))