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

Reflection error when creating XeroClient #163

Closed
ludup opened this issue Nov 8, 2019 · 4 comments
Closed

Reflection error when creating XeroClient #163

ludup opened this issue Nov 8, 2019 · 4 comments

Comments

@ludup
Copy link

ludup commented Nov 8, 2019

I'm trying to track down a problem with the Xero API.

Version 2.3.16

I get an exception whilst trying to create an instance of XeroClient.

I wonder if this is some sort of dependency / version issue? Although the maven module does not appear to draw in any transitive dependencies?

[Thread-111] ERROR com.hypersocket.crm.xero.XeroAccountingServiceImpl - Failed to post invoice
java.lang.NoSuchFieldError: REFLECTION
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.(RuntimeModelBuilder.java:89)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:456)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.(JAXBContextImpl.java:302)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1140)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:121)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:202)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:171)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:131)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:335)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:431)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:394)
at com.xero.api.jaxb.XeroJAXBMarshaller.initContext(XeroJAXBMarshaller.java:27)
at com.xero.api.jaxb.XeroJAXBMarshaller.(XeroJAXBMarshaller.java:23)
at com.xero.api.XeroClient.(XeroClient.java:40)

I used the following code:

	Config config = JsonConfig.getInstance();

	config.setConsumerKey(configurationService.getValue(realm, "xero.consumerKey"));
	config.setConsumerSecret(configurationService.getValue(realm, "xero.consumerSecret"));
	config.setAppType("PRIVATE");
	
	
	String privateKey = configurationService.getValue(realm, "xero.privateKey");
	if(StringUtils.isNotBlank(privateKey)) {
		try (InputStream privateKeyStream = fileService.getInputStream(privateKey))
		{
			String phrase  = configurationService.getDecryptedValue(realm, "xero.passphrase");
			RsaSignerFactory signerFactory = new RsaSignerFactory(privateKeyStream, phrase);
			client = new XeroClient(config, signerFactory);
			client.setOAuthToken(config.getConsumerKey(), 
							config.getConsumerSecret());
			return client;
		}
	}
	
	throw new IOException("No private key configured for Xero accounting");
@ludup
Copy link
Author

ludup commented Nov 8, 2019

Looking at the pom it looks like you are creating an uber jar with all the dependencies?

This is not an ideal situation for projects that rely on maven to discover and resolve dependencies. I believe this is the source of my problem because you are including dependencies that I have elsewhere but with different versions.

Do you have a maven pom that does not do this?

@SidneyAllen
Copy link
Contributor

Hey @ludup

Always interested in hearing how to do things better. If you want to share some links to how to enable "discover and resolve dependencies" I'd be happy to review it for an enhancement request.

In the meantime, the order of your dependencies does impact which version is loaded. Perhaps you could work around this in the near term.
https://stackoverflow.com/questions/31740785/why-order-of-maven-dependencies-matter

@ludup
Copy link
Author

ludup commented Nov 12, 2019

Thanks for the quick response.

You do not need to "enable" dependency discovery, its a core part of Maven.

https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

I note that actually you are deploying both an uber jar and the standard jar so I do have the artifact I need. I'm still trying to track down the problem here, it may not be caused by the uber jar after all. I'll update you when I have more information.

I would like to make one suggestion for the improvement of your project layout. It would be better for users if you separate out the core API code that developers need to use, from the examples code so that we do not have to pull in the dependencies of your examples. I'd prefer that I did not have to pull in servlet API etc for your example web app. yes I can exclude from maven, but I'd rather not have to.

@SidneyAllen
Copy link
Contributor

Hi @ludup

We've already separated example code in version 3.x of our SDK which is for OAuth 2.0. I've gone ahead and removed "servlet" code from the example for version 2.3.21.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants