Skip to content

Commit

Permalink
Add S2S (#10)
Browse files Browse the repository at this point in the history
DM removed their gateway when they moved to CNP, now services need to
use S2S
  • Loading branch information
timja authored May 31, 2018
1 parent 1570c11 commit 4e551e7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The two main responsibilities are:

Just include the library as your dependency and you will be to use the client class. Health check for DM service is provided as well.

Components provided by this library will get automatically configured in a Spring context if `document_management.api_gateway.url` configuration property is defined and does not equal `false`.
Components provided by this library will get automatically configured in a Spring context if `document_management.url` configuration property is defined and does not equal `false`.

### Building

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'

group 'uk.gov.hmcts.reform'
version '2.0.0'
version '3.0.0'

checkstyle {
maxWarnings = 0
Expand Down Expand Up @@ -106,7 +106,7 @@ publishing {

pom.withXml {
def root = asNode()
root.appendNode('description', 'Client library for communicating with document management gateway')
root.appendNode('description', 'Client library for communicating with document management api')
root.appendNode('name', 'Document management client')
root.appendNode('url', 'https://github.com/hmcts/document-management-client')
root.children().last() + pomConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@FeignClient(name = "document-management-download-gateway-api", url = "${document_management.api_gateway.url}")
@FeignClient(name = "document-management-download-api", url = "${document_management.url}")
public interface DocumentDownloadClientApi {

@RequestMapping(method = RequestMethod.GET, value = "{document_download_uri}")
ResponseEntity<Resource> downloadBinary(@RequestHeader(HttpHeaders.AUTHORIZATION) String authorisation,
@PathVariable("document_download_uri") String documentDownloadUri);
ResponseEntity<Resource> downloadBinary(
@RequestHeader(HttpHeaders.AUTHORIZATION) String authorisation,
@RequestHeader("ServiceAuthorization") String serviceAuth,
@PathVariable("document_download_uri") String documentDownloadUri
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import uk.gov.hmcts.reform.document.healthcheck.DocumentManagementHealthIndicator;

@Configuration
@ConditionalOnProperty(prefix = "document_management", name = "api_gateway.url")
@ConditionalOnProperty(prefix = "document_management", name = "url")
@EnableFeignClients(basePackages = "uk.gov.hmcts.reform.document")
public class DocumentManagementClientAutoConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;

@FeignClient(name = "document-management-metadata-download-gateway-api", url = "${document_management.api_gateway.url}",
@FeignClient(name = "document-management-metadata-download-api", url = "${document_management.url}",
configuration = DocumentMetadataDownloadClientApi.DownloadConfiguration.class)
public interface DocumentMetadataDownloadClientApi {

@RequestMapping(method = RequestMethod.GET, value = "{document_metadata_uri}")
Document getDocumentMetadata(@RequestHeader(HttpHeaders.AUTHORIZATION) String authorisation,
@PathVariable("document_metadata_uri") String documentMetadataUri);
Document getDocumentMetadata(
@RequestHeader(HttpHeaders.AUTHORIZATION) String authorisation,
@RequestHeader("ServiceAuthorization") String serviceAuth,
@PathVariable("document_metadata_uri") String documentMetadataUri
);


@RequestMapping(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@
import java.io.IOException;
import java.util.List;

import static java.util.Objects.requireNonNull;
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;

@Service
public class DocumentUploadClientApi {

private static final String AUTHORIZATION = "Authorization";
private static final String CONTENT_TYPE = "Content-Type";
private static final String CLASSIFICATION = "classification";
private static final String FILES = "files";
private static final String DOCUMENTS_PATH = "/documents";
private static final String SERVICE_AUTHORIZATION = "ServiceAuthorization";
private final String dmUri;
private final RestTemplate restTemplate;
private final ObjectMapper objectMapper;

@Autowired
public DocumentUploadClientApi(
@Value("${document_management.api_gateway.url}") final String dmUri,
@Value("${document_management.url}") final String dmUri,
final RestTemplate restTemplate,
final ObjectMapper objectMapper
) {
Expand All @@ -46,12 +46,15 @@ public DocumentUploadClientApi(
this.objectMapper = objectMapper;
}

public UploadResponse upload(@RequestHeader(HttpHeaders.AUTHORIZATION) String authorisation,
@RequestPart List<MultipartFile> files) {
public UploadResponse upload(
@RequestHeader(HttpHeaders.AUTHORIZATION) String authorisation,
@RequestHeader(SERVICE_AUTHORIZATION) String serviceAuth,
@RequestPart List<MultipartFile> files
) {
try {
MultiValueMap<String, Object> parameters = prepareRequest(files);

HttpHeaders httpHeaders = setHttpHeaders(authorisation);
HttpHeaders httpHeaders = setHttpHeaders(authorisation, serviceAuth);

HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(parameters,
httpHeaders);
Expand All @@ -63,10 +66,11 @@ public UploadResponse upload(@RequestHeader(HttpHeaders.AUTHORIZATION) String au
}
}

private HttpHeaders setHttpHeaders(String authorizationToken) {
private HttpHeaders setHttpHeaders(String authorizationToken, String serviceAuth) {
HttpHeaders headers = new HttpHeaders();
headers.add(AUTHORIZATION, authorizationToken);
headers.set(CONTENT_TYPE, MULTIPART_FORM_DATA_VALUE);
headers.add(HttpHeaders.AUTHORIZATION, authorizationToken);
headers.add(SERVICE_AUTHORIZATION, serviceAuth);
headers.set(HttpHeaders.CONTENT_TYPE, MULTIPART_FORM_DATA_VALUE);
return headers;
}

Expand All @@ -84,6 +88,7 @@ private static HttpEntity<Resource> buildPartFromFile(MultipartFile file) {
}

private static HttpHeaders buildPartHeaders(MultipartFile file) {
requireNonNull(file.getContentType());
final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.valueOf(file.getContentType()));
return headers;
Expand Down

0 comments on commit 4e551e7

Please sign in to comment.