Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.56 KB | None | 0 0
  1. application - Shutting down connection pool.
  2.  
  3. [error] 32#32: *177005 upstream prematurely closed connection while reading response header from upstream, client: 130.211.0.233, server: , request: "POST /openptp/b2731a6ff0d3470c9d98a67bebae2c3e HTTP/1.1", upstream: "http://172.17.0.1:8080/openptp/b2731a6ff0d3470c9d98a67bebae2c3e", host: "(my GAE url)", referrer: "https://(my GAE url)/openptp/b2731a6ff0d3470c9d98a67bebae2c3e"
  4.  
  5. application - Creating Pool for datasource 'default'
  6. p.a.d.DefaultDBApi - Database [default] connected at jdbc:mysql://google/ptp?cloudSqlInstance=hcpf-ptp-test:us-central1:ptp-test-mysql&socketFactory=com.google.cloud.sql.mysql.SocketFactory&characterEncoding=UTF-8&useSSL=true
  7. play.api.Play - Application started (Prod)
  8. p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:8080
  9.  
  10. try {
  11. Logger.info("AdultPTPController: Starting File Upload...");
  12. File file = null;
  13. File fileFinal = null;
  14. String fileName = "";
  15. String fileContentType = "";
  16. String filePath = "";
  17. String fileID = "";
  18. // String folderIDToFind =
  19. // adultDemo.getNew_Provider_Id().toString();
  20. String folderIDToFind = adultDemo.getLegacy_Provider_Id().toString();
  21. Http.MultipartFormData<File> formData = request().body().asMultipartFormData();
  22. if (formData != null) {
  23. Http.MultipartFormData.FilePart<File> filePart = formData.getFile("fileAttach");
  24. if (filePart != null) {
  25. fileName = filePart.getFilename().trim();
  26. // Is there a file?
  27. if (!fileName.equals("") && fileName != null) {
  28. Logger.info("AdultPTPController: File Name = " + fileName);
  29. fileContentType = filePart.getContentType();
  30. file = filePart.getFile();
  31. long size = Files.size(file.toPath());
  32.  
  33. // Now we have the file, let's make a copy so we have
  34. // the correct file info before we send to Google
  35. // Drive...
  36. String origPath = file.getCanonicalPath();
  37. String destPath = origPath.replace(file.getName(), "");
  38. Logger.info("AdultPTPController: origPath = " + origPath);
  39. Logger.info("AdultPTPController: destPath = " + destPath);
  40. filePath = destPath + fileName;
  41. Logger.info("AdultPTPController: filePath = " + filePath);
  42. Path FROM = Paths.get(origPath);
  43. Path TO = Paths.get(filePath);
  44. // overwrite existing file, if exists
  45. CopyOption[] options = new CopyOption[] { StandardCopyOption.REPLACE_EXISTING,
  46. StandardCopyOption.COPY_ATTRIBUTES };
  47. try {
  48. Files.copy(FROM, TO, options);
  49. } catch (final DirectoryNotEmptyException dnee) {
  50. dnee.printStackTrace();
  51. }
  52.  
  53. // Set the file we are uploading...
  54. fileFinal = new File(filePath);
  55. Logger.info("AdultPTPController: File Final = " + fileFinal);
  56.  
  57. // Delete the temporary file...
  58. Files.deleteIfExists(file.toPath());
  59. Logger.info("AdultPTPController: Deleted temporary file...");
  60.  
  61. // Send the file to Google Drive...
  62. if (fileFinal != null) {
  63. // Upload the file and return the file ID...
  64. Logger.info("AdultPTPController: File is not null, sending to uploadFile...");
  65. fileID = GoogleDrive.uploadFile(fileFinal, folderIDToFind);
  66. Logger.info("AdultPTPController: File ID = " + fileID);
  67. if (!fileID.equals("")) {
  68. // Success...
  69. // Create a file record...
  70. FileUpload fileUpload = new FileUpload();
  71. // Create a unique ID...
  72. fileUpload.setFileKey(fileUpload.createFileKey());
  73. // Set the needed fields...
  74. fileUpload.setRecordID(adultDemo.getLegacy_Provider_Id().toString());
  75. fileUpload.setRecordKey(adultPTP.getPtpkey());
  76. fileUpload.setCreatedBy(user.getFullname());
  77. fileUpload.setCreatedByEmail(user.getEmail());
  78. fileUpload.setCreatedByKey(user.getUserkey());
  79. fileUpload.setCreatedDate(GlobalUtilities.getCurrentLocalDateTime());
  80. fileUpload.setDateCreatedDisplay(
  81. GlobalUtilities.getStringDate(fileUpload.getCreatedDate()));
  82. // Set the file info...
  83. fileUpload.setFileID(fileID);
  84. fileUpload.setFileName(fileName);
  85. fileUpload.setFilePath(filePath);
  86. String folderID = Configuration.root().getString("google.drive.folderid");
  87. fileUpload.setFolderID(folderID);
  88. // Set the URL...
  89. String urlString = Configuration.root().getString("server.hostname");
  90. String fullURL = urlString + "/downloadfile?ptpKey=" + adultPTP.getPtpkey() + "&fileID="
  91. + fileID;
  92. fileUpload.setFileURL(fullURL);
  93. fileUpload.save();
  94. }
  95. }
  96. }
  97. }
  98. }
  99. } catch (Exception e) {
  100. e.printStackTrace();
  101. }
  102.  
  103. fileID = GoogleDrive.uploadFile(fileFinal, folderIDToFind);
  104.  
  105. public static String uploadFile(java.io.File file, String folderIDToFind) throws IOException {
  106. String fileID = "";
  107. String fileName = "";
  108. try {
  109. Logger.info("GoogleDrive: uploadFile: Starting File Upload...");
  110. // Build a new authorized API client service.
  111. Drive service = getDriveService();
  112. Logger.info("GoogleDrive: uploadFile: Completed Drive Service...");
  113.  
  114. // Set the folder...
  115. String folderID = Configuration.root().getString("google.drive.folderid");
  116. Logger.info("GoogleDrive: uploadFile: Folder ID = " + folderID);
  117.  
  118. String folderIDToUse = getSubfolderID(service, folderID, folderIDToFind);
  119.  
  120. String fullFilePath = file.getAbsolutePath();
  121. Logger.info("GoogleDrive: uploadFile: Full File Path: " + fullFilePath);
  122. File fileMetadata = new File();
  123.  
  124. // Let's see what slashes exist to get the correct file name...
  125. if (fullFilePath.contains("/")) {
  126. fileName = StringControl.rightBack(fullFilePath, "/");
  127. } else {
  128. fileName = StringControl.rightBack(fullFilePath, "\");
  129. }
  130. String fileContentType = getContentType(fileName);
  131. Logger.info("GoogleDrive: uploadFile: File Content Type: " + fileContentType);
  132. fileMetadata.setName(fileName);
  133. Logger.info("GoogleDrive: uploadFile: File Name = " + fileName);
  134.  
  135. Logger.info("GoogleDrive: uploadFile: Setting the folder...");
  136. fileMetadata.setParents(Collections.singletonList(folderIDToUse));
  137. Logger.info("GoogleDrive: uploadFile: Folder set...");
  138.  
  139. // Team Drive settings...
  140. fileMetadata.set("supportsTeamDrives", true);
  141.  
  142. java.io.File filePath = new java.io.File(fullFilePath);
  143.  
  144. FileContent mediaContent = new FileContent(fileContentType, filePath);
  145.  
  146. File fileToUpload = service.files().create(fileMetadata, mediaContent).setSupportsTeamDrives(true)
  147. .setFields("id, parents").execute();
  148.  
  149. fileID = fileToUpload.getId();
  150. Logger.info("GoogleDrive: uploadFile: File ID: " + fileID);
  151. } catch (Exception ex) {
  152. System.out.println(ex.toString());
  153. ex.printStackTrace();
  154. }
  155. Logger.info("GoogleDrive: uploadFile: Ending File Upload...");
  156. return fileID;
  157. }
  158.  
  159. application - AdultPTPController: Starting File Upload...
  160. application - AdultPTPController: File Name = icon_Add_User2.png
  161. application - AdultPTPController: origPath = /tmp/playtemp3821505761099468678/multipartBody536561590473173911asTemporaryFile
  162. application - AdultPTPController: destPath = /tmp/playtemp3821505761099468678/
  163. application - AdultPTPController: filePath = /tmp/playtemp3821505761099468678/icon_Add_User2.png
  164. application - AdultPTPController: File Final = /tmp/playtemp3821505761099468678/icon_Add_User2.png
  165. application - AdultPTPController: Deleted temporary file...
  166. application - AdultPTPController: File is not null, sending to uploadFile...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement