Description
Product images can't be uploaded on admin panel while trying to add a product using the "Ürün Ekle" flow.
The front end app receives a 500 status code from the back end app which throws a NullPointerException
at retrieving Google credentials through the uploadFile
method of the FirebaseFileServiceImpl
class. Inside this method, getResourceAsStream
method call is passed an argument as "zuri-petshop-firebase.json" (non-existent) instead of "firebase.json" (existent).
@Service
public class FirebaseFileServiceImpl implements FirebaseFileService {
// ...
@Override
public String uploadFile(InputStream is, String contentType, String path, String fileName) throws IOException {
InputStream serviceAccount = getClass()
.getClassLoader()
.getResourceAsStream("zuri-petshop-firebase.json"); // <= Correct filename is "firebase.json"
Storage storage = StorageOptions.newBuilder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount)) // <= Throws NullPointerException
.setProjectId(PETSHOP_FIREBASE_PROJECT_ID).build().getService();
// ...
}
}
Steps to Reproduce
- Login to admin panel.
- Add a category if none exists.
- Upload an image file for a product using the "Ürün Ekle" flow .
Expected Result
The product image file is uploaded successfully to Firebase.
Actual Result
Upload fails. Admin panel receives a 500 status code from the back end app and the back end app throws a NPE.
Error Message
2021-09-09 03:47:24.233 ERROR 6832 --- [nio-8081-exec-4] c.t.p.v.h.ApplicationExceptionHandler : Exception : class java.lang.NullPointerException: null
java.lang.NullPointerException: null
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:892) ~[guava-30.1.1-android.jar:na]
at com.google.api.client.util.Preconditions.checkNotNull(Preconditions.java:125) ~[google-http-client-1.39.2.jar:1.39.2]
at com.google.auth.oauth2.GoogleCredentials.fromStream(GoogleCredentials.java:151) ~[google-auth-library-oauth2-http-0.26.0.jar:na]
at com.google.auth.oauth2.GoogleCredentials.fromStream(GoogleCredentials.java:134) ~[google-auth-library-oauth2-http-0.26.0.jar:na]
at com.turkninja.petshop.file.impl.FirebaseFileServiceImpl.uploadFile(FirebaseFileServiceImpl.java:32) ~[classes/:na]
at com.turkninja.petshop.v1.FileResource.uploadFile(FileResource.java:30) ~[classes/:na]
// ... Rest of the error message is omitted
bug