private String getAuthToken(String token) { if(token == null || token.isEmpty()) { return null; } String path = this.protocol + "://" + this.server + "/api/auth"; String body = "{\"token\":\"" + token + "\"}"; HTTPRequest httpRequest = WS.url(path).body(body).header("Content-Type", "application/json;charset=UTF-8"); try (HTTPResponse response = httpRequest.put()) { int status = response.getStatus(); if (200 <= status && 300 > status) { String responseAsString = response.getResponseAsString(); if (responseAsString.startsWith("\"")) { responseAsString = responseAsString.substring(1); } if (responseAsString.endsWith("\"")) { responseAsString = responseAsString.substring(0, responseAsString.length() - 1); } return responseAsString; } else { this.logger.warn("Authentication with CloudConductor Server {} failed with status {}", this.server, status); } } return null; } }
private String createTicket(Ticket ticket) { final String json; try { json = MapperFactory.createDefault().writeValueAsString(ticket.toJsonMap()); } catch (JsonProcessingException e) { throw new RuntimeException(e); } String url = "https://" + this.subdomain + ".zendesk.com/api/v2/tickets.json"; HTTPRequest req = WS.url(url).authBasic(this.agentMail + "/token", this.agentToken).contentType(MediaType.APPLICATION_JSON).body(json); try (HTTPResponse post = req.post()) { if (post.getStatus() != 201) { throw new InternalServerErrorException(); } return post.getResponseAsString(); } }