簡體   English   中英

通過REST API管理JIRA Webhooks

[英]Managing JIRA webhooks via REST API

我正在嘗試通過Java REST API管理JIRA。 以下是我的問題:1.如何在調用REST代碼時通過webhook在URL中傳遞參數。 2.如何在我的REST代碼中接收通過webhook傳遞的請求。

我創建了一個Webhook,並在提供的URL中調用了我的REST API http:// localhost:8080 / rest / JIRAIntegration / JIRAService / record

雖然我的其余代碼看起來像

    @Path("/JiraService")
    public class JiraService {

    @GET
    @Path("/records")
    public String getJiraRequest(InputStream response){
     //req.getParameter("key");
  BufferedReader br = null;
  StringBuilder sb = new StringBuilder();
  String line;
  br = new BufferedReader(new InputStreamReader(response));
  try {
     while ((line = br.readLine()) != null) {
        sb.append(line);
     }
  }
  catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
  }
  System.out.println("Inputstream::"+sb.toString());
  return sb.toString();

}

我是JIRA webhooks和REST的新手。 任何幫助,感激不盡。

接收Webhook的回復。 您需要在jira中創建一個Webhook,並提供一個可以公開訪問的URL。 您的代碼應在端口80或443上運行。

現在說,例如,您休息的鏈接是POST呼叫: http : //xyz.abc.com/webservice/rest/jira/

在webhook中,您應將網址設為http://xyz.abc.com/webservice/rest/jira/

您的休息控制器將具有以下休息方法

@POST()@Consumes(MediaType.APPLICATION_JSON)@Produces(MediaType.APPLICATION_JSON)public Response postMsg(String h){

  Gson gson = new GsonBuilder().setPrettyPrinting().create(); JsonParser jp = new JsonParser(); JsonElement je = jp.parse(h); String prettyJsonString = gson.toJson(je); System.out.println("################################"); System.out.println(prettyJsonString); String output = prettyJsonString; return Response.status(200).entity(output).build(); } 

現在執行此操作后,您應該配置webhook以在創建或更新的Jira票證上發送重發。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM