Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[groovy]Unexpected error on small script #262

Open
Hooghof opened this issue Aug 6, 2024 · 5 comments
Open

[groovy]Unexpected error on small script #262

Hooghof opened this issue Aug 6, 2024 · 5 comments
Assignees
Labels
accepted bug Something isn't working
Milestone

Comments

@Hooghof
Copy link

Hooghof commented Aug 6, 2024

EXAMPLE 1

Input header

name: counter
value: 0

Script

request.setHeader("counter", request.getHeader("counter", Integer.class) + 1);
result = request.body

Error

Invalid groovy script: 'Unable to make field private static final long java.lang.Number.serialVersionUID accessible: module java.base does not "opens java.lang" to unnamed module @71ba6d4e'

EXAMPLE 2

Input body

{
    "name": "John McClusky",
    "age": 45,
    "city": "York"
}

Script

import java.util.UUID

// Generate a random UUID
def uuid = UUID.randomUUID()

// Convert the UUID to a string
def uuidString = uuid.toString()

request.setHeader('uuid', uuidString)
result = request.body

Error

Invalid groovy script: 'Unable to make private java.util.UUID(byte[]) accessible: module java.base does not "opens java.util" to unnamed module @71ba6d4e'
@Hooghof Hooghof added the bug Something isn't working label Aug 6, 2024
@Hooghof Hooghof added this to the 5.0.0 milestone Aug 6, 2024
@brunovg
Copy link
Collaborator

brunovg commented Aug 8, 2024

These 2 examples should work now on Next.

Basically we added the following options when running java:

--add-opens java.base/java.lang=ALL-UNNAMED
--add-opens java.base/java.util=ALL-UNNAMED

Maybe in the feature we need to add more modules.

@Hooghof
Copy link
Author

Hooghof commented Aug 9, 2024

The 2 examples work fine on next now. The next new examples give an error or an unexpected response.

EXAMPLE 3

Input header

name: uuid
value: 7cbf5a21-0e95-4df0-80c8-34f2c56d2032

Script

def headerName = 'uuid'
def headerValue = exchange.message.getHeader(headerName, String)

int charCount = headerValue.length()

Expected result (equal to groovy 3.0)

body: 36

EXAMPLE 4

Script

import groovy.json.JsonSlurper

def messageBody = request.getBody(String.class)
def slurper = new JsonSlurper()
def parsedJson = slurper.parseText(messageBody)

parsedJson.each { key, value ->
    exchange.in.setHeader(key, value)
}

Error

Invalid groovy script: 'class [B cannot be cast to class [C ([B and [C are in module java.base of loader 'bootstrap')'

@skin27
Copy link
Member

skin27 commented Aug 9, 2024

Example 3: Don't know what error you exactly get, but I got '36', as expected. Did you set the input header?

"uuid"="7cbf5a21-0e95-4df0-80c8-34f2c56d2032"

If there is not input header then you will get "Invalid groovy script: 'Cannot invoke method length() on null object'"

@skin27
Copy link
Member

skin27 commented Aug 9, 2024

Example 4 was an dependency issue. This script can be retested.

@Hooghof
Copy link
Author

Hooghof commented Aug 12, 2024

Concerning example 3, the frontend shows the expected body. The header ''uuid' is in the incoming message. If you call the flow, the body stays empty.

Image

Image

The jsonslurper (example 4) works properly now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants