2016-06-22 2 views
1

다음은 리치 텍스트/wiki 텍스트가 포함 된 JSON 데이터입니다. 이 데이터를 REST API를 통해 Jira의 문제 중 하나로 전달하려고합니다. 여기 자바는 내가 사용하고있는 기술이다.json의 나머지 API를 통해 Jira의 설명을 업데이트하는 방법

{"update":{"summary": [{"set": "CRF-397 – For Virgin Mobile, alert must be sent via email when Tier Mismatch exception is encountered."}]},"fields":{"description":{"set":"*Clients Impacted** Virgin Mobile *Background Information*<br>All UK schemes are experiencing at different levels some issues of:* Customers being billed on the wrong premium* Excess Fees paid at point of claim do not correspond to what has been communicated to the customer at the point of sale.* Welcome packs not being issued due to a mismatch *CRF Scope*<br>The scope of this project consists of identifying whenever a new device is communicated to Asurion by a client system and ensuring the data in each of those instances is validated to confirm that the device premium and excess fees are correctly aligned.*User Story Scope*<br>While doing enrollment if any record goes into exception due to Tier is match we have to send consolidated list of such records via email so that Asurion Team can communicate with Virgin Mobile to resolve the Tier Mismatch issues.*Requirement** An email alert must be sent when Tier Mismatch exception is encountered.* Flag based development must be done for triggering an email.* Email must be sent to Client Service, SCM and BI teams* Recipient email IDs must be configurable.* Exception list must contain below records:-  * The list of devices for which there was an exception * The Feature Code sent by Virgin Mobile * The feature code configured in Client Convention for the given device*"}}} 

위의 JSON은 jiraUpdateFromBuilder에 저장하고 있습니다.

다음과 같이 Jira의 설명을 업데이트하려면 PUT 메서드를 호출합니다. 여기에 201 이외의 상태를 받고 그리고 같은 문제가 포함 JIRA에서 이슈의 모든 필드이기 때문에

String _jiraUrl = applicationProperties.get(Constants.JIRAURL) 
      + "/rest/api/2/issue/" + reference; 
String _jiraUser = applicationProperties.get(Constants.JIRAUSER); 
String _jiraPwd = applicationProperties.get(Constants.JIRAPWD); 
String auth = new String(Base64.encode(_jiraUser + ":" + _jiraPwd)); 
int statusCode = invokePutMethod(auth, _jiraUrl.trim(), 
      jiraUpdateFromBuilder.toString().trim()); 

public static int invokePutMethod(String auth, String url, String data) { 

    int statusCode = 0; 
    try { 
     Client client = Client.create(); 
     WebResource webResource = client.resource(url); 
     ClientResponse response = webResource 
       .header("Authorization", "Basic " + auth) 
       .type("application/json").accept("application/json") 
       .put(ClientResponse.class, data); 
     statusCode = response.getStatus(); 
     return statusCode; 
    } catch (Exception e) { 
     Constants.ERROR.info(Level.INFO, e); 

    } 
    return statusCode; 
} 

이렇게, 나는 어떤 REST API를 통해, 락스에 문제의 설명을 업데이트 할 수 없습니다입니다 서식있는 텍스트 JSON 또는 다른 방법으로 변경해야하는 경우 JRJC가 다른 도움을 줄 수 있는지 여부를 알려주세요.

+0

어떤 오류가 발생합니까? – GlennV

+0

이와 같이 오류가 없지만 위의 json으로 put() 메서드를 호출 한 후 상태 코드가 400으로 표시됩니다. –

답변

1

당신의 JSON은 다음과 같습니다

{ 
    "update": { 
    "summary": [ 
     { 
     "set": "CRF-397 ..." 
     } 
    ] 
    }, 
    "fields": { 
    "description": { 
     "set": "..." 
    } 
    } 
} 

그러나 "필드"부분은 '설정'키워드를 사용할 필요가 없습니다, 그래서 이런 식으로 뭔가해야한다 :

{ 
    "update": { 
    "summary": [ 
     { 
     "set": "CRF-397 ..." 
     } 
    ] 
    }, 
    "fields": { 
    "description": "..." 
    } 
} 

하는 경우 또한

Specifying a "field_id": field_value in the "fields" is a shorthand for a "set" operation in the "update" section. Field should appear either in "fields" or "update", not in both.

: 당신이 PUT /issue REST resource에 대한 문서를 확인, 당신은이 언급 한 것을 볼 수 있습니다 , 응답 상태 코드가 400이라고 말한 것은 잘못된 요청임을 의미합니다. 응답 본문에는 무엇이 잘못되었는지에 대한 세부 정보가 포함되어 있으므로 로그에 기록하는 것이 가장 좋습니다. 이 오류에 관한

:

Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: [email protected]; line: 1, column: 187]

귀하의 설명 값이 줄 바꿈이 포함되어 있지만, 직접 JSON 문자열 사람들을 사용할 수 없습니다입니다. 당신은 그것들을 벗어나야 할 것입니다. this post for an example을 참조하십시오.

+0

"set"없이 사용하기 전에 사실이지만 작동하지 않았습니다. 여기에는 "set"이없는 완전한 로그와 json이 있습니다. –

+0

{ "요약": [{ "set": "CRF-397 - 버진 모바일의 경우, 계층 불일치 예외가 발생하면 이메일로 경고를 보내야합니다."}]}, "fields": { 설명 ":"매복 * 클라이언트 * * 버진 모바일 (Virgin Mobile) *
모든 영국의 제도는 서로 다른 수준에서의 몇 가지 문제가 발생하는 * 배경 정보 : 고객이 잘못된 프리미엄 "} 청구} 여기에 대한 응답하고 * 메시지. PUT https://ejira.int.syne.com/rest/api/2/issue/ISD-17223이 응답 상태 400을 반환했습니다. –

+0

400이 응답 상태 코드입니다. 응답 본문이 무엇입니까? – GlennV

관련 문제