groovygroovyshellgroovy-console

Facing issue while executing the Groovy code


def hawkClient = new com.wealdtech.hawk.HawkClient.
    Builder()
    .credentials(new com.wealdtech.hawk.HawkCredentials.Builder()
            .keyId("your-hawk-hey-id")
            .key("your-hawk-key")
            .algorithm(Algorithm.SHA256)
            .build())
    .build();

def authorization = hawkClient
    .generateAuthorizationHeader(sampler.getUrl().toURI(), sampler.getMethod(), sampler.getArguments().getArgument(0).getValue())

vars.put('authorization', authorization)

after execute the above code snippet I got some error. like-

org.codehaus.groovy.control.MultipleCompilationErrorsException: 
startup failed:
/home/cg/root/62c2edae2dde2/main.groovy: 1: unexpected token: . @ 
line 1, column 51.
    com.wealdtech.hawk.HawkClient.
                             ^
1 error

can anyone please help me to fix this issue ??

can anyone please help me to fix


Solution

  • The Groovy parser can't handle newlines as you have it above.

    Instead of

    def hawkClient = new com.wealdtech.hawk.HawkClient.
        Builder()
    

    You need to use

    def hawkClient = new com.wealdtech.hawk.HawkClient.Builder()
    

    So the parser can know what you mean to do