Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Problem when I make put or post request

Brahim ESSALIH November 22, 2016

Hello everybody,

I developped an Atlassian connect addon for JIRA onDemand. I developped this addon using spring-boot and resttemplate for making REST requests. I'm using webHook to add some features to JIRA. the problem is when the whebhook call the service, resttemplate throws an exception

this is the service called by webhook:

...
@RequestMapping(value = "/assignedMe", method = RequestMethod.POST)
    public String assigneMe(@RequestBody WebhookBodyWrapper webhookBodyWrapper) throws JsonProcessingException {
        String issueKey = webhookBodyWrapper.getIssue().getIssueKey();
        String userName = webhookBodyWrapper.getUser().getName();
        // Assigne issue to user
        IssueUserWrapper assigneeWrapper = new IssueUserWrapper();
        assigneeWrapper.setName(userName);
        assigneeWrapper.setDisplayName(webhookBodyWrapper.getUser().getDisplayName());
        assigneeWrapper.setEmailAddress(webhookBodyWrapper.getUser().getEmailAddress());
        if (webhookBodyWrapper.getIssue().getFields().getAssignee() == null) {
            logger.info("AssignedMe assigneeWrapper: ==> " + mapper.writeValueAsString(assigneeWrapper));
            HttpEntity<IssueUserWrapper> httpEntity = new HttpEntity<IssueUserWrapper>(assigneeWrapper, jiraUtils.getHeader());
// THIS THROWs ERROR BELOW
            restTemplate.exchange(jiraRestApiURL + issueKey + "/assignee", HttpMethod.PUT, httpEntity, Object.class);
        }
        return "Success";
    }
 
...

 

this a snippet of the trace track:

java.lang.NullPointerException                                                                                                                                                                                                   
        at com.nimbusds.jose.crypto.MACProvider.<init>(MACProvider.java:116) ~[nimbus-jose-jwt-3.6.jar!/:3.6]                                                                                                                    
        at com.nimbusds.jose.crypto.MACSigner.<init>(MACSigner.java:51) ~[nimbus-jose-jwt-3.6.jar!/:3.6]                                                                                                                         
        at com.atlassian.connect.spring.internal.request.jwt.JwtBuilder.createJwtWriter(JwtBuilder.java:89) ~[atlassian-connect-spring-boot-core-1.0.0.jar!/:?]                                                                  
        at com.atlassian.connect.spring.internal.request.jwt.JwtBuilder.build(JwtBuilder.java:85) ~[atlassian-connect-spring-boot-core-1.0.0.jar!/:?]                                                                            
        at com.atlassian.connect.spring.internal.request.jwt.JwtGenerator.createJwtToken(JwtGenerator.java:27) ~[atlassian-connect-spring-boot-core-1.0.0.jar!/:?]                                                               
        at com.atlassian.connect.spring.internal.request.jwt.JwtSigningClientHttpRequestInterceptor.createJwt(JwtSigningClientHttpRequestInterceptor.java:119) ~[atlassian-connect-spring-boot-core-1.0.0.jar!/:?]               
        at com.atlassian.connect.spring.internal.request.jwt.JwtSigningClientHttpRequestInterceptor.wrapRequest(JwtSigningClientHttpRequestInterceptor.java:113) ~[atlassian-connect-spring-boot-core-1.0.0.jar!/:?]             
        at com.atlassian.connect.spring.internal.request.jwt.JwtSigningClientHttpRequestInterceptor.lambda$intercept$0(JwtSigningClientHttpRequestInterceptor.java:43) ~[atlassian-connect-spring-boot-core-1.0.0.jar!/:?]       
        at java.util.Optional.map(Optional.java:215) ~[?:1.8.0_91]                                                                                                                                                               
        at com.atlassian.connect.spring.internal.request.jwt.JwtSigningClientHttpRequestInterceptor.intercept(JwtSigningClientHttpRequestInterceptor.java:43) ~[atlassian-connect-spring-boot-core-1.0.0.jar!/:?]                
        at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:85) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                             
        at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:69) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                  
        at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                        
        at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                                  
        at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:596) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                                                          
        at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                                                            
        at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:475) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                                                           
        at com.oliverstore.plugins.service.WebhookServices.updateIsPrincipal(WebhookServices.java:63) ~[crm-plugins.jar!/:1.0]                                                                                                   
        at com.oliverstore.plugins.controller.MicroServicesController.mainContactInfo(MicroServicesController.java:122) ~[crm-plugins.jar!/:1.0]                                                                                 
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]                                                                                                                                             
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]                                                                                                                           
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]                                                                                                                   
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]                                                                                                                                                        
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                               
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                       
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) ~[spring-webmvc-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                        
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:832) ~[spring-webmvc-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                      
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:743) ~[spring-webmvc-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                           
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                               
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:961) ~[spring-webmvc-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                                           
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895) ~[spring-webmvc-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                                            
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967) ~[spring-webmvc-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                                         
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:869) ~[spring-webmvc-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                                                 
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) ~[tomcat-embed-core-8.0.33.jar!/:8.0.33]                                                                                                                 
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843) ~[spring-webmvc-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                                                
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.0.33.jar!/:8.0.33]                                                                                                                 
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) ~[tomcat-embed-core-8.0.33.jar!/:8.0.33]                                                                            
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.33.jar!/:8.0.33]                                                                                    
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.0.33.jar!/:8.0.33]                                                                                                  
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) ~[tomcat-embed-core-8.0.33.jar!/:8.0.33]                                                                            
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.33.jar!/:8.0.33]                                                                                    
        at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConfiguration.java:261) ~[spring-boot-actuator-1.3.5.RELEASE.jar!/:1.
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                                           
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) ~[tomcat-embed-core-8.0.33.jar!/:8.0.33]                                                                            
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) ~[tomcat-embed-core-8.0.33.jar!/:8.0.33]

 

