Java vs REST API. Need Help
Hi. I want to syncronize issues from redmine to YouTrack.
With API i'm get all issues from youtrack, all issues from redmine and for all new issues from redmine create new issue in YouTrack
Project in java
step 1
CookieStore cYouTrack = getCookieYoutrack(yBaseUrl, yLogin, yPass);
public static CookieStore getCookieYoutrack(String baseurl, String login, String password) throws Exception {
HttpClient httpClient = new DefaultHttpClient();
..............
HttpPost httpPost = new HttpPost(baseurl + "/rest/user/login");
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
.............
CookieStore cookieStore = ((DefaultHttpClient) httpClient).getCookieStore();
step2:
// get xml with issues
String xmlYouTrack = getYouTrackIssues(yBaseUrl, cYouTrack);
String xmlRedmine = getRedmineIssues(rBaseUrl, rKey, rProject);
private static String getYouTrackIssues(String baseurl, CookieStore c) throws Exception {
String url = baseurl + "/rest/export/Task/issues?10";
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
// add request header
((DefaultHttpClient) client).setCookieStore(c);
.....
step3:
IssueSync(xmlYouTrack, xmlRedmine, cYouTrack);
public static void IssueSync (String xmlYouTrack, String xmlRedmine, CookieStore cookie) {
.....
if (!youtrackids.contains(((Node) fstNm.item(0)).getNodeValue())) {
putYouTrackIssue(subject, description, author, cookie);
public static void putYouTrackIssue(String subject, String description, String author, CookieStore cookie){
String desc = description + "\n Автор:"+author;
String url = yBaseUrl + "/rest/issue?Task&"+ URLEncoder.encode(subject)+"&"+URLEncoder.encode(desc);
System.out.println(url);
HttpClient client = new DefaultHttpClient();
HttpPut request = new HttpPut(url);
//response = client.execute(httppost, localContext);
// add request header
((DefaultHttpClient) client).setCookieStore(cookie);
HttpResponse response = null;
//client.execute(post);
try {
response = client.execute(request);
System.out.println(response.getStatusLine().getStatusCode());
} catch (IOException e) {
e.printStackTrace();
}
When i'm send PUT request, i'm get 403. In logs:
Why the GET method return me issues, PUT - no created...
With API i'm get all issues from youtrack, all issues from redmine and for all new issues from redmine create new issue in YouTrack
Project in java
step 1
CookieStore cYouTrack = getCookieYoutrack(yBaseUrl, yLogin, yPass);
public static CookieStore getCookieYoutrack(String baseurl, String login, String password) throws Exception {
HttpClient httpClient = new DefaultHttpClient();
..............
HttpPost httpPost = new HttpPost(baseurl + "/rest/user/login");
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
.............
CookieStore cookieStore = ((DefaultHttpClient) httpClient).getCookieStore();
step2:
// get xml with issues
String xmlYouTrack = getYouTrackIssues(yBaseUrl, cYouTrack);
String xmlRedmine = getRedmineIssues(rBaseUrl, rKey, rProject);
private static String getYouTrackIssues(String baseurl, CookieStore c) throws Exception {
String url = baseurl + "/rest/export/Task/issues?10";
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
// add request header
((DefaultHttpClient) client).setCookieStore(c);
.....
step3:
IssueSync(xmlYouTrack, xmlRedmine, cYouTrack);
public static void IssueSync (String xmlYouTrack, String xmlRedmine, CookieStore cookie) {
.....
if (!youtrackids.contains(((Node) fstNm.item(0)).getNodeValue())) {
putYouTrackIssue(subject, description, author, cookie);
public static void putYouTrackIssue(String subject, String description, String author, CookieStore cookie){
String desc = description + "\n Автор:"+author;
String url = yBaseUrl + "/rest/issue?Task&"+ URLEncoder.encode(subject)+"&"+URLEncoder.encode(desc);
System.out.println(url);
HttpClient client = new DefaultHttpClient();
HttpPut request = new HttpPut(url);
//response = client.execute(httppost, localContext);
// add request header
((DefaultHttpClient) client).setCookieStore(cookie);
HttpResponse response = null;
//client.execute(post);
try {
response = client.execute(request);
System.out.println(response.getStatusLine().getStatusCode());
} catch (IOException e) {
e.printStackTrace();
}
When i'm send PUT request, i'm get 403. In logs:
jetbrains.mps.webr.rpc.rest.provider.exception.ForbiddenException: You do not have permissions to Создание задач, or project [null] does not exist.…
jetbrains.mps.webr.rpc.rest.provider.exception.ForbiddenException: You do not have permissions to Создание задач, or project [null] does not exist.
at jetbrains.charisma.rest.RestUtil.assertCanCreateIssue(RestUtil.java:188)
at jetbrains.charisma.rest.RestUtil.createIssue(RestUtil.java:202)
at jetbrains.charisma.rest.IssueResource.put(IssueResource.java:388)
at sun.reflect.GeneratedMethodAccessor363.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
Why the GET method return me issues, PUT - no created...
Please sign in to leave a comment.
wrong url. Work url: String url = yBaseUrl + "/rest/issue?project=Task&summary="+ URLEncoder.encode(subject)+"&description="+URLEncoder.encode(desc);