Skip to content

Commit

Permalink
Merge pull request #3 from Hi-Fi/release/0.0.1
Browse files Browse the repository at this point in the history
Release/0.0.1
  • Loading branch information
Hi-Fi authored Jan 18, 2017
2 parents 575ed3c + 724d23a commit 668d631
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.hi-fi</groupId>
<artifactId>robotframework-httprequestlibrary</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.1</version>
<packaging>jar</packaging>

<name>robotframework-httprequestlibrary</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.hi_fi.httprequestlibrary.domain;

import java.io.IOException;
import java.util.Map;

import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
Expand All @@ -19,6 +20,7 @@ public class Session {
private Authentication authentication;
private HttpHost httpHost;
private String verify;
private Map<String, String> headers;

public String getAlias() {
return alias;
Expand Down Expand Up @@ -106,4 +108,12 @@ public String getVerify() {
public void setVerify(String verify) {
this.verify = verify;
}

public Map<String, String> getHeaders() {
return headers;
}

public void setHeaders(Map<String, String> headers) {
this.headers = headers;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.github.hi_fi.httprequestlibrary.keywords;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.robotframework.javalib.annotation.ArgumentNames;
import org.robotframework.javalib.annotation.RobotKeyword;
Expand All @@ -18,20 +20,22 @@ public class Session {
@ArgumentNames({"alias", "url", "headers={}", "cookies=None", "auth=None", "timeout=None", "proxies=None", "verify=False", "debug=False", "max_retries=3", "backoff_factor=0.1", "disable_warnings=0"})
public void createSession(String alias, String url, String...params) {
RestClient rc = new RestClient();
Map<String, String> headers = Robot.getParamsValue(params, 0, new HashMap<String, String>());
String verify = Robot.getParamsValue(params, 5, "False");
Boolean debug = Boolean.parseBoolean(Robot.getParamsValue(params, 6, "False"));
Authentication auth = Authentication.getAuthentication(Robot.getParamsValue(params, 2, (List<String>) new ArrayList<String>()));
rc.createSession(alias, url, auth, verify, debug);
rc.createSession(alias, url, headers, auth, verify, debug);
}

@RobotKeyword
@ArgumentNames({"alias", "url", "headers={}", "cookies=None", "auth=None", "timeout=None", "proxies=None", "verify=False", "debug=False", "max_retries=3", "backoff_factor=0.1", "disable_warnings=0"})
public void createDigestSession(String alias, String url, String...params) {
RestClient rc = new RestClient();
Map<String, String> headers = Robot.getParamsValue(params, 0, new HashMap<String, String>());
String verify = Robot.getParamsValue(params, 5, "False");
Boolean debug = Boolean.parseBoolean(Robot.getParamsValue(params, 6, "False"));
Authentication auth = Authentication.getAuthentication(Robot.getParamsValue(params, 2, (List<String>) new ArrayList<String>()), Authentication.Type.DIGEST);
rc.createSession(alias, url, auth, verify, debug);
rc.createSession(alias, url, headers, auth, verify, debug);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Session getSession(String alias) {
return sessions.get(alias);
}

public void createSession(String alias, String url, Authentication auth, String verify, Boolean debug) {
public void createSession(String alias, String url, Map<String, String> headers, Authentication auth, String verify, Boolean debug) {
if (debug) {
System.setProperty("org.apache.commons.logging.Log",
"com.github.hi_fi.httprequestlibrary.utils.RobotLogger");
Expand All @@ -72,6 +72,7 @@ public void createSession(String alias, String url, Authentication auth, String
session.setContext(this.createContext(auth, target));
session.setClient(this.createHttpClient(auth, verify, target, false));
session.setUrl(url);
session.setHeaders(headers);
session.setHttpHost(target);
session.setVerify(verify);
session.setAuthentication(auth);
Expand Down Expand Up @@ -141,6 +142,7 @@ private HttpEntity createFileEntity(Object files) {
}

private void makeRequest(HttpUriRequest request, Session session) {
request = this.setHeaders(request, session.getHeaders());
try {
session.setResponse(session.getClient().execute(request, session.getContext()));
} catch (ClientProtocolException e) {
Expand Down

0 comments on commit 668d631

Please sign in to comment.