in my pom.xml

I use  the version 1.0.0:

<atlassian-connect-spring-boot.version>1.0.0</atlassian-connect-spring-boot.version>

 

Would you have any ideas ?

Best regards

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Jake Furler
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 22, 2016

Hi Brahim, it looks like the null pointer exception is being thrown because the atlassian connect spring boot framework doesn't have a shared secret stored for the instance you're making the request to. Are you sure the instance you're hitting currently has the add-on installed? Is the "jiraRestApiURL" variable in your code an absolute url or a relative one?

Brahim ESSALIH November 22, 2016

Thanks @Jake Furler.

I have installed my addon on the instance and JIRA confirm that is installed with success. 

The URI is absolute. I tried using absolute URL and I had this error

2016-11-23T10:04:32,570 ERROR [[/jira-rct/v1.0].[dispatcherServlet]] [http-nio-8080-exec-4] Servlet.service() for servlet [dispatcherServlet] in context with path [/jira-rct/v1.0] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: URI is not absolute] with root cause
java.lang.IllegalArgumentException: URI is not absolute
	at java.net.URI.toURL(URI.java:1088) ~[?:1.8.0_91]
	at org.springframework.http.client.SimpleClientHttpRequestFactory.createRequest(SimpleClientHttpRequestFactory.java:137) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
	at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:88) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
	at com.atlassian.connect.spring.internal.request.jwt.JwtSigningClientHttpRequestInterceptor.intercept(JwtSigningClientHttpRequestInterceptor.java:44) ~[atlassian-connect-spring-boot-core-1.0.0.jar:?]
	at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:85) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
	at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:69) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]

this is a snippet of my descriptor:

