@@ -49,39 +49,97 @@ private HttpClient(Client httpClient, String principal, String encodedCredential
49
49
this .encodedCredentials = encodedCredentials ;
50
50
}
51
51
52
- public String executeGetOnServiceClusterIP (String requestUrl , String serviceName , String namespace ) {
53
- String serviceURL = SERVICE_URL == null ? getServiceURL (principal , serviceName , namespace ) : SERVICE_URL ;
52
+ /**
53
+ * Constructs a URL using the provided service URL and request URL, and use the resulting URL to issue a HTTP GET request
54
+ *
55
+ * @param requestUrl The request URL containing the request of the REST call
56
+ * @param serviceURL The service URL containing the host and port of the server where the HTTP
57
+ * request is to be sent to
58
+ *
59
+ * @return A Result object containing the respond from the REST call
60
+ */
61
+ public Result executeGetOnServiceClusterIP (String requestUrl , String serviceURL ) {
54
62
String url = serviceURL + requestUrl ;
55
63
WebTarget target = httpClient .target (url );
56
64
Invocation .Builder invocationBuilder = target .request ().accept ("application/json" )
57
65
.header ("Authorization" , "Basic " + encodedCredentials );
58
66
Response response = invocationBuilder .get ();
67
+ String responseString = null ;
68
+ int status = response .getStatus ();
69
+ boolean successful = false ;
59
70
if (response .getStatusInfo ().getFamily () == Response .Status .Family .SUCCESSFUL ) {
71
+ successful = true ;
60
72
if (response .hasEntity ()) {
61
- return String .valueOf (response .readEntity (String .class ));
73
+ responseString = String .valueOf (response .readEntity (String .class ));
62
74
}
63
75
} else {
64
76
LOGGER .warning (MessageKeys .HTTP_METHOD_FAILED , "GET" , url , response .getStatus ());
65
77
}
66
- return null ;
78
+ return new Result ( responseString , status , successful ) ;
67
79
}
68
80
69
- public String executePostUrlOnServiceClusterIP (String requestUrl , String serviceURL , String namespace , String payload ) {
81
+ /**
82
+ * Constructs a URL using the provided service URL and request URL, and use the resulting URL and the
83
+ * payload provided to issue a HTTP POST request.
84
+ * This method does not throw HTTPException if the HTTP request returns failure status code
85
+ *
86
+ * @param requestUrl The request URL containing the request of the REST call
87
+ * @param serviceURL The service URL containing the host and port of the server where the HTTP
88
+ * request is to be sent to
89
+ * @param payload The payload to be used in the HTTP POST request
90
+ *
91
+ * @return A Result object containing the respond from the REST call
92
+ * @throws HTTPException if throwOnFailure is true and the status of the HTTP response indicates the request was not
93
+ * successful
94
+ */ public Result executePostUrlOnServiceClusterIP (String requestUrl , String serviceURL , String payload ) {
95
+ Result result = null ;
96
+ try {
97
+ result = executePostUrlOnServiceClusterIP (requestUrl , serviceURL , payload , false );
98
+ } catch (HTTPException httpException ) {
99
+ // ignore as executePostUrlOnServiceClusterIP only throw HTTPException if throwOnFailure is true
100
+ }
101
+ return result ;
102
+ }
103
+
104
+ /**
105
+ * Constructs a URL using the provided service URL and request URL, and use the resulting URL and the
106
+ * payload provided to issue a HTTP POST request
107
+ *
108
+ * @param requestUrl The request URL containing the request of the REST call
109
+ * @param serviceURL The service URL containing the host and port of the server where the HTTP
110
+ * request is to be sent to
111
+ * @param payload The payload to be used in the HTTP POST request
112
+ * @param throwOnFailure Throws HTTPException if the status code in the HTTP response indicates any error
113
+ *
114
+ * @return A Result object containing the respond from the REST call
115
+ * @throws HTTPException if throwOnFailure is true and the status of the HTTP response indicates the request was not
116
+ * successful
117
+ */
118
+ public Result executePostUrlOnServiceClusterIP (String requestUrl , String serviceURL , String payload ,
119
+ boolean throwOnFailure ) throws HTTPException {
120
+
70
121
String url = serviceURL + requestUrl ;
71
122
WebTarget target = httpClient .target (url );
72
123
Invocation .Builder invocationBuilder = target .request ().accept ("application/json" )
73
124
.header ("Authorization" , "Basic " + encodedCredentials )
74
125
.header ("X-Requested-By" , "WebLogicOperator" );
75
126
Response response = invocationBuilder .post (Entity .json (payload ));
76
127
LOGGER .finer ("Response is " + response .getStatusInfo ());
128
+ String responseString = null ;
129
+ int status = response .getStatus ();
130
+ boolean successful = false ;
77
131
if (response .getStatusInfo ().getFamily () == Response .Status .Family .SUCCESSFUL ) {
132
+ successful = true ;
78
133
if (response .hasEntity ()) {
79
- return String .valueOf (response .readEntity (String .class ));
134
+ responseString = String .valueOf (response .readEntity (String .class ));
80
135
}
81
136
} else {
82
137
LOGGER .warning (MessageKeys .HTTP_METHOD_FAILED , "POST" , url , response .getStatus ());
138
+ if (throwOnFailure ) {
139
+ throw new HTTPException (status );
140
+ }
83
141
}
84
- return null ;
142
+ return new Result ( responseString , status , successful ) ;
85
143
}
86
144
87
145
/**
0 commit comments