user955732
user955732

Reputation: 1370

Java syntax to Groovy syntax

I am not really sure how to translate this to groovy syntax.

Have checked this differences with java page already.

Thanks!

    TrustManager[] trustAllCerts = new TrustManager[] {
       new X509TrustManager() {
          public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return null;
          }

          public void checkClientTrusted(X509Certificate[] certs, String authType) {  }

          public void checkServerTrusted(X509Certificate[] certs, String authType) {  }

       }
    };

enter image description here

Upvotes: 0

Views: 379

Answers (2)

tim_yates
tim_yates

Reputation: 171154

The following should work:

import java.security.cert.*
import javax.net.ssl.*

TrustManager[] trustAllCerts = [
    [ getAcceptedIssuers: { -> null },
      checkClientTrusted: { X509Certificate[] certs, String authType -> },
      checkServerTrusted: { X509Certificate[] certs, String authType -> } ] as X509TrustManager
]

Upvotes: 3

cfrick
cfrick

Reputation: 37063

in groovy {} is always a block/closure. You would have to use [ new X509TrustManager() { ... } ]. If there are problems casting this dash an ... as TrustManager[] at the end.

Upvotes: 0

Related Questions