Change content download rest template config. 50/2850/1
authorSerban Jora <sj2381@att.com>
Fri, 14 Sep 2018 18:36:40 +0000 (14:36 -0400)
committerSerban Jora <sj2381@att.com>
Fri, 14 Sep 2018 18:37:53 +0000 (14:37 -0400)
Change-Id: Icde1d94981fb6b572e7336d2f8bea866cf50311d
Issue-ID: ACUMOS-1690
Signed-off-by: Serban Jora <sj2381@att.com>
gateway/src/main/java/org/acumos/federation/gateway/common/AbstractClient.java
gateway/src/main/java/org/acumos/federation/gateway/common/FederationClient.java
gateway/src/main/java/org/acumos/federation/gateway/service/impl/ContentServiceImpl.java

index 2269df0..f03f938 100644 (file)
@@ -25,12 +25,15 @@ import java.net.URI;
 import java.net.URL;
 import java.util.Date;
 import java.util.Map;
+import java.util.Collections;
 
 import org.acumos.cds.transport.RestPageRequest;
 import org.apache.http.client.HttpClient;
 import org.springframework.boot.web.client.RestTemplateBuilder;
+import org.springframework.http.MediaType;
 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
 import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
+import org.springframework.http.converter.ResourceHttpMessageConverter;
 import org.springframework.web.client.RestTemplate;
 import org.springframework.web.util.UriComponentsBuilder;
 
@@ -56,6 +59,7 @@ public abstract class AbstractClient {
         */
        public AbstractClient(String theTarget, HttpClient theClient) {
                setTarget(theTarget);
+               
                this.restTemplate = new RestTemplateBuilder()
                                                                                                        .requestFactory(new HttpComponentsClientHttpRequestFactory(theClient))
                                                                                                        .rootUri(this.baseUrl)
@@ -68,9 +72,12 @@ public abstract class AbstractClient {
                MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();
     messageConverter.setObjectMapper(theMapper); //try to avoid building one every time
 
+               ResourceHttpMessageConverter contentConverter = new ResourceHttpMessageConverter();
+               contentConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_OCTET_STREAM));
+
                this.restTemplate = new RestTemplateBuilder()
                                                                                                        .requestFactory(new HttpComponentsClientHttpRequestFactory(theClient))
-                                                                                                       .messageConverters(messageConverter)
+                                                                                                       .messageConverters(messageConverter, contentConverter)
                                                                                                        .rootUri(this.baseUrl)
                                                                                                        .build();
        
index 2e04542..cab73b0 100644 (file)
@@ -362,7 +362,7 @@ public class FederationClient extends AbstractClient {
                ResponseEntity<Resource> response = null;
                RequestEntity<Void> request = RequestEntity
                                                                                                                                        .get(theUri)
-                                                                                                                                       .accept(MediaType.APPLICATION_OCTET_STREAM)
+                                                                                                                                       .accept(MediaType.ALL)
                                                                                                                                        .build();
                try {
                        response = restTemplate.exchange(request, Resource.class);
index 9ac01a5..6aa461c 100644 (file)
@@ -136,7 +136,7 @@ public class ContentServiceImpl extends AbstractServiceImpl
                else {
                        String[] nameParts = splitName(theArtifact.getName());
                        UploadArtifactInfo info = putNexusContent(
-                               nexusConfig.getGroupId(), nameParts[0], theArtifact.getVersion(), nameParts[1], theResource);
+                               nexusPrefix(theSolutionId, theRevisionId), nameParts[0], theArtifact.getVersion(), nameParts[1], theResource);
                        // update artifact with local repo reference
                        theArtifact.setUri(info.getArtifactMvnPath());
                }
@@ -159,7 +159,7 @@ public class ContentServiceImpl extends AbstractServiceImpl
                                                                                                                                                                                                                                                                                                                                                throws ServiceException {
                String[] nameParts = splitName(theDocument.getName());
                UploadArtifactInfo info = putNexusContent(
-                               String.join(nexusConfig.getNameSeparator(), nexusConfig.getGroupId(), theSolutionId, theRevisionId), nameParts[0], AccessTypeCode.PB.name(), nameParts[1], theResource);
+                       nexusPrefix(theSolutionId, theRevisionId), nameParts[0], AccessTypeCode.PB.name(), nameParts[1], theResource);
                theDocument.setUri(info.getArtifactMvnPath());
        }
 
@@ -196,6 +196,10 @@ public class ContentServiceImpl extends AbstractServiceImpl
                }
        }
 
+       private String nexusPrefix(String theSolutionId, String theRevisionId) {
+               return String.join(nexusConfig.getNameSeparator(), nexusConfig.getGroupId(), theSolutionId, theRevisionId);
+       }
+
        /**
         * Split a file name into its core name and extension parts.
         * @param theName file name to split