@@ -49,39 +49,97 @@ private HttpClient(Client httpClient, String principal, String encodedCredential
4949 this .encodedCredentials = encodedCredentials ;
5050 }
5151
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 ) {
5462 String url = serviceURL + requestUrl ;
5563 WebTarget target = httpClient .target (url );
5664 Invocation .Builder invocationBuilder = target .request ().accept ("application/json" )
5765 .header ("Authorization" , "Basic " + encodedCredentials );
5866 Response response = invocationBuilder .get ();
67+ String responseString = null ;
68+ int status = response .getStatus ();
69+ boolean successful = false ;
5970 if (response .getStatusInfo ().getFamily () == Response .Status .Family .SUCCESSFUL ) {
71+ successful = true ;
6072 if (response .hasEntity ()) {
61- return String .valueOf (response .readEntity (String .class ));
73+ responseString = String .valueOf (response .readEntity (String .class ));
6274 }
6375 } else {
6476 LOGGER .warning (MessageKeys .HTTP_METHOD_FAILED , "GET" , url , response .getStatus ());
6577 }
66- return null ;
78+ return new Result ( responseString , status , successful ) ;
6779 }
6880
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+
70121 String url = serviceURL + requestUrl ;
71122 WebTarget target = httpClient .target (url );
72123 Invocation .Builder invocationBuilder = target .request ().accept ("application/json" )
73124 .header ("Authorization" , "Basic " + encodedCredentials )
74125 .header ("X-Requested-By" , "WebLogicOperator" );
75126 Response response = invocationBuilder .post (Entity .json (payload ));
76127 LOGGER .finer ("Response is " + response .getStatusInfo ());
128+ String responseString = null ;
129+ int status = response .getStatus ();
130+ boolean successful = false ;
77131 if (response .getStatusInfo ().getFamily () == Response .Status .Family .SUCCESSFUL ) {
132+ successful = true ;
78133 if (response .hasEntity ()) {
79- return String .valueOf (response .readEntity (String .class ));
134+ responseString = String .valueOf (response .readEntity (String .class ));
80135 }
81136 } else {
82137 LOGGER .warning (MessageKeys .HTTP_METHOD_FAILED , "POST" , url , response .getStatus ());
138+ if (throwOnFailure ) {
139+ throw new HTTPException (status );
140+ }
83141 }
84- return null ;
142+ return new Result ( responseString , status , successful ) ;
85143 }
86144
87145 /**
0 commit comments