package com.perforce.ts.rest;
/**
* Copyright (c) 2013 Perforce Software. All rights reserved.
*/
import com.atlassian.httpclient.api.EntityBuilder;
import com.atlassian.httpclient.api.HttpClient;
import com.atlassian.httpclient.api.ResponsePromise;
import com.atlassian.jira.rest.client.api.MetadataRestClient;
import com.atlassian.jira.rest.client.api.RestClientException;
import com.atlassian.jira.rest.client.api.SessionRestClient;
import com.atlassian.jira.rest.client.api.domain.Issue;
import com.atlassian.jira.rest.client.api.domain.input.IssueInput;
import com.atlassian.jira.rest.client.internal.async.AsynchronousIssueRestClient;
import com.atlassian.jira.rest.client.internal.json.gen.IssueInputJsonGenerator;
import com.atlassian.jira.rest.client.internal.json.gen.JsonGenerator;
import io.atlassian.util.concurrent.Promise;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.Map;
import org.codehaus.jettison.json.JSONException;
/**
* Asynchronous implementation of ExtendedIssueRestClient.
*/
public class AsynchronousExtendedIssueRestClient extends AsynchronousIssueRestClient implements ExtendedIssueRestClient {
private static final String JSON_CONTENT_TYPE = "application/json";
private final HttpClient client;
public AsynchronousExtendedIssueRestClient(final URI baseUri, final HttpClient client, final SessionRestClient sessionRestClient,
final MetadataRestClient metadataRestClient) {
super(baseUri, client, sessionRestClient, metadataRestClient);
this.client = client;
}
/**
* @see com.perforce.p4dtg.plugin.jira.rest.client.ExtendedIssueRestClient#update(URI, IssueInput)
*/
public Promise<Void> update(final URI issueUri, final IssueInput issueInput) {
return put(issueUri, issueInput, new IssueInputJsonGenerator());
}
/**
* @see com.perforce.p4dtg.plugin.jira.rest.client.ExtendedIssueRestClient#update(Issue, IssueInput)
*/
public Promise<Void> update(final Issue issue, final IssueInput issueInput) {
return update(issue.getSelf(), issueInput);
}
/* protected final <T> Promise<Void> put(final URI uri, final T entity, final JsonGenerator<T> jsonGenerator) {
final ResponsePromise responsePromise = client.newRequest(uri)
.setEntity(toEntity(jsonGenerator, entity))
.put();
return call(responsePromise);
}
*/
private <T> EntityBuilder toEntity(final JsonGenerator<T> generator, final T bean) {
return new EntityBuilder() {
public Entity build() {
return new Entity() {
public Map<String, String> getHeaders() {
return Collections.singletonMap("Content-Type", JSON_CONTENT_TYPE);
}
public InputStream getInputStream() {
try {
return new ByteArrayInputStream(generator.generate(bean).toString().getBytes(Charset
.forName("UTF-8")));
} catch (JSONException e) {
throw new RestClientException(e);
}
}
};
}
};
}
}
# |
Change |
User |
Description |
Committed |
|
#2
|
26340 |
Joel Brown |
Update jiraRestAccess to use latest jira java client. |
|
|
#1
|
26339 |
Joel Brown |
Branching for reworking with most recent atlassian jira jave client |
|
|
//guest/joel_brown/jiraRestAccess/src/com/perforce/ts/rest/AsynchronousExtendedIssueRestClient.java |
#1
|
12538 |
Joel Brown |
Test program for JIRA REST connections, useful for troubleshooting p4dtg's JIRA-REST plugin. |
|
|