Example #1
0
        public string getRenderedContent(string issueKey, int issueType, int projectId, string markup)
        {
            var url = new StringBuilder(BaseUrl + "/rest/api/1.0/render");

            if (server.OldSkoolAuth)
            {
                url.Append(appendAuthentication(url.ToString()));
            }

            try {
                var req = (HttpWebRequest)WebRequest.Create(url.ToString());
                req.Proxy = server.NoProxy ? null : GlobalSettings.Proxy;

                req.Credentials      = CredentialUtils.getCredentialsForUserAndPassword(url.ToString(), UserName, Password);
                req.Method           = "POST";
                req.Timeout          = GlobalSettings.NetworkTimeout * 1000;
                req.ReadWriteTimeout = GlobalSettings.NetworkTimeout * 2000;
                req.ContentType      = "application/json";
                req.UserAgent        = Constants.USER_AGENT;

                loadLoginSessionCookies(req);
//                setSessionCookie(req);

                var requestStream = req.GetRequestStream();
                var encoding      = new ASCIIEncoding();

                object json = new {
                    rendererType     = "atlassian-wiki-renderer",
                    unrenderedMarkup = markup,
                    issueKey         = issueKey,
                    issueType        = issueType,
                    projectId        = projectId
                };

                var serialized = JsonConvert.SerializeObject(json);
                var buffer     = encoding.GetBytes(serialized);

                requestStream.Write(buffer, 0, buffer.Length);
                requestStream.Flush();
                requestStream.Close();

                var resp = (HttpWebResponse)req.GetResponse();

                storeLoginSessionCookies(req);

                var stream = resp.GetResponseStream();
                var text   = PlvsUtils.getTextDocument(stream);
                if (stream != null)
                {
                    stream.Close();
                }
                resp.Close();

                return(text);
            } catch (Exception e) {
                Debug.WriteLine(e.Message);
                throw;
            }
        }
        public IDictionary <string, string> login()
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(BaseUrl + "/Dashboard.jspa");

            req.Proxy            = dontUseProxy ? null : GlobalSettings.Proxy;
            req.Credentials      = CredentialUtils.getCredentialsForUserAndPassword(BaseUrl, UserName, Password);
            req.Timeout          = GlobalSettings.NetworkTimeout * 1000;
            req.ReadWriteTimeout = GlobalSettings.NetworkTimeout * 2000;
            req.Method           = "POST";

            req.ContentType = "application/x-www-form-urlencoded";
            string pars = getLoginPostData(UserName, Password);

            req.ContentLength = pars.Length;
            using (StreamWriter outStream = new StreamWriter(req.GetRequestStream(), Encoding.ASCII)) {
                outStream.Write(pars);
                outStream.Flush();
                outStream.Close();

                HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                using (resp.GetResponseStream()) {
                    if (!resp.StatusCode.Equals(HttpStatusCode.OK))
                    {
                        throw new LoginException(new Exception(resp.StatusDescription));
                    }

                    string cookies = resp.Headers["Set-Cookie"];
                    if (cookies == null)
                    {
                        throw new LoginException(new Exception(NO_SESSION_COOKIE));
                    }
                    string jSessionId       = getSessionToken(cookies, JSESSIONID);
                    string studioCrowdToken = getSessionToken(cookies, STUDIO_CROWD_TOKEN);
                    if (jSessionId == null && studioCrowdToken == null)
                    {
                        throw new LoginException(new Exception(NO_SESSION_COOKIE));
                    }
                    Dictionary <string, string> tokens = new Dictionary <string, string>();
                    if (jSessionId != null)
                    {
                        tokens[JSESSIONID] = jSessionId;
                    }
                    if (studioCrowdToken != null)
                    {
                        tokens[STUDIO_CROWD_TOKEN] = studioCrowdToken;
                    }
                    SessionTokens = tokens;
                    return(SessionTokens);
                }
            }
        }
        private void setBasicAuthHeader(string url, WebRequest req)
        {
            if (userName == null || password == null)
            {
                return;
            }
#if true
            req.Credentials = CredentialUtils.getCredentialsForUserAndPassword(url, userName, password);
#else
            string authInfo = CredentialUtils.getUserNameWithoutDomain(userName) + ":" + password;
            authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
            req.Headers["Authorization"] = "Basic " + authInfo;
#endif
        }
Example #4
0
        private static HttpWebResponse getResponse(Server server, string url)
        {
            string authUrl = server == null ? url : url + "?" + CredentialUtils.getOsAuthString(server);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(authUrl);

            request.KeepAlive = true;

            if (server != null)
            {
                request.Credentials = CredentialUtils.getCredentialsForUserAndPassword(url, server.UserName, server.Password);
            }

            request.Accept = @"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            return(response);
        }
Example #5
0
        private Stream getRssQueryResultStream(StringBuilder url)
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url.ToString());

            req.Proxy            = server.NoProxy ? null : GlobalSettings.Proxy;
            req.Credentials      = CredentialUtils.getCredentialsForUserAndPassword(url.ToString(), UserName, Password);
            req.Timeout          = GlobalSettings.NetworkTimeout * 1000;
            req.ReadWriteTimeout = GlobalSettings.NetworkTimeout * 2000;
            req.UserAgent        = Constants.USER_AGENT;

            if (!server.OldSkoolAuth)
            {
                setSessionCookie(req);
            }

            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

            return(resp.GetResponseStream());
        }