Skip to content

Commit

Permalink
v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
onurciner committed Dec 26, 2016
1 parent e817fe9 commit 97b74be
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,52 @@ public class WebServiceGetData {
private Integer readTimeout = 20000;
private Integer connectTimeout = 30000;
private String urlString = null;
private String character = "UTF-8";

private ArrayList<String> requestPropertyKey = new ArrayList<>();
private ArrayList<String> requestPropertyValue = new ArrayList<>();
private String requestPropertyType = null;

public WebServiceGetData setUrl(String url) {
this.urlString = url;
return this;
}

public WebServiceGetData setRequestProperty(RequestPropertyType requestPropertyType) {
if (requestPropertyType.equals(RequestPropertyType.APPLICATION_JSON))
this.requestPropertyType = "application/json";
else if (requestPropertyType.equals(RequestPropertyType.MULTIPART_FORM_DATA))
this.requestPropertyType = "multipart-form-data";
else if (requestPropertyType.equals(RequestPropertyType.APPLICATION_X_WWW_FORM_URLENCODED))
this.requestPropertyType = "application/x-www-form-urlencoded";
else if (requestPropertyType.equals(RequestPropertyType.APPLICATION_XML))
this.requestPropertyType = "application/xml";
else if (requestPropertyType.equals(RequestPropertyType.APPLICATION_BASE64))
this.requestPropertyType = "application/base64";
else if (requestPropertyType.equals(RequestPropertyType.APPLICATION_OCTET_STREAM))
this.requestPropertyType = "application/octet-stream";
else if (requestPropertyType.equals(RequestPropertyType.TEXT_PLAIN))
this.requestPropertyType = "text/plain";
else if (requestPropertyType.equals(RequestPropertyType.TEXT_CSS))
this.requestPropertyType = "text/css";
else if (requestPropertyType.equals(RequestPropertyType.TEXT_HTML))
this.requestPropertyType = "text/html";
else if (requestPropertyType.equals(RequestPropertyType.APPLICATION_JAVASCRIPT))
this.requestPropertyType = "application/javascript";
return this;
}

public WebServiceGetData setRequestProperty(String key, String value) {
this.requestPropertyKey.add(key);
this.requestPropertyValue.add(value);
return this;
}

public WebServiceGetData setCharacter(String character) {
this.character = character;
return this;
}

public WebServiceGetData setRequestMethod(MethodType methodType) {
if (methodType.equals(MethodType.GET))
requestMethod = "GET";
Expand Down Expand Up @@ -74,6 +114,13 @@ public Object connect() throws IOException {
urlConnection.setRequestMethod(requestMethod);
urlConnection.setReadTimeout(readTimeout);
urlConnection.setConnectTimeout(connectTimeout);

if (requestPropertyType != null)
urlConnection.setRequestProperty("Content-Type", requestPropertyType);
for (int i = 0; i < requestPropertyKey.size(); i++) {
urlConnection.setRequestProperty(requestPropertyKey.get(i), requestPropertyValue.get(i));
}

urlConnection.setDoOutput(true);
urlConnection.connect();

Expand Down

0 comments on commit 97b74be

Please sign in to comment.