SDK you're using (please complete the following information):
4.21.0
Describe the bug
While trying to authenticate a Custom Connection, using the sample code, I get the following exception:
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.internal.RuntimeDelegateImpl
at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:154)
at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:121)
at javax.ws.rs.core.UriBuilder.newInstance(UriBuilder.java:96)
at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:120)
at com.xero.api.client.IdentityApi.getConnectionsForHttpResponse(IdentityApi.java:245)
at com.xero.api.client.IdentityApi.getConnections(IdentityApi.java:207)
at nz.co.xxx.yyy.XeroUtils.authenticateWithXero(XeroUtils.java:60)
at nz.co.xxx.yyy.BalanceFetcher.start(BalanceFetcher.java:72)
at nz.co.xxx.yyy.Main.main(Main.java:39)
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.internal.RuntimeDelegateImpl
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:390)
at java.base/java.lang.Class.forName(Class.java:381)
at javax.ws.rs.ext.FactoryFinder.newInstance(FactoryFinder.java:111)
at javax.ws.rs.ext.FactoryFinder.find(FactoryFinder.java:209)
at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:136)
... 8 more
To Reproduce
Code I used:
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
private static final String TOKEN_REQUEST_URL = "https://identity.xero.com/connect/token";
public static final TokenStorage XERO_ERROR = null;
public static TokenStorage authenticateWithXero(XeroCredentials credentials, boolean verbose)
{
if (verbose)
System.out.println("Authenticating with Xero... ");
// The scopes that we will need
ArrayList<String> scopeList = new ArrayList<String>();
scopeList.add("accounting.transactions.read");
new NetHttpTransport();
try {
ClientCredentialsTokenRequest tokReq = new ClientCredentialsTokenRequest(HTTP_TRANSPORT, JSON_FACTORY, new GenericUrl(TOKEN_REQUEST_URL));
BasicAuthentication basicAuth = new BasicAuthentication(credentials.getClientId(), credentials.getClientSecret());
TokenResponse tokenResponse = tokReq.setScopes(scopeList)
.setClientAuthentication(basicAuth)
.execute();
if (Build.isDebug)
System.out.println(" Access token: " + tokenResponse.getAccessToken());
ApiClient defaultIdentityClient = new ApiClient("https://api.xero.com", null, null, null, null);
IdentityApi idApi = new IdentityApi(defaultIdentityClient);
List<Connection> connection = idApi.getConnections(tokenResponse.getAccessToken(),null);
// ... snip...
}
catch (TokenResponseException e) {
if (e.getDetails() != null) {
System.err.println("Error: " + e.getDetails().getError());
if (e.getDetails().getErrorDescription() != null) {
System.err.println(e.getDetails().getErrorDescription());
}
if (e.getDetails().getErrorUri() != null) {
System.err.println(e.getDetails().getErrorUri());
}
} else {
System.err.println(e.getMessage());
}
} catch (IOException e) {
System.err.println("Error: " + e.getMessage());
}
return XERO_ERROR;
}
After scratching my head for a while, I found a workaround by including the following dependency:
SDK you're using (please complete the following information): 4.21.0
Describe the bug While trying to authenticate a Custom Connection, using the sample code, I get the following exception:
To Reproduce Code I used:
After scratching my head for a while, I found a workaround by including the following dependency:
My POM file before the workaround was as follows (client details removed for privacy):