Hello,
I am in process of developing Jira Server Plugin.
Inside one of the Rest Api call (Jira Plugin Module) there is service call which has Rest request to another Rest API service (custom REST server).
For calling custom Rest API I am using RestTemplate provided by plugin container itself.
@Autowired
public ProofInodeNavigatorImpl(@ClasspathComponent RestTemplate restTemplate)
I got problem with reading response inside restTemplate call because of MediaType problems.
So one of the solution was adding MessageConverter inside RestTemplate with defining suported media types.
Now my code looks like that
@Autowired
public ProofInodeNavigatorImpl(@ClasspathComponent RestTemplate restTemplate) {
setMessageConverter(restTemplate);
this.proofRestTemplate = restTemplate;
}
private void setMessageConverter(final RestTemplate restTemplate) {
MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
mappingJackson2HttpMessageConverter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON, MediaType.APPLICATION_PROBLEM_JSON_UTF8));
restTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter);
}
I checked the version of spring-web in the OSGI browser.
It was Apache ServiceMix :: Bundles :: spring-web
So I added it’s spring-web dependency with ‘provided’ scope to the pom.
Also find what the Jackson version is used inside spring-web and also added Jackson dependency with ‘provided’ scope.
The pom file parts
<instructions>
<Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>
<Export-Package>com.subject7</Export-Package>
<Import-Package>
org.springframework.osgi.*;resolution:="optional",
org.eclipse.gemini.blueprint.*;resolution:="optional",
org.springframework.http;resolution:="optional",
com.fasterxml.jackson;resolution:="optional",
*
</Import-Package>
<Spring-Context>*</Spring-Context>
</instructions>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.10.RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.10.RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.6</version>
<scope>provided</scope>
</dependency>
<jira.version>8.0.2</jira.version>
<amps.version>8.0.2</amps.version>
<atlassian.spring.scanner.version>2.1.7</atlassian.spring.scanner.version>
And now when I try to start my plugin I see an exception
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException
at com.subject7.addon.jira.service.proof.ProofInodeNavigatorImpl.<init>(ProofInodeNavigatorImpl.java:44)
... 3 filtered
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:170)
... 20 more
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException not found by org.apache.servicemix.bundles.spring-web [4]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1639)
at org.apache.felix.framework.BundleWiringImpl.access$200(BundleWiringImpl.java:80)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2053)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 27 more
In case the line setMessageConverter(restTemplate);
is removed then there is no any actions with
MappingJackson2HttpMessageConverter and plugin starts without any problem.
I am not well-oriented in Jira Plugin development and currently have no idea where I did mistake.
If you have any comments or recommendations, I would be glad to know about them.
Thanks