Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
Conflicts:
	CHANGES.md
  • Loading branch information
Subbu Allamaraju committed Jan 26, 2012
2 parents ea32092 + 2777f1d commit 7dd8896
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Jan 25, 2011

* Support for extended xml content-types returned per rfc: http://www.ietf.org/rfc/rfc3023.txt
* Also better handling of unrecognized content-types.

## Jan 22, 2012

* Integrate HAR view (https://github.com/s3u/har-view) replacing the vanilla tree view.
Expand Down
2 changes: 2 additions & 0 deletions modules/console/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ var Console = module.exports = function(config, cb) {
'route': /\/scripts\/all.js/,
'path': __dirname + '/public/scripts/',
'dataType': 'javascript',
debug: true,
'files': [
'splitter.js',
'codemirror.js',
Expand All @@ -129,6 +130,7 @@ var Console = module.exports = function(config, cb) {
'route': /\/css\/all.css/,
'path': __dirname + '/public/css/',
'dataType': 'css',
debug: true,
'files': [
'console.css',
'codemirror.css',
Expand Down
5 changes: 4 additions & 1 deletion modules/engine/lib/engine/http.request.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ function jsonify(respData, mediaType, xformers, respCb, errorCb) {
if (!respData || /^\s*$/.test(respData)) {
respCb({});
}
else if(mediaType.subtype === 'xml') {
else if(mediaType.subtype === 'xml' || /\+xml$/.test(mediaType.subtype)) {
xformers['xml'].toJson(respData, respCb, errorCb);
}
else if(mediaType.subtype === 'json') {
Expand All @@ -681,6 +681,9 @@ function jsonify(respData, mediaType, xformers, respCb, errorCb) {
xformers['xml'].toJson(respData, respCb, errorCb);
});
}
else {
errorCb({message:"No transformer available", type:mediaType.type, subType:mediaType.subtype})
}
}

function getStatus(res, resource, respJson, respData) {
Expand Down
1 change: 1 addition & 0 deletions modules/engine/lib/engine/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ function execInternal(opts, statement, cb, parentEvent) {
if(statement.assign) {
context[statement.assign] = projected;
emitter.emit(statement.assign, projected);
console.log('>> emitting ' + statement.assign + ' ' + projected);
}
return apiTx.cb(null, {
headers: {
Expand Down
2 changes: 1 addition & 1 deletion modules/engine/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "ql.io",
"name": "ql.io-engine",
"version": "0.4.0-beta",
"version": "0.4.0-beta.1",
"repository": {
"type": "git",
"url": "https://github.com/ql-io/ql.io"
Expand Down
7 changes: 7 additions & 0 deletions modules/engine/test/mock/plusXml.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

create table plusxml
on select get from "http://localhost:3000/test";

aResponse = select * from plusxml;
return "{aResponse}";

214 changes: 214 additions & 0 deletions modules/engine/test/plusxml-content-type-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
/*
* Copyright 2011 eBay Software Foundation
*
* Licensed 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.
*/

var _ = require('underscore'),
Engine = require('../lib/engine'),
http = require('http'),
fs = require('fs'),
util = require('util');

var engine = new Engine({
config:__dirname + '/config/dev.json',
connection:'close'
});

exports['soap+xml'] = function (test) {
var server = http.createServer(function (req, res) {

req.on('end', function() {
var respStr = '<?xml version="1.0"?>' +
'<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" ' +
'soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">' +
'<soap:Body xmlns:m="http://www.example.org/stock">' +
'<m:GetStockPriceResponse>' +
'<m:Price>34.5</m:Price>' +
'</m:GetStockPriceResponse>' +
'</soap:Body>' +
'</soap:Envelope>';

res.writeHead(200, {
'Content-Type':'application/soap+xml',
'Content-Length':respStr.length
});
res.write(respStr);
res.end();
});

});
server.listen(3000, function () {
// Do the test here.
var engine = new Engine({
connection:'close'
});
var script = fs.readFileSync(__dirname + '/mock/plusXml.ql', 'UTF-8');

engine.exec(script, function (err, result) {
if (err) {
console.log(err.stack || util.inspect(err, false, 10));
test.fail('got error');
test.done();
}
else {
test.equals(result.headers['content-type'], 'application/json', 'HTML expected');
test.ok(result.body['soap:Envelope']['soap:Body'], 'expected soap body in json resp');
test.done();
}
server.close();
});
});
}

exports['atom+xml'] = function (test) {
var server = http.createServer(function (req, res) {

req.on('end', function() {
var respStr = '<?xml version="1.0" encoding="utf-8"?>' +
'<feed xmlns="http://www.w3.org/2005/Atom">' +
'<title>Example Feed</title>' +
'<link href="http://example.org/"/>' +
'<updated>2003-12-13T18:30:02Z</updated>' +
'<author>' +
'<name>John Doe</name>' +
'</author>' +
'<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>' +
'<entry>' +
'<title>Atom-Powered Robots Run Amok</title>' +
'<link href="http://example.org/2003/12/13/atom03"/>' +
'<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>' +
'<updated>2003-12-13T18:30:02Z</updated>' +
'<summary>Some text.</summary>' +
'</entry>' +
'</feed>';

res.writeHead(200, {
'Content-Type':'application/atom+xml',
'Content-Length':respStr.length
});
res.write(respStr);
res.end();
});

});
server.listen(3000, function () {
// Do the test here.
var engine = new Engine({
connection:'close'
});
var script = fs.readFileSync(__dirname + '/mock/plusXml.ql', 'UTF-8');

engine.exec(script, function (err, result) {
if (err) {
console.log(err.stack || util.inspect(err, false, 10));
test.fail('got error');
test.done();
}
else {
test.equals(result.headers['content-type'], 'application/json', 'HTML expected');
test.ok(result.body['feed'], 'expected atom feed in json resp');
test.done();
}
server.close();
});
});
}

exports['foo+xml'] = function (test) {
var server = http.createServer(function (req, res) {

req.on('end', function() {
var respStr = '<?xml version="1.0" encoding="utf-8"?>' +
'<foo>bar</foo>';

res.writeHead(200, {
'Content-Type':'application/foo+xml',
'Content-Length':respStr.length
});
res.write(respStr);
res.end();
});

});
server.listen(3000, function () {
// Do the test here.
var engine = new Engine({
connection:'close'
});
var script = fs.readFileSync(__dirname + '/mock/plusXml.ql', 'UTF-8');

engine.exec(script, function (err, result) {
if (err) {
console.log(err.stack || util.inspect(err, false, 10));
test.fail('got error');
test.done();
}
else {
test.equals(result.headers['content-type'], 'application/json', 'HTML expected');
test.equal('bar',result.body['foo'], 'expected foo.bar in json resp');
test.done();
}
server.close();
});
});
}

exports['bad content'] = function (test) {

var server = http.createServer(function (req, res) {
req.on('end', function() {
var respStr = '<?xml version="1.0"?>' +
'<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" ' +
'soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">' +
'<soap:Body xmlns:m="http://www.example.org/stock">' +
'<m:GetStockPriceResponse>' +
'<m:Price>34.5</m:Price>' +
'</m:GetStockPriceResponse>' +
'</soap:Body>' +
'</soap:Envelope>';

res.writeHead(200, {
'Content-Type': 'application/bad+type',
'Content-Length':respStr.length
});
res.write(respStr);
res.end();
});

});


server.listen(3000, function () {
// Do the test here.
var engine = new Engine({
connection:'close'
});
var script = fs.readFileSync(__dirname + '/mock/plusXml.ql', 'UTF-8');

engine.exec(script, function (err, result) {
if (err) {
test.equals(err.message,"No transformer available");
test.equals(err.type,"application");
test.equals(err.subType,"bad+type");
test.done();
}
else {
console.log(util.inspect(result,false,null));
test.ok(false, 'Expected exception');
test.done();
}
server.close();
});
});
}

0 comments on commit 7dd8896

Please sign in to comment.