ahgittin commented on code in PR #1363:
URL: https://github.com/apache/brooklyn-server/pull/1363#discussion_r999124334


##########
core/src/main/java/org/apache/brooklyn/core/workflow/steps/HttpWorkflowStep.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.workflow.steps;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.google.common.reflect.TypeToken;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.config.MapConfigKey;
+import org.apache.brooklyn.core.resolve.jackson.BeanWithTypeUtils;
+import org.apache.brooklyn.core.workflow.WorkflowStepDefinition;
+import org.apache.brooklyn.core.workflow.WorkflowStepInstanceExecutionContext;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.core.javalang.BrooklynHttpConfig;
+import org.apache.brooklyn.util.core.json.ShellEnvironmentSerializer;
+import org.apache.brooklyn.util.core.predicates.DslPredicates;
+import org.apache.brooklyn.util.core.task.system.ProcessTaskWrapper;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.http.HttpTool;
+import org.apache.brooklyn.util.http.auth.UsernamePassword;
+import org.apache.brooklyn.util.http.executor.HttpExecutor;
+import org.apache.brooklyn.util.http.executor.HttpRequest;
+import org.apache.brooklyn.util.http.executor.HttpResponse;
+import org.apache.brooklyn.util.net.Urls;
+import org.apache.brooklyn.util.stream.Streams;
+import org.apache.brooklyn.util.text.Strings;
+import org.apache.brooklyn.util.time.Duration;
+import org.apache.http.client.utils.URIBuilder;
+
+import java.io.IOException;
+import java.lang.reflect.Array;
+import java.net.URISyntaxException;
+import java.nio.charset.Charset;
+import java.util.Map;
+import java.util.function.Predicate;
+
+public class HttpWorkflowStep extends WorkflowStepDefinition {
+
+    public static final String SHORTHAND = "${endpoint}";
+
+    public static final ConfigKey<String> ENDPOINT = 
ConfigKeys.newStringConfigKey("endpoint");
+    public static final ConfigKey<Map<String,Object>> QUERY = new 
MapConfigKey.Builder(Object.class, "query").build();
+    public static final ConfigKey<Object> BODY = 
ConfigKeys.newConfigKey(Object.class, "body");
+    public static final ConfigKey<String> CHARSET = 
ConfigKeys.newStringConfigKey("charset", "Character set to interpret content as 
when converting to string, and for converting body to bytes to upload if body 
is set");
+    public static final ConfigKey<DslPredicates.DslPredicate<Integer>> 
STATUS_CODE = ConfigKeys.newConfigKey(new 
TypeToken<DslPredicates.DslPredicate<Integer>>() {}, "status-code");
+    public static final ConfigKey<Map<String, String>> HEADERS = new 
MapConfigKey<>(String.class, "headers");
+    public static final ConfigKey<String> METHOD = 
ConfigKeys.newStringConfigKey("method");
+
+    public static final ConfigKey<String> USERNAME = 
ConfigKeys.newStringConfigKey("username", "Username for HTTP request, if 
required");
+    public static final ConfigKey<String> PASSWORD = 
ConfigKeys.newStringConfigKey("password", "Password for HTTP request, if 
required");
+
+
+    // used for http feed, but not sure needed
+//    public static final ConfigKey<Boolean> PREEMPTIVE_BASIC_AUTH = 
ConfigKeys.newBooleanConfigKey(
+//            "preemptiveBasicAuth",
+//            "Whether to pre-emptively including a basic-auth header of the 
username:password (rather than waiting for a challenge)",
+//            Boolean.FALSE);
+
+    @Override
+    public void populateFromShorthand(String expression) {
+        populateFromShorthandTemplate(SHORTHAND, expression);
+    }
+
+    @Override
+    protected Object doTaskBody(WorkflowStepInstanceExecutionContext context) {
+        String endpoint = context.getInput(ENDPOINT);
+        if (Strings.isBlank(endpoint)) {
+            throw new IllegalStateException("Endpoint required for http step");
+        }
+        String proto = Urls.getProtocol(endpoint);
+        if (proto==null) {
+            endpoint = "https://"+endpoint;
+        }
+
+        HttpRequest.Builder httpb = new HttpRequest.Builder();

Review Comment:
   @jcabrerizo great idea.  i've added a `config` key which lets you set 
`trustAll` etc.
   
   note you can also to set these properties on the entity or brooklyn.config 
(from `BrooklynHttpConfig`):
   
   ```
       public static final String HTTPS_CONFIG = "brooklyn.https.config.";
       public static final ConfigKey<Boolean> TRUST_ALL = 
ConfigKeys.newBooleanConfigKey(HTTPS_CONFIG + "trustAll",
           "Whether HTTPS and TLS connections should trust all certificates");
       public static final ConfigKey<Boolean> TRUST_SELF_SIGNED = 
ConfigKeys.newBooleanConfigKey(HTTPS_CONFIG + "trustSelfSigned",
               "Whether HTTPS and TLS connections should trust self-signed 
certificates");
       public static final ConfigKey<Boolean> LAX_REDIRECT = 
ConfigKeys.newBooleanConfigKey(HTTPS_CONFIG + "laxRedirect",
               "Whether HTTPS and TLS connections should be lax about 
redirecting");
   ```
   
   (i fixed an issue where these were not always used, and added tests for 
https)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to