It's all about the answers!

Ask a question

RQM api interogation with Golang


Ionut Nechita (11) | asked Feb 17 '20, 1:18 p.m.

 I try to inspect with Golang this RQM.


My code is:
package main

import (
"net/http"
"net/url"
"fmt"
"log"
"io/ioutil"
"crypto/tls"
"crypto/x509"
"strings"
"strconv"
)

func main() {
fmt.Println("Start program. ")
caCert, err := ioutil.ReadFile("rqm_certs.crt")

if err != nil {
log.Fatal(err)
}
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)


tr := &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs:      caCertPool,
InsecureSkipVerify: true,
},
}
client := &http.Client{
Transport: tr,
}
data := url.Values{}
data.Set("j_username", "test1")
data.Set("j_password", "test2")


req, err := http.NewRequest("POST", "https://test-server-jazz.example.com/rqm001/j_security_check", strings.NewReader(data.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Cookie", "JazzFormAuth=Form; Path=/rqm001; Secure")
req.Header.Set("OSLC-Core-Version", "3.0")
req.Header.Set("Accept", "application/xml")
req.Header.Set("Content-Length", strconv.Itoa(len(data.Encode())))
req.Header.Set("Configuration-Context", "_NQfiQI8PEeelKpQbl_90kA")
if err != nil {
log.Println(err)
}
resp, err := client.Do(req)
if err != nil {
log.Println(err)
}

f, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Println(err)
}
resp.Body.Close()
if err != nil {
log.Fatal(err)
}
fmt.Println(string(f))
fmt.Println(resp.Status)
}

But with inspect, this message appear:
net.jazz.ajax.ui.PlatformUI.createAndRunWorkbench("net.jazz.web.app.authrequired");

Does anyone know what the problem is here?
I tried other ways, but it gives me this error.


One answer



permanent link
Ian Barnard (2.3k714) | answered Feb 18 '20, 8:46 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Feb 18 '20, 8:47 a.m.
You aren't authenticating properly - you should probably do a GET from the j_security_check before doing the POST. Or do a GET from a protected resource (e.g. https://server:port/qm/authenticated/identity) and you will be forced into authentication sequence - once the POST gets a 200, repeat the GET and it should work with a 200.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.