package com.perforce.hwsclient.auth; import java.io.IOException; import java.util.Map; import java.util.Map.Entry; import org.apache.oltu.oauth2.client.HttpClient; import org.apache.oltu.oauth2.client.request.OAuthClientRequest; import org.apache.oltu.oauth2.client.response.OAuthClientResponse; import org.apache.oltu.oauth2.client.response.OAuthClientResponseFactory; import org.apache.oltu.oauth2.common.exception.OAuthProblemException; import org.apache.oltu.oauth2.common.exception.OAuthSystemException; import com.squareup.okhttp.MediaType; import com.squareup.okhttp.OkHttpClient; import com.squareup.okhttp.Request; import com.squareup.okhttp.RequestBody; import com.squareup.okhttp.Response; public class OAuthOkHttpClient implements HttpClient { private OkHttpClient client; public OAuthOkHttpClient() { this.client = new OkHttpClient(); } public OAuthOkHttpClient(OkHttpClient client) { this.client = client; } public <T extends OAuthClientResponse> T execute(OAuthClientRequest request, Map<String, String> headers, String requestMethod, Class<T> responseClass) throws OAuthSystemException, OAuthProblemException { MediaType mediaType = MediaType.parse("application/json"); Request.Builder requestBuilder = new Request.Builder().url(request.getLocationUri()); if(headers != null) { for (Entry<String, String> entry : headers.entrySet()) { if (entry.getKey().equalsIgnoreCase("Content-Type")) { mediaType = MediaType.parse(entry.getValue()); } else { requestBuilder.addHeader(entry.getKey(), entry.getValue()); } } } RequestBody body = request.getBody() != null ? RequestBody.create(mediaType, request.getBody()) : null; requestBuilder.method(requestMethod, body); try { Response response = client.newCall(requestBuilder.build()).execute(); return OAuthClientResponseFactory.createCustomResponse( response.body().string(), response.body().contentType().toString(), response.code(), responseClass); } catch (IOException e) { throw new OAuthSystemException(e); } } public void shutdown() { // Nothing to do here } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 19553 | swellard | Move and rename clients | ||
//guest/perforce_software/helix-web-services/main/source/clients/2016.1.0/java/src/main/java/com/perforce/hwsclient/auth/OAuthOkHttpClient.java | |||||
#1 | 19535 | drobins | Refactor package names to hws | ||
//guest/perforce_software/helix-web-services/main/source/clients/2016.1.0/java/src/main/java/com/perforce/helix_web_services_client/auth/OAuthOkHttpClient.java | |||||
#1 | 18795 | tjuricek | Use point-release versioning for the client SDKs and installers. | ||
//guest/perforce_software/helix-web-services/main/source/clients/2016.1/java/src/main/java/com/perforce/helix_web_services_client/auth/OAuthOkHttpClient.java | |||||
#1 | 18679 | tjuricek |
Revising HWS paths to work primarily at product version 2016.1. The swagger definitions will primarily work at a major platform release number. We will generate new clients for each major release, and ensure backwards compatibility as time goes on by keeping the older clients around in the tree. Note: These are JUST URLs, and do not include other revisions we plan on making shortly. |
||
//guest/perforce_software/helix-web-services/main/source/clients/java/src/main/java/com/perforce/helix_web_services_client/auth/OAuthOkHttpClient.java | |||||
#1 | 18515 | tjuricek |
Replacing java_client with Swagger-based clients/java project. - Switched implementations of the Swagger client to use okhttp with gson. - Added the version to the "status" method, and hey, added that method to the spec - Added templates to the java code generator to add some default methods, fixing some import issues in Gradle NOTE: We may want to break down the API a bit and restructure it. |