Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Adding attachment working fine in postman but not work via java spring boot

Rex U
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 6, 2020

Hi All,

 

Iam working in a client project,there jira is hosted in aws .iam trying to add attachments to issue via rest api, it is working fine in postman and i used the same code in other cloud instances there also working fine,but in the client hosted instance it is not working giving 400 error ,other apis working fine.please find my below code .Please provide the solution for this.

 

final String username = "****";
final String password = "****";
final String proxyUrl = "****";
final int port = 8080;

CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(proxyUrl, port),
new UsernamePasswordCredentials(username, password)
);

HttpHost myProxy = new HttpHost(proxyUrl, port);
HttpClientBuilder clientBuilder = HttpClientBuilder.create();

clientBuilder.setProxy(myProxy).setDefaultCredentialsProvider(credsProvider).disableCookieManagement();

HttpClient httpClient = clientBuilder.build();
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
factory.setHttpClient(httpClient);

RestTemplate restTemplate = new RestTemplate(factory);

//Headers
HttpHeaders headers = new HttpHeaders();

String auth = "****" + ":" + "****";
String basicAuth = "Basic " + new String(new sun.misc.BASE64Encoder().encode(auth.getBytes()));
headers.set("Authorization", basicAuth);
headers.set("X-Atlassian-Token", "no-check");

//map
LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
FileSystemResource value = new FileSystemResource(new File("D://test.txt"));
map.add("file", value);

HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(map, headers);


ResponseEntity<String> d = restTemplate.exchange("https://*******/rest/api/2/issue/***-1/attachments", HttpMethod.POST, requestEntity, String.class);

 

 

 

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events