...
baseUrl = "http://salvatores-macbook-pro.local:2990/jira"
apiPath = "/rest/api/latest/issue/10100/attachments"
method = "POST"
...
static public String createJwt(String key, String sharedSecret, String method, String baseUrl, String contextPath, String apiPath)
throws UnsupportedEncodingException, NoSuchAlgorithmException {
long issuedAt = System.currentTimeMillis() / 1000L;
long expiresAt = issuedAt + 180L;
JwtJsonBuilder jwtBuilder = new JsonSmartJwtJsonBuilder()
.issuedAt(issuedAt)
.expirationTime(expiresAt)
.issuer(key);
CanonicalHttpUriRequest canonical = new CanonicalHttpUriRequest(method,
apiPath, contextPath, new HashMap<String, String[]>());
JwtClaimsBuilder.appendHttpRequestClaims(jwtBuilder, canonical);
JwtWriterFactory jwtWriterFactory = new NimbusJwtWriterFactory();
String jwtBuilt = jwtBuilder.build();
String jwtToken = jwtWriterFactory.macSigningWriter(SigningAlgorithm.HS256,
sharedSecret).jsonToJwt(jwtBuilt);
return jwtToken;
}private void upload(HttpServletResponse resp, String jwt, String url, String filename) throws IOException{
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost(url); httppost.setHeader("X-Atlassian-Token", "nocheck");
// Basic authorization works!// String jira_attachment_authentication = new String(org.apache.commons.codec.binary.Base64.encodeBase64(("admin:admin").getBytes()));// httppost.setHeader("Authorization", "Basic " + jira_attachment_authentication); httppost.setHeader("Authorization", "JWT "+ jwt);
InputStream is = getServletContext().getResourceAsStream("/" + filename); ByteArrayBody fileBody = new ByteArrayBody(IOUtils.toByteArray(is), filename);
HttpEntity entity = MultipartEntityBuilder.create() .addPart("file", fileBody) .build();
httppost.setEntity(entity); String mess = "Executing request " + httppost.getRequestLine(); log.info(mess);
CloseableHttpResponse response;
try { response = httpclient.execute(httppost); } finally { httpclient.close(); }
resp.setContentType("application/json"); resp.getWriter().print("{ response: " + response.getStatusLine().getStatusCode() + ", reason: " + response.getStatusLine().getReasonPhrase() + "}");}
HttpPost httppost = new HttpPost(url + "?jwt=" + jwt);
--
You received this message because you are subscribed to the Google Groups "Atlassian Connect Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to atlassian-connec...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to atlassian-connect-dev+unsub...@googlegroups.com.