-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/lmco/spectrum/systemnavigation3d/controller/ResourceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.lmco.spectrum.systemnavigation3d.controller; | ||
|
||
import com.lmco.spectrum.systemnavigation3d.service.ResourceService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
@Controller | ||
@RequestMapping("api/resources") | ||
public class ResourceController { | ||
|
||
@Autowired | ||
ResourceService resourceService; | ||
|
||
@RequestMapping(value = "/pdf/{id}", method = RequestMethod.GET) | ||
public ResponseEntity<?> testEndpoint(@PathVariable("id") Long id){ | ||
// TODO call ResourceService | ||
String x = resourceService.getFileTest(); | ||
if(x == null) { | ||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
return ResponseEntity.ok(x); | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/lmco/spectrum/systemnavigation3d/service/AmazonClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.lmco.spectrum.systemnavigation3d.service; | ||
|
||
import com.amazonaws.auth.profile.ProfileCredentialsProvider; | ||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.AmazonS3ClientBuilder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
@Service | ||
public class AmazonClient { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(AmazonClient.class); | ||
|
||
private AmazonS3 amazonS3; | ||
|
||
@Value("${app.s3.credentialsProfile}") | ||
private String s3CredentialsProfile; | ||
@Value("${app.s3.bucket}") | ||
private String s3Bucket; | ||
@Value("${app.s3.region}") | ||
private String s3Region; | ||
|
||
@PostConstruct | ||
private void initializeAmazon() { | ||
log.debug("Connecting to Amazon S3 using credentials profile {} on region {}.", s3CredentialsProfile, s3Region); | ||
log.debug("Using bucket {}.", s3Bucket); | ||
this.amazonS3 = AmazonS3ClientBuilder.standard() | ||
.withCredentials(new ProfileCredentialsProvider(s3CredentialsProfile)) | ||
.withRegion(s3Region) | ||
.build(); | ||
} | ||
|
||
public AmazonS3 getAmazonS3Connection() { | ||
return this.amazonS3; | ||
} | ||
|
||
public String getS3Bucket() { | ||
return this.s3Bucket; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/lmco/spectrum/systemnavigation3d/service/ResourceService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.lmco.spectrum.systemnavigation3d.service; | ||
|
||
import com.amazonaws.services.s3.AmazonS3; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.lang.Nullable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.util.StreamUtils; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
@Service | ||
public class ResourceService { | ||
|
||
@Autowired | ||
AmazonClient amazonClient; | ||
|
||
@Nullable | ||
public String getFileTest() { | ||
AmazonS3 amazonS3 = amazonClient.getAmazonS3Connection(); | ||
try (InputStream is = amazonS3.getObject(amazonClient.getS3Bucket(), "test.txt").getObjectContent()) { | ||
return StreamUtils.copyToString(is, StandardCharsets.UTF_8); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
server.servlet.contextPath=/3dsysnavbackend | ||
|
||
app.s3.credentialsProfile=s3 | ||
app.s3.bucket=3dsysnavstorage | ||
app.s3.region=us-west-2 |