5555import java .util .Arrays ;
5656import java .util .Optional ;
5757import java .util .Random ;
58- import java .util .function .BiConsumer ;
59- import java .util .function .Consumer ;
6058import java .util .function .Supplier ;
6159import org .joda .time .Duration ;
6260
@@ -118,19 +116,13 @@ public ImmutableList<Task> enqueue(String queue, Task... tasks) {
118116 * <p>For GET requests we add them on to the URL, and for POST requests we add them in the body of
119117 * the request.
120118 *
121- * <p>The parameters {@code putHeadersFunction} and {@code setBodyFunction} are used so that this
122- * method can be called with either an AppEngine HTTP request or a standard non-AppEngine HTTP
123- * request. The two objects do not have the same methods, but both have ways of setting headers /
124- * body.
125- *
126119 * @return the resulting path (unchanged for POST requests, with params added for GET requests)
127120 */
128121 private static String processRequestParameters (
129122 String path ,
130123 Method method ,
131124 Multimap <String , String > params ,
132- BiConsumer <String , String > putHeadersFunction ,
133- Consumer <ByteString > setBodyFunction ) {
125+ HttpRequest .Builder requestBuilder ) {
134126 if (CollectionUtils .isNullOrEmpty (params )) {
135127 return path ;
136128 }
@@ -148,8 +140,8 @@ private static String processRequestParameters(
148140 if (method .equals (Method .GET )) {
149141 return String .format ("%s?%s" , path , encodedParams );
150142 }
151- putHeadersFunction . accept (HttpHeaders .CONTENT_TYPE , MediaType .FORM_DATA .toString ());
152- setBodyFunction . accept (ByteString .copyFrom (encodedParams , StandardCharsets .UTF_8 ));
143+ requestBuilder . putHeaders (HttpHeaders .CONTENT_TYPE , MediaType .FORM_DATA .toString ());
144+ requestBuilder . setBody (ByteString .copyFrom (encodedParams , StandardCharsets .UTF_8 ));
153145 return path ;
154146 }
155147
@@ -160,18 +152,17 @@ private static String processRequestParameters(
160152 * default service account as the principal. That account must have permission to submit tasks to
161153 * Cloud Tasks.
162154 *
163- * <p>The caller of this method is responsible for passing in the appropriate service based on the
164- * runtime (GAE/GKE). Use the overload that takes an action class if possible.
155+ * <p>The caller of this method is responsible for passing in the appropriate service. Use the
156+ * overload that takes an action class if possible.
165157 *
166158 * @param path the relative URI (staring with a slash and ending without one).
167159 * @param method the HTTP method to be used for the request.
168- * @param service the GAE/GKE service to route the request to.
160+ * @param service the service to route the request to.
169161 * @param params a multimap of URL query parameters. Duplicate keys are saved as is, and it is up
170162 * to the server to process the duplicate keys.
171163 * @return the enqueued task.
172- * @see <a
173- * href=ttps://cloud.google.com/appengine/docs/standard/java/taskqueue/push/creating-tasks#target>Specifyinig
174- * the worker service</a>
164+ * @see <a href=https://docs.cloud.google.com/tasks/docs/creating-http-target-tasks#java>Creating
165+ * HTTP target tasks</a>
175166 */
176167 protected Task createTask (
177168 String path , Method method , Action .Service service , Multimap <String , String > params ) {
@@ -180,9 +171,7 @@ protected Task createTask(
180171 "The path must start with a '/'." );
181172 HttpRequest .Builder requestBuilder =
182173 HttpRequest .newBuilder ().setHttpMethod (HttpMethod .valueOf (method .name ()));
183- path =
184- processRequestParameters (
185- path , method , params , requestBuilder ::putHeaders , requestBuilder ::setBody );
174+ path = processRequestParameters (path , method , params , requestBuilder );
186175 OidcToken .Builder oidcTokenBuilder =
187176 OidcToken .newBuilder ()
188177 .setServiceAccountEmail (credential .serviceAccount ())
@@ -204,16 +193,15 @@ protected Task createTask(
204193 * Cloud Tasks.
205194 *
206195 * <p>Prefer this overload over the one where the path and service are explicitly defined, as this
207- * class will automatically determine the service to use based on the action and the runtime .
196+ * class will automatically determine the service to use based on the action.
208197 *
209198 * @param actionClazz the action class to run, must be annotated with {@link Action}.
210199 * @param method the HTTP method to be used for the request.
211200 * @param params a multimap of URL query parameters. Duplicate keys are saved as is, and it is up
212201 * to the server to process the duplicate keys.
213202 * @return the enqueued task.
214- * @see <a
215- * href=ttps://cloud.google.com/appengine/docs/standard/java/taskqueue/push/creating-tasks#target>Specifyinig
216- * the worker service</a>
203+ * @see <a href=https://docs.cloud.google.com/tasks/docs/creating-http-target-tasks#java>Creating
204+ * HTTP target tasks</a>
217205 */
218206 public Task createTask (
219207 Class <? extends Runnable > actionClazz , Method method , Multimap <String , String > params ) {
@@ -236,19 +224,18 @@ public Task createTask(
236224 /**
237225 * Create a {@link Task} to be enqueued with a random delay up to {@code jitterSeconds}.
238226 *
239- * <p>The caller of this method is responsible for passing in the appropriate service based on the
240- * runtime (GAE/GKE). Use the overload that takes an action class if possible.
227+ * <p>The caller of this method is responsible for passing in the appropriate service. Use the
228+ * overload that takes an action class if possible.
241229 *
242230 * @param path the relative URI (staring with a slash and ending without one).
243231 * @param method the HTTP method to be used for the request.
244- * @param service the GAE/GKE service to route the request to.
232+ * @param service the service to route the request to.
245233 * @param params a multimap of URL query parameters. Duplicate keys are saved as is, and it is up
246234 * to the server to process the duplicate keys.
247235 * @param jitterSeconds the number of seconds that a task is randomly delayed up to.
248236 * @return the enqueued task.
249- * @see <a
250- * href=ttps://cloud.google.com/appengine/docs/standard/java/taskqueue/push/creating-tasks#target>Specifyinig
251- * the worker service</a>
237+ * @see <a href=https://docs.cloud.google.com/tasks/docs/creating-http-target-tasks#java>Creating
238+ * HTTP target tasks</a>
252239 */
253240 public Task createTaskWithJitter (
254241 String path ,
@@ -271,17 +258,16 @@ public Task createTaskWithJitter(
271258 * Create a {@link Task} to be enqueued with a random delay up to {@code jitterSeconds}.
272259 *
273260 * <p>Prefer this overload over the one where the path and service are explicitly defined, as this
274- * class will automatically determine the service to use based on the action and the runtime .
261+ * class will automatically determine the service to use based on the action.
275262 *
276263 * @param actionClazz the action class to run, must be annotated with {@link Action}.
277264 * @param method the HTTP method to be used for the request.
278265 * @param params a multimap of URL query parameters. Duplicate keys are saved as is, and it is up
279266 * to the server to process the duplicate keys.
280267 * @param jitterSeconds the number of seconds that a task is randomly delayed up to.
281268 * @return the enqueued task.
282- * @see <a
283- * href=ttps://cloud.google.com/appengine/docs/standard/java/taskqueue/push/creating-tasks#target>Specifyinig
284- * the worker service</a>
269+ * @see <a href=https://docs.cloud.google.com/tasks/docs/creating-http-target-tasks#java>Creating
270+ * HTTP target tasks</a>
285271 */
286272 public Task createTaskWithJitter (
287273 Class <? extends Runnable > actionClazz ,
@@ -302,14 +288,13 @@ public Task createTaskWithJitter(
302288 *
303289 * @param path the relative URI (staring with a slash and ending without one).
304290 * @param method the HTTP method to be used for the request.
305- * @param service the GAE/GKE service to route the request to.
291+ * @param service the service to route the request to.
306292 * @param params a multimap of URL query parameters. Duplicate keys are saved as is, and it is up
307293 * to the server to process the duplicate keys.
308294 * @param delay the amount of time that a task needs to be delayed for.
309295 * @return the enqueued task.
310- * @see <a
311- * href=ttps://cloud.google.com/appengine/docs/standard/java/taskqueue/push/creating-tasks#target>Specifyinig
312- * the worker service</a>
296+ * @see <a href=https://docs.cloud.google.com/tasks/docs/creating-http-target-tasks#java>Creating
297+ * HTTP target tasks</a>
313298 */
314299 private Task createTaskWithDelay (
315300 String path ,
@@ -330,17 +315,16 @@ private Task createTaskWithDelay(
330315 * Create a {@link Task} to be enqueued with delay of {@code duration}.
331316 *
332317 * <p>Prefer this overload over the one where the path and service are explicitly defined, as this
333- * class will automatically determine the service to use based on the action and the runtime .
318+ * class will automatically determine the service to use based on the action.
334319 *
335320 * @param actionClazz the action class to run, must be annotated with {@link Action}.
336321 * @param method the HTTP method to be used for the request.
337322 * @param params a multimap of URL query parameters. Duplicate keys are saved as is, and it is up
338323 * to the server to process the duplicate keys.
339324 * @param delay the amount of time that a task needs to be delayed for.
340325 * @return the enqueued task.
341- * @see <a
342- * href=ttps://cloud.google.com/appengine/docs/standard/java/taskqueue/push/creating-tasks#target>Specifyinig
343- * the worker service</a>
326+ * @see <a href=https://docs.cloud.google.com/tasks/docs/creating-http-target-tasks#java>Creating
327+ * HTTP target tasks</a>
344328 */
345329 public Task createTaskWithDelay (
346330 Class <? extends Runnable > actionClazz ,
0 commit comments