-
Notifications
You must be signed in to change notification settings - Fork 0
/
activity.go
63 lines (46 loc) · 1.43 KB
/
activity.go
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
package flogogetcontent
import (
"fmt"
"io/ioutil"
"net/http"
"github.com/TIBCOSoftware/flogo-lib/core/activity"
"github.com/TIBCOSoftware/flogo-lib/logger"
)
// activityLog is the default logger for the exec Activity
var log = logger.GetLogger("activity-tibco-flogogetcontent")
// Create client
var client = &http.Client{}
type GetcontentActivity struct {
metadata *activity.Metadata
}
// NewActivity creates a new AppActivity
func NewActivity(metadata *activity.Metadata) activity.Activity {
return &GetcontentActivity{metadata: metadata}
}
// Metadata returns the activity's metadata
func (a *GetcontentActivity) Metadata() *activity.Metadata {
return a.metadata
}
func (a *GetcontentActivity) Eval(context activity.Context) (done bool, err error) {
basicAuthUser, _ := context.GetInput("basicAuthUser").(string)
basicAuthPassword, _ := context.GetInput("basicAuthPassword").(string)
url, _ := context.GetInput("URL").(string)
// Create request
req, err := http.NewRequest("GET", url, nil)
if basicAuthUser != "" {
req.SetBasicAuth(basicAuthUser, basicAuthPassword)
}
// Fetch Request
resp, err := client.Do(req)
if err != nil {
fmt.Println("Failure : ", err)
}
// Read Response Body
respBody, _ := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
// Add Results
context.SetOutput("result", string(respBody))
context.SetOutput("status", resp.Status)
context.SetOutput("header", resp.Header)
return true, nil
}