Java syntax to Groovy syntax

367 Views Asked by At

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

2

There are 2 best solutions below

1
On BEST ANSWER

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
]
0
On

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.