#mihaild_unexpected

1 messages ยท Page 1 of 1 (latest)

plain stoneBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1219562313791701022

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

next latchBOT
royal osprey
#

Can you share the backtrace log?

cerulean sphinx
#

Sure, sec

royal osprey
#

I don't see any Stripe classes in the backtrace, so I don't see a direct connection between this error and Stripe Java SDK.

cerulean sphinx
#

Yes you are right but this exception is happening because Invoice.list() is returning null, only when executed from an builded native image

This is code for getInvoices() nothing special that may cause this issue

                                         final String startingAfter,
                                         final String endingBefore,
                                         final Long limit) {

        log.infof("Request invoices from stripe for customer = {} with limit = {}, startingBefore = {}, endingBefore = {}",
                customer, limit, startingAfter, endingBefore);

        final InvoiceListParams params = InvoiceListParams.builder()
                .setLimit(limit)
                .setCustomer(customer)
                .setStartingAfter(startingAfter)
                .setEndingBefore(endingBefore)
                .build();

        try {
            return Invoice.list(params);
        } catch (StripeException e) {
            throw new WebApplicationException("Error when requesting data from Stripe for customer = %s".formatted(customer), e);
        }
    }```
royal osprey
#

Which line is line 63?

cerulean sphinx
#

Is failing on controller layer on line 63 that is operating on aboves getInvoice(...) results

#

basicaly on invoices.getData()

royal osprey
#

Is this stripeInvoiceService of type com.stripe.service.InvoiceService ?

cerulean sphinx
#

stripeInvoiceService on line 61 is basically a wrapper around one that you mentioned

plain stoneBOT
cerulean sphinx
astral pendant
#

hi! hmm I have no idea what Quarkus or native images are. I'd suggest just opening an issue on the stripe-java Github if you have an account and are comfortable with that! Otherwise we'll file a ticket internally.

cerulean sphinx
#

Yes sure will do it , will past it here when done

cerulean sphinx
river rune
cerulean sphinx
#

I already did this changes

#

before I faced

#

java.lang.RuntimeException: Unable to invoke no-args constructor for class com.stripe.model.Event. Registering an InstanceCreator with Gson for this type may fix this problem.

#

After creating serialization-config.json as is stated in stripe-java-graalvm NPE starts to happen

river rune
#

Did you try to use the configu files from the repository I shared with you ?

cerulean sphinx
#

yes

#

after that conig NPE issue starts happening

river rune
#

You are facing the same issue...

cerulean sphinx
#

no

river rune
cerulean sphinx
#

I followed steps described there
"Copy the whole directory native-image in META-INF to your own META-INF directory."
This solved
java.lang.RuntimeException: Unable to invoke no-args constructor for class com.stripe.model.Event. Registering an InstanceCreator with Gson for this type may fix this problem.
But instead Stripe Invoice.list() is returning alwys null

cerulean sphinx
#

yes

river rune
#

And what is the issue you were facing ?

cerulean sphinx
#

NPE for stripe calls results for example Invoice.lis()

river rune
#

Ok let me do a quick tests...

#

Can you share your pom.xml?

cerulean sphinx
#

please

#

I replaced company name with x for obvious reasons, is an multi module project so I am sharing base pom and one for rest taht is containing controller that are failling

river rune
#

And what do you have in your META-INF ?

cerulean sphinx
river rune
#

thanks, checking...

river rune
#

I'm still doing some tests sorry for my late reply @cerulean sphinx

#

as you may know, building the native image takes some time...

cerulean sphinx
#

yes sure, np I totaly understand

river rune
#

Ok now I managed to run Stripe-java with graalvm

#

testing your invoice function...

river rune
#

So far, I'm getting missing registred attribute but no NPE.... e.g.

java.lang.IllegalArgumentException: Type com.stripe.model.Price$Recurring is instantiated reflectively but was never registered. Register the type by adding "unsafeAllocated" for the type in reflect-config.json.
cerulean sphinx
#

can you check please ?

river rune
#

Yes I'm updating the attributes one by one...

#

Your file is missing too

#

I'll share the final one by the end...

#

For example you don't have InvoiceLineItem$ProrationDetails

#

But no NPE so far, every think working perfectly

#

I'm testing this Jakarta API for example with customer:

@GetMapping("/stripe")
    public ResponseEntity<Map<String, String>> hello() {
        CustomerCreateParams params =
                CustomerCreateParams
                        .builder()
                        .setDescription("Example description")
                        .setEmail("test@example.com")
                        .setPaymentMethod("pm_card_visa")  // obtained via Stripe.js
                        .build();

        try {
            Customer customer = client.customers().create(params);
            System.out.println(customer);
            Map<String, String> response = new HashMap<>();
            response.put("customerId", customer.getId());
            return ResponseEntity.ofNullable(response);
        } catch (StripeException e) {
            e.printStackTrace();
        }
        return null;
    }
#

and it creates a customer

#

I simply added the reflect-config.json and the native-image.properties under src/main/resources/META-INF/native-image/{package}/

#

I can sharre with you the updated project if you want at the end...

cerulean sphinx
#

yes would be greate

river rune
#

Between I'm using Java 21 and latest version of GraalVM

#

Here is the sample I'm using...

#

After untarring it, you can build the native image using this command:
./mvnw package -Dnative

#

And then run the image:
`./target/getting-started-1.0.0-SNAPSHOT-runner

`

#

You can test the customer endpoint at localhost:8080/hello/stripe/customer

#

And don't forget to update your stripe API key

#

at GreetingResource line 20

cerulean sphinx
#

thank you let me try

river rune
#

For the invoice part, there is still other attribute to update in the reflect-config.json, continue to add them one by one...

cerulean sphinx
#

Hey @river rune any luck with Invoice ?

#

I just checked customer creation , I already had an similar endpoint in the service I am developing , and strangely enougth is working fine , but any enpoint that is fetching something is failing with NPE

#

for example trying to fetch all products defined in stripe is failing with

river rune
#

if so can you share it back with me ?

cerulean sphinx
#

yes

#

sec

river rune
#

thanks checking...

#

You still have unregistred attributes in that file...

#

for example,

Caused by: java.lang.IllegalArgumentException: Type com.stripe.model.StripeCollection is instantiated reflectively but was never registered. Register the type by adding "unsafeAllocated" for the type in reflect-config.json.

#

Are you getting NPE on the sample I shared with you ?

cerulean sphinx
#

No on my main project

river rune
#

I can't tell much about your main project

#

but what I'm sure of is that stripe-java works with quarkus and graalvm

#

you can always refer to the quickstart I shared with you and double check..

cerulean sphinx
#

But you still was not able to execute an succesfull GET request, how can you be sure that is working ?

river rune
#

Ah maybe I wasn't enough clear then earlier

#

first you need to complete the reflect-config.json with all the required fields using the quickstart I shared with

#

are you able to complete this step ?

cerulean sphinx
#

not sure

#

let me see

river rune
#

Why ?

#

You simply need to package the native image and run the invoice endpoint and see what field is missing.

cerulean sphinx
#

But wait let's do it a bit simpler, lets pick an resource that have all the properties already present and try to fetch it

cerulean sphinx
river rune
#

I strongly invite you to run the quarkus I shared with you and make your tests on it first, then try to see what is the different with your main project and what is causing issue...

#

There must be something else causing the NPE while packaging your app

cerulean sphinx
#

Men I don't know who you are but If we will meat one day I will buy you a drink ๐Ÿ˜„ , thank you verry much is finnaly working

#

I am still missing some properties but I was able to get thoues cursed Invoices ๐Ÿ˜„

#

Thank you