forked from liferay/liferay-portal
/
StatusResource.java
180 lines (132 loc) · 4.41 KB
/
StatusResource.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.segments.asah.rest.client.resource.v1_0;
import com.liferay.segments.asah.rest.client.dto.v1_0.Status;
import com.liferay.segments.asah.rest.client.http.HttpInvoker;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Generated;
/**
* @author Javier Gamarra
* @generated
*/
@Generated("")
public interface StatusResource {
public static Builder builder() {
return new Builder();
}
public com.liferay.segments.asah.rest.client.dto.v1_0.Experiment
postExperimentStatus(Long experimentId, Status status)
throws Exception;
public HttpInvoker.HttpResponse postExperimentStatusHttpResponse(
Long experimentId, Status status)
throws Exception;
public static class Builder {
public Builder authentication(String login, String password) {
_login = login;
_password = password;
return this;
}
public StatusResource build() {
return new StatusResourceImpl(this);
}
public Builder endpoint(String host, int port, String scheme) {
_host = host;
_port = port;
_scheme = scheme;
return this;
}
public Builder header(String key, String value) {
_headers.put(key, value);
return this;
}
public Builder locale(Locale locale) {
_locale = locale;
return this;
}
public Builder parameter(String key, String value) {
_parameters.put(key, value);
return this;
}
private Builder() {
}
private Map<String, String> _headers = new LinkedHashMap<>();
private String _host = "localhost";
private Locale _locale;
private String _login = "test@liferay.com";
private String _password = "test";
private Map<String, String> _parameters = new LinkedHashMap<>();
private int _port = 8080;
private String _scheme = "http";
}
public static class StatusResourceImpl implements StatusResource {
public com.liferay.segments.asah.rest.client.dto.v1_0.Experiment
postExperimentStatus(Long experimentId, Status status)
throws Exception {
HttpInvoker.HttpResponse httpResponse =
postExperimentStatusHttpResponse(experimentId, status);
String content = httpResponse.getContent();
_logger.fine("HTTP response content: " + content);
_logger.fine("HTTP response message: " + httpResponse.getMessage());
_logger.fine(
"HTTP response status code: " + httpResponse.getStatusCode());
try {
return com.liferay.segments.asah.rest.client.serdes.v1_0.
ExperimentSerDes.toDTO(content);
}
catch (Exception e) {
_logger.log(
Level.WARNING,
"Unable to process HTTP response: " + content, e);
throw e;
}
}
public HttpInvoker.HttpResponse postExperimentStatusHttpResponse(
Long experimentId, Status status)
throws Exception {
HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
httpInvoker.body(status.toString(), "application/json");
if (_builder._locale != null) {
httpInvoker.header(
"Accept-Language", _builder._locale.toLanguageTag());
}
for (Map.Entry<String, String> entry :
_builder._headers.entrySet()) {
httpInvoker.header(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, String> entry :
_builder._parameters.entrySet()) {
httpInvoker.parameter(entry.getKey(), entry.getValue());
}
httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
httpInvoker.path(
_builder._scheme + "://" + _builder._host + ":" +
_builder._port +
"/o/segments-asah/v1.0/experiments/{experimentId}/status",
experimentId);
httpInvoker.userNameAndPassword(
_builder._login + ":" + _builder._password);
return httpInvoker.invoke();
}
private StatusResourceImpl(Builder builder) {
_builder = builder;
}
private static final Logger _logger = Logger.getLogger(
StatusResource.class.getName());
private Builder _builder;
}
}