Skip to content

Commit

Permalink
Related to: JENKINS-36829 - empty rootURL causes an error with sse (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
kzantow authored and tfennelly committed Aug 25, 2016
1 parent f012d51 commit ca1826b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/main/js/sse-client.js
Expand Up @@ -73,12 +73,13 @@ function scheduleDoConfigure(delay) {
}
function discoverJenkinsUrl() {
jenkinsUrl = jsModules.getRootURL();

if (!jenkinsUrl || jenkinsUrl.length < 1) {
throw new Error('Invalid jenkinsUrl argument ' + jenkinsUrl);
}
if (jenkinsUrl.charAt(jenkinsUrl.length - 1) !== '/') {
jenkinsUrl += '/';
if (!jenkinsUrl) {
jenkinsUrl = '';
} else {
// only in tests, this is suffixed ...
while (jenkinsUrl.charAt(jenkinsUrl.length - 1) === '/') {
jenkinsUrl = jenkinsUrl.substring(0, jenkinsUrl.length - 1);
}
}
}

Expand Down Expand Up @@ -141,11 +142,10 @@ exports.connect = function (clientId, onConnect) {
// TODO: Need to add browser poly-fills for stuff like this
// See https://github.com/remy/polyfills/blob/master/EventSource.js
} else {
var connectUrl = jenkinsUrl + 'sse-gateway/connect?clientId='
var connectUrl = jenkinsUrl + '/sse-gateway/connect?clientId='
+ encodeURIComponent(clientId);

ajax.get(connectUrl, function (response) {
var listenUrl = jenkinsUrl + 'sse-gateway/listen/' + encodeURIComponent(clientId);
var listenUrl = jenkinsUrl + '/sse-gateway/listen/' + encodeURIComponent(clientId);

if (configuration.sendSessionId) {
// Sending the jsessionid helps headless clients to maintain
Expand Down Expand Up @@ -385,7 +385,7 @@ function doConfigure() {
// open the SSE channel + send the jenkins session info.
scheduleDoConfigure(100);
} else {
var configureUrl = jenkinsUrl + 'sse-gateway/configure?batchId=' + configurationBatchId;
var configureUrl = jenkinsUrl + '/sse-gateway/configure?batchId=' + configurationBatchId;

LOGGER.debug('Sending notification configuration request for configuration batch '
+ configurationBatchId + '.', configurationQueue);
Expand Down
2 changes: 1 addition & 1 deletion src/test/js/sse-plugin-no-filter-ispec.js
Expand Up @@ -16,7 +16,7 @@ describe("sse plugin integration tests - subscribe and unsubscribe - no filters"

function runBuild() {
var ajax = jsTest.requireSrcModule('ajax');
ajax.post(undefined, sseClient.jenkinsUrl + 'job/sse-gateway-test-job/build', jenkinsSessionInfo);
ajax.post(undefined, sseClient.jenkinsUrl + '/job/sse-gateway-test-job/build', jenkinsSessionInfo);
}

sseClient.connect('sse-client-123', function(jenkinsSession) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/js/sse-plugin-with-filter-ispec.js
Expand Up @@ -16,7 +16,7 @@ describe("sse plugin integration tests - with filters", function () {
var ajax = jsTest.requireSrcModule('ajax');

// Once connected to the SSE Gateway, fire off a build of the sample job
ajax.post(undefined, sseClient.jenkinsUrl + 'job/sse-gateway-test-job/build', jenkinsSessionInfo);
ajax.post(undefined, sseClient.jenkinsUrl + '/job/sse-gateway-test-job/build', jenkinsSessionInfo);

sseClient.subscribe('job', function () {
expect('Should not have received this event').toBe();
Expand Down

0 comments on commit ca1826b

Please sign in to comment.