{
	"key": "com.test.issue.plugins.key.int",
	"baseUrl": "https://myserver.com",
	"name": "plugins INT",
	"description": "Les plugins de la CRM",
	"vendor": {
		"name": "tst",
		"url": "http://www.tst.com"
	},
	"authentication": {
		"type": "jwt"
	},
	"lifecycle": {
		"installed": "/installed",
		"uninstalled": "/uninstalled",
		"enabled": "/enabled",
		"disabled": "/disabled"
	},
	"apiVersion": 1,
	"scopes": [
		"read",
		"write"
	],
	"modules": {
...

 

Best regards

 

 

Brahim ESSALIH November 22, 2016

When I try to install for 2nd time the addon I have this error in the logs: 

Incoming installation request was not properly authenticated, but we have already installed the add-on for host jira:a9ac500d-50e2-402b-b53b-6ef72fce6425. Subsequent installation requests must include valid JWT. Returning 401.
Brahim ESSALIH November 22, 2016

I have also sometime this error

2016-11-23T11:03:18,171 ERROR [[/jira-rct/v1.0].[dispatcherServlet]] [http-nio-8080-exec-7] Servlet.service() for servlet [dispatcherServlet] in context with path [/jira-rct/v1.0] threw exception [Request processing failed; nested excepti
on is java.lang.UnsupportedOperationException] with root cause                                                                                                                                                                                
java.lang.UnsupportedOperationException                                                                                                                                                                                                       
        at java.util.Collections$UnmodifiableCollection.add(Collections.java:1055) ~[?:1.8.0_91]                                                                                                                                              
        at org.springframework.http.HttpHeaders.add(HttpHeaders.java:1031) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                                                                                    
        at com.atlassian.connect.spring.internal.request.jwt.JwtSigningClientHttpRequestInterceptor$JwtSignedHttpRequestWrapper.setJwtHeaders(JwtSigningClientHttpRequestInterceptor.java:171) ~[atlassian-connect-spring-boot-core-1.0.0.jar!
/:?]                                                                                                                                                                                                                                          
        at com.atlassian.connect.spring.internal.request.jwt.JwtSigningClientHttpRequestInterceptor$JwtSignedHttpRequestWrapper.<init>(JwtSigningClientHttpRequestInterceptor.java:161) ~[atlassian-connect-spring-boot-core-1.0.0.jar!/:?]   
        at com.atlassian.connect.spring.internal.request.jwt.JwtSigningClientHttpRequestInterceptor.wrapRequest(JwtSigningClientHttpRequestInterceptor.java:115) ~[atlassian-connect-spring-boot-core-1.0.0.jar!/:?]                          
        at com.atlassian.connect.spring.internal.request.jwt.JwtSigningClientHttpRequestInterceptor.lambda$intercept$0(JwtSigningClientHttpRequestInterceptor.java:43) ~[atlassian-connect-spring-boot-core-1.0.0.jar!/:?]                    
        at java.util.Optional.map(Optional.java:215) ~[?:1.8.0_91]                                                                                                                                                                            
        at com.atlassian.connect.spring.internal.request.jwt.JwtSigningClientHttpRequestInterceptor.intercept(JwtSigningClientHttpRequestInterceptor.java:43) ~[atlassian-connect-spring-boot-core-1.0.0.jar!/:?]                             
        at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:85) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                          
        at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:69) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                               
        at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                     
        at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                                               
        at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:596) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                                                                       
        at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                                                                         
        at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:475) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]                                                                                                        
        at com.oliverstore.plugins.controller.MicroServicesController.assigneMe(MicroServicesController.java:94) ~[crm-plugins.jar!/:1.0]                                                                                                     
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]                                                                                                                                                          
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]                                                                                                                                        
 
.....

But this error was fixed in version 1.0.0 of spring-boot-starter

https://ecosystem.atlassian.net/browse/ACSPRING-19

 

Jake Furler
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 23, 2016

It sounds like your add-on and JIRA instance have got into different states. By default your add-on should allow re-installation from a missing host. The 401 error you're seeing suggests that isn't happening. Are you using the production profile when starting your add-on (e.g. starting it with the -Drun.profiles=production parameter)? Or are you overriding the value of the atlassian.connect.allow-reinstall-missing-host property somewhere and setting it to false? Either of these would prevent re-installation in this case.

You could try changing the above, or explicity setting atlassian.connect.allow-reinstall-missing-host to true in your properties file, or clearing your add-on's database. Then reinstall the add-on on your instance. That should fix the discrepancies.

I imagine the error you were seeing when you tried to use a relative url was related.

Brahim ESSALIH November 23, 2016

No I didn't override this value atlassian.connect.allow-reinstall-missing-host. Concerning database I use the default one, "memory database". I used httpClient instead of restTemplate and it works

 

 

TAGS
AUG Leaders

Atlassian Community Events