-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Javier Rojas <javier.rojas.blum@gmail.com> Co-authored-by: Javier Rojas Blum <javier.rojas.blum@gmail.com> Co-authored-by: Mike Schwartz <mike@gluu.org> Co-authored-by: William Lowe <willow9886@gmail.com> Co-authored-by: Yuriy Movchan <Yuriy.Movchan@gmail.com> Co-authored-by: Yuriy Zabrovarnyy <yzabrovarniy@gmail.com> Co-authored-by: YuriyZ <yzabrovarniy@gmail.com> Co-authored-by: ossdhaval <343411+ossdhaval@users.noreply.github.com> Co-authored-by: yurem <Yuriy.Movchan@gmail.com> Signed-off-by: moabu <47318409+moabu@users.noreply.github.com>
- Loading branch information
Showing
67 changed files
with
6,693 additions
and
1 deletion.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# IntelliJ IDEA project files | ||
.idea | ||
*.iml | ||
.classpath | ||
.project | ||
|
||
# Maven | ||
target | ||
.settings/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>oxeleven-client</artifactId> | ||
<name>oxEleven Client</name> | ||
<packaging>jar</packaging> | ||
|
||
<parent> | ||
<artifactId>oxeleven</artifactId> | ||
<groupId>org.gluu</groupId> | ||
<version>4.5.6-SNAPSHOT</version> | ||
</parent> | ||
|
||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.19.1</version> | ||
<configuration> | ||
<!-- Needed as we have both junit and testng --> | ||
<failIfNoTests>false</failIfNoTests> | ||
<trimStackTrace>false</trimStackTrace> | ||
|
||
<!-- exclude selenium tests --> | ||
<excludes> | ||
<exclude>**/selenium/*</exclude> | ||
<exclude>**/webdriver/*</exclude> | ||
<exclude>**/xml/*</exclude> | ||
</excludes> | ||
|
||
<suiteXmlFiles> | ||
<suiteXmlFile>target/test-classes/testng.xml</suiteXmlFile> | ||
</suiteXmlFiles> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.gluu</groupId> | ||
<artifactId>oxeleven-model</artifactId> | ||
</dependency> | ||
|
||
<!-- Jackson --> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.datatype</groupId> | ||
<artifactId>jackson-datatype-json-org </artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-client</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpcore</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
</dependency> | ||
|
||
<!-- Test --> | ||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
164 changes: 164 additions & 0 deletions
164
oxEleven/Client/src/main/java/org/gluu/oxeleven/client/BaseClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/* | ||
* oxEleven is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text. | ||
* | ||
* Copyright (c) 2016, Gluu | ||
*/ | ||
|
||
package org.gluu.oxeleven.client; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.Arrays; | ||
|
||
import javax.ws.rs.HttpMethod; | ||
import javax.ws.rs.client.WebTarget; | ||
import javax.ws.rs.core.Form; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.base.Strings; | ||
|
||
/** | ||
* @author Javier Rojas Blum | ||
* @version March 20, 2017 | ||
*/ | ||
public abstract class BaseClient<T extends BaseRequest, V extends BaseResponse> { | ||
|
||
private static final Logger LOG = Logger.getLogger(BaseClient.class); | ||
|
||
protected String url; | ||
protected BaseRequest request; | ||
protected BaseResponse response; | ||
protected WebTarget webTarget = null; | ||
protected Form requestForm = new Form(); | ||
protected Response clientResponse; | ||
|
||
public BaseClient(String url) { | ||
this.url = url; | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
protected void addRequestParam(String key, String value) { | ||
if (!Strings.isNullOrEmpty(key) && !Strings.isNullOrEmpty(value)) { | ||
if (HttpMethod.POST.equals(request.getHttpMethod())) { | ||
requestForm.param(key, value); | ||
} else { | ||
webTarget = webTarget.queryParam(key, value); | ||
} | ||
} | ||
} | ||
|
||
protected void addRequestParam(String key, Long value) { | ||
if (!Strings.isNullOrEmpty(key) && value != null) { | ||
if (HttpMethod.POST.equals(request.getHttpMethod())) { | ||
requestForm.param(key, value.toString()); | ||
} else { | ||
webTarget = webTarget.queryParam(key, value); | ||
} | ||
} | ||
} | ||
|
||
protected void addRequestParam(String key, String[] value) { | ||
if (!Strings.isNullOrEmpty(key) && value != null) { | ||
if (HttpMethod.POST.equals(request.getHttpMethod())) { | ||
requestForm.param(key, Arrays.toString(value)); | ||
} else { | ||
webTarget.queryParam(key, Arrays.toString(value)); | ||
} | ||
} | ||
} | ||
|
||
public abstract T getRequest(); | ||
|
||
public abstract void setRequest(T request); | ||
|
||
public abstract V getResponse(); | ||
|
||
public abstract void setResponse(V response); | ||
|
||
public abstract V exec() throws Exception; | ||
|
||
public String getRequestAsString() { | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
try { | ||
URL theUrl = new URL(url); | ||
|
||
if (getHttpMethod().equals(HttpMethod.POST)) { | ||
sb.append(HttpMethod.POST).append(" ").append(theUrl.getPath()).append(" HTTP/1.1"); | ||
if (!Strings.isNullOrEmpty(request.getContentType())) { | ||
sb.append("\n"); | ||
sb.append("Content-Type: ").append(request.getContentType()); | ||
} | ||
if (!Strings.isNullOrEmpty(request.getMediaType())) { | ||
sb.append("\n"); | ||
sb.append("Accept: ").append(request.getMediaType()); | ||
} | ||
sb.append("\n"); | ||
sb.append("Host: ").append(theUrl.getHost()); | ||
|
||
String accessToken = request.getAccessToken(); | ||
if (!Strings.isNullOrEmpty(accessToken)) { | ||
sb.append("\n"); | ||
sb.append("Authorization: Bearer ").append(accessToken); | ||
} | ||
|
||
sb.append("\n"); | ||
sb.append("\n"); | ||
sb.append(request.getQueryString()); | ||
} else if (getHttpMethod().equals(HttpMethod.GET)) { | ||
sb.append("GET ").append(theUrl.getPath()); | ||
if (!Strings.isNullOrEmpty(request.getQueryString())) { | ||
sb.append("?").append(request.getQueryString()); | ||
} | ||
sb.append(" HTTP/1.1"); | ||
sb.append("\n"); | ||
sb.append("Host: ").append(theUrl.getHost()); | ||
|
||
String accessToken = request.getAccessToken(); | ||
sb.append("\n"); | ||
sb.append("Authorization: Bearer ").append(accessToken); | ||
} | ||
} catch (MalformedURLException e) { | ||
LOG.error(e.getMessage(), e); | ||
} | ||
|
||
return sb.toString(); | ||
} | ||
|
||
public String getResponseAsString() { | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
if (response != null) { | ||
sb.append("HTTP/1.1 ").append(response.getStatus()); | ||
if (response.getHeaders() != null) { | ||
for (String key : response.getHeaders().keySet()) { | ||
sb.append("\n") | ||
.append(key) | ||
.append(": ") | ||
.append(response.getHeaders().get(key).get(0)); | ||
} | ||
} | ||
if (response.getEntity() != null) { | ||
sb.append("\n"); | ||
sb.append("\n"); | ||
sb.append(response.getEntity()); | ||
} | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
public abstract String getHttpMethod(); | ||
|
||
public static String toPrettyJson(Object object) throws JsonProcessingException { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
oxEleven/Client/src/main/java/org/gluu/oxeleven/client/BaseRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* oxEleven is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text. | ||
* | ||
* Copyright (c) 2016, Gluu | ||
*/ | ||
|
||
package org.gluu.oxeleven.client; | ||
|
||
/** | ||
* @author Javier Rojas Blum | ||
* @version March 20, 2017 | ||
*/ | ||
public abstract class BaseRequest { | ||
|
||
private String contentType; | ||
private String mediaType; | ||
private String httpMethod; | ||
private String accessToken; | ||
|
||
public String getContentType() { | ||
return contentType; | ||
} | ||
|
||
public void setContentType(String contentType) { | ||
this.contentType = contentType; | ||
} | ||
|
||
public String getMediaType() { | ||
return mediaType; | ||
} | ||
|
||
public void setMediaType(String mediaType) { | ||
this.mediaType = mediaType; | ||
} | ||
|
||
public String getHttpMethod() { | ||
return httpMethod; | ||
} | ||
|
||
public void setHttpMethod(String httpMethod) { | ||
this.httpMethod = httpMethod; | ||
} | ||
|
||
public String getAccessToken() { | ||
return accessToken; | ||
} | ||
|
||
public void setAccessToken(String accessToken) { | ||
this.accessToken = accessToken; | ||
} | ||
|
||
public abstract String getQueryString(); | ||
} |
65 changes: 65 additions & 0 deletions
65
oxEleven/Client/src/main/java/org/gluu/oxeleven/client/BaseResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* oxEleven is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text. | ||
* | ||
* Copyright (c) 2016, Gluu | ||
*/ | ||
|
||
package org.gluu.oxeleven.client; | ||
|
||
import javax.ws.rs.core.MultivaluedMap; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
/** | ||
* @author Javier Rojas Blum | ||
* @version March 20, 2017 | ||
*/ | ||
public abstract class BaseResponse { | ||
|
||
protected int status; | ||
protected String location; | ||
protected String entity; | ||
protected MultivaluedMap<String, Object> headers; | ||
|
||
public BaseResponse(Response clientResponse) { | ||
if (clientResponse != null) { | ||
status = clientResponse.getStatus(); | ||
entity = clientResponse.readEntity(String.class); | ||
headers = clientResponse.getHeaders(); | ||
if (clientResponse.getLocation() != null) { | ||
location = clientResponse.getLocation().toString(); | ||
} | ||
} | ||
} | ||
|
||
public int getStatus() { | ||
return status; | ||
} | ||
|
||
public String getLocation() { | ||
return location; | ||
} | ||
|
||
public String getEntity() { | ||
return entity; | ||
} | ||
|
||
public MultivaluedMap<String, Object> getHeaders() { | ||
return headers; | ||
} | ||
|
||
public JSONObject getJSONEntity() { | ||
if (entity != null) { | ||
try { | ||
JSONObject jsonObject = new JSONObject(entity); | ||
return jsonObject; | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
Oops, something went wrong.