Skip to content

Commit

Permalink
Merge pull request #112 from 3-Round-Stones/v1.3.1
Browse files Browse the repository at this point in the history
Resolve many issues scheduled for v1.3.1
  • Loading branch information
catch-point committed Apr 16, 2014
2 parents 863b504 + dd9e128 commit 2a07287
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 105 deletions.
4 changes: 2 additions & 2 deletions src/org/callimachusproject/server/WebServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
import org.callimachusproject.server.chain.ResponseExceptionHandler;
import org.callimachusproject.server.chain.SecureChannelFilter;
import org.callimachusproject.server.chain.ServerNameFilter;
import org.callimachusproject.server.chain.TraceHandler;
import org.callimachusproject.server.chain.PingOptionsHandler;
import org.callimachusproject.server.chain.TransactionHandler;
import org.callimachusproject.server.chain.UnmodifiedSinceHandler;
import org.callimachusproject.server.exceptions.BadGateway;
Expand Down Expand Up @@ -223,7 +223,7 @@ public WebServer(File cacheDir)
filter = new ResponseExceptionHandler(filter);
filter = transaction = new TransactionHandler(filter, closing);
filter = env = new HttpResponseFilter(filter);
filter = new TraceHandler(filter);
filter = new PingOptionsHandler(filter);
// exec in i/o thread
filter = new PooledExecChain(filter, triaging);
filter = cache = new CacheHandler(filter, new FileResourceFactory(cacheDir), getDefaultCacheConfig());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Future<HttpResponse> execute(HttpHost target,
if ("OPTIONS".equals(request.getRequestLine().getMethod())) {
ResourceOperation trans = CalliContext.adapt(context).getResourceTransaction();
StringBuilder sb = new StringBuilder();
sb.append("OPTIONS, TRACE");
sb.append("OPTIONS");
for (String method : trans.getAllowedMethods()) {
sb.append(", ").append(method);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright 2011-2014 3 Round Stones Inc., Some rights reserved.
* Copyright 2009-2010, James Leigh and Zepheira LLC Some rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -28,10 +29,8 @@
*/
package org.callimachusproject.server.chain;

import java.nio.charset.Charset;
import java.util.concurrent.Future;

import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
Expand All @@ -40,25 +39,21 @@
import org.apache.http.RequestLine;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.nio.entity.NStringEntity;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpDateGenerator;
import org.callimachusproject.client.HttpUriResponse;
import org.callimachusproject.server.AsyncExecChain;
import org.callimachusproject.server.helpers.CompletedResponse;
import org.callimachusproject.server.helpers.EntityRemovedHttpResponse;
import org.callimachusproject.server.helpers.ResponseBuilder;
import org.callimachusproject.server.helpers.ResponseCallback;

/**
* Handles the TRACE and OPTIONS * requests.
* Handles the OPTIONS * requests.
*/
public class TraceHandler implements AsyncExecChain {
public class PingOptionsHandler implements AsyncExecChain {
private static final HttpDateGenerator DATE_GENERATOR = new HttpDateGenerator();

private final AsyncExecChain delegate;

public TraceHandler(AsyncExecChain delegate) {
public PingOptionsHandler(AsyncExecChain delegate) {
this.delegate = delegate;
}

Expand All @@ -67,57 +62,16 @@ public Future<HttpResponse> execute(HttpHost target,
HttpRequest request, HttpContext context,
FutureCallback<HttpResponse> callback) {
RequestLine line = request.getRequestLine();
if ("TRACE".equals(request.getRequestLine().getMethod())) {
String CRLF = "\r\n";
StringBuilder sb = new StringBuilder();
sb.append("TRACE ").append(line.getUri()).append(" ");
sb.append(line.getProtocolVersion());

for (Header hd : request.getAllHeaders()) {
sb.append(CRLF).append(hd.getName());
sb.append(": ").append(hd.getValue());
}

sb.append(CRLF);
ProtocolVersion ver = HttpVersion.HTTP_1_1;
BasicHttpResponse resp = new EntityRemovedHttpResponse(ver, 200, "OK");
resp.setHeader("Date", DATE_GENERATOR.getCurrentDate());
NStringEntity entity = new NStringEntity(sb.toString(), Charset.forName("ISO-8859-1"));
entity.setContentType("message/http");
entity.setChunked(false);
resp.setEntity(entity);
resp.setHeader("Content-Length", Long.toString(entity.getContentLength()));
resp.setHeader(entity.getContentType());
return new CompletedResponse(callback, new ResponseBuilder(request, context).respond(resp));
} else if ("OPTIONS".equals(request.getRequestLine().getMethod())
if ("OPTIONS".equals(request.getRequestLine().getMethod())
&& "*".equals(line.getUri())) {
ProtocolVersion ver = HttpVersion.HTTP_1_1;
BasicHttpResponse resp = new BasicHttpResponse(ver, 204, "No Content");
resp.setHeader("Date", DATE_GENERATOR.getCurrentDate());
resp.setHeader("Allow", "OPTIONS, TRACE, GET, HEAD, PUT, DELETE");
resp.setHeader("Allow", "OPTIONS, GET, HEAD, PUT, DELETE");
// TRACE is not supported, due to http://www.kb.cert.org/vuls/id/867593
return new CompletedResponse(callback, new HttpUriResponse("*", resp));
} else {
return delegate.execute(target, request, context, new ResponseCallback(callback) {
public void completed(HttpResponse result) {
try {
allow(result);
super.completed(result);
} catch (RuntimeException ex) {
super.failed(ex);
}
}
});
}
}

void allow(HttpResponse resp) {
if (resp != null && resp.getStatusLine().getStatusCode() == 405) {
if (resp.containsHeader("Allow")) {
String allow = resp.getFirstHeader("Allow").getValue();
resp.setHeader("Allow", allow + ",TRACE");
} else {
resp.setHeader("Allow", "TRACE");
}
return delegate.execute(target, request, context, callback);
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/org/callimachusproject/server/DataResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ public void testPUTContentType() throws Exception {
public void testNoOptions() throws Exception {
ClientResponse options = client.path("hello").options(ClientResponse.class);
String allows = options.getMetadata().getFirst("Allow");
assertEquals("OPTIONS, TRACE, PUT", allows);
assertEquals("OPTIONS, PUT", allows);
}

public void testOPTIONS() throws Exception {
client.path("hello").put("world");
ClientResponse options = client.path("hello").options(ClientResponse.class);
String allows = options.getMetadata().getFirst("Allow");
assertEquals("OPTIONS, TRACE, GET, HEAD, PUT, DELETE", allows);
assertEquals("OPTIONS, GET, HEAD, PUT, DELETE", allows);
}

public void testSetOfInputStream() throws Exception {
Expand Down
34 changes: 28 additions & 6 deletions webapp/queries/what-links-here.rq
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,34 @@ WHERE {
?url ?rel <$target>
FILTER (isIRI(?url))
FILTER (?rel != prov:wasAssociatedWith)
?url prov:wasGeneratedBy ?revision
OPTIONAL { ?revision prov:endedAtTime ?modified }
OPTIONAL { ?url a [calli:icon ?icon] }
OPTIONAL { ?url skos:prefLabel ?label }
OPTIONAL { ?url rdfs:label ?label }
OPTIONAL { ?url rdfs:comment ?comment }
{
FILTER (!contains(str(?url), "?") && !contains(str(?url), "#"))
?url prov:wasGeneratedBy ?revision
OPTIONAL { ?revision prov:endedAtTime ?modified }
OPTIONAL { ?url a [calli:icon ?icon] }
OPTIONAL { ?url skos:prefLabel ?label }
OPTIONAL { ?url rdfs:label ?label }
OPTIONAL { ?url rdfs:comment ?comment }
} UNION {
FILTER contains(str(?url), "?")
BIND (iri(strbefore(str(?url), "?")) AS ?entity)
?entity prov:wasGeneratedBy ?revision
OPTIONAL { ?revision prov:endedAtTime ?modified }
OPTIONAL { ?entity a [calli:icon ?icon] }
OPTIONAL { ?entity skos:prefLabel ?label }
OPTIONAL { ?entity rdfs:label ?label }
OPTIONAL { ?entity rdfs:comment ?comment }
} UNION {
FILTER (!contains(str(?url), "?"))
FILTER contains(str(?url), "#")
BIND (iri(strbefore(str(?url), "#")) AS ?entity)
?entity prov:wasGeneratedBy ?revision
OPTIONAL { ?revision prov:endedAtTime ?modified }
OPTIONAL { ?entity a [calli:icon ?icon] }
OPTIONAL { ?entity skos:prefLabel ?label }
OPTIONAL { ?entity rdfs:label ?label }
OPTIONAL { ?entity rdfs:comment ?comment }
}
}
ORDER BY ?label ?url ?icon
LIMIT 100
2 changes: 1 addition & 1 deletion webapp/scripts/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ window.calli.error = function(message, stack) {
error = new Error(message.toString());
}
if (window.console && window.console.error) {
console.error(error.message);
console.error(message);
}
if (!e.isPropagationStopped() && parent != window && parent.postMessage) {
if (stack) {
Expand Down
1 change: 1 addition & 0 deletions webapp/scripts/index.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
rdf:_5 <../assets/ckeditor/ckeditor.js> . # include after document-editor.js!

<query_bundle> a calli:ScriptBundle;
calli:minified 0;
calli:reader </auth/groups/public>;
rdf:_1 <../assets/d3/d3.v3.3.3.js>;
rdf:_2 <../assets/nv/nv.d3.js>;
Expand Down
6 changes: 4 additions & 2 deletions webapp/scripts/save-resource-as.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ window.calli.saveResourceAs = function(event, fileName, create, folder) {
var label = fileName || findLabel(form) || localPart(resource);
openSaveAsDialog(form, label, create, folder, function(ns, local) {
if (fileName) {
local = local.replace(/\+/g,'-');
local = local.replace(/%20/g,'-');
} else {
local = local.replace(/%20/g,'+');
}
var resource = ns + local.toLowerCase();
$(form).removeAttr('about');
Expand Down Expand Up @@ -159,7 +161,7 @@ function openSaveAsDialog(form, label, create, folder, callback) {
if (ns.lastIndexOf('/') != ns.length - 1) {
ns += '/';
}
var local = encodeURI(label).replace(/%20/g,'+');
var local = encodeURI(label);
updateFormAction(form, src, create);
callback(ns, local);
calli.closeDialog(dialog);
Expand Down
5 changes: 0 additions & 5 deletions webapp/styles/callimachus-query-view.less
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,13 @@
-moz-border-radius: 4px;
border-radius: 4px;
overflow: visible;
}

#calli-viz-editor a {
cursor: pointer;
}

/* viz menu */

.viz-menu {
border-bottom: 1px solid #ccc;
line-height: 1em;
cursor: move;
}

.viz-menu .visualizations {
Expand Down
2 changes: 1 addition & 1 deletion webapp/templates/class-create.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<div class="form-group col-sm-10">
<label for="label">Label</label>
<div>
<input type="text" id="label" value="{rdfs:label}" class="form-control" required="required" />
<input type="text" id="label" value="{rdfs:label}" class="form-control" required="required" autofocus="autofocus" />
</div>
</div>
<div id="icon" dropzone="link string:text/uri-list" class="form-group col-sm-2"
Expand Down
12 changes: 10 additions & 2 deletions webapp/templates/concept-edit.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<head>
<title resource="?this">{skos:prefLabel}</title>
<link rel="help" href="../../callimachus-for-web-developers#Concept" target="_blank" title="Help" />
<link id="folder" about="?this" rev="calli:hasComponent" href="?folder" />
<link id="type" href="../types/Concept" />
<script type="text/javascript">
function saveChangeNote() {
var note = document.getElementById('note')
Expand All @@ -24,6 +26,13 @@
.attr("datatype", "xsd:dateTime")
.attr("content", new Date().toISOString())
.appendTo('#form');
$('#saveas').on('click', function(event){
$('#modified').attr("property", "decterms:created");
var local = calli.slugify($('#label').val());
var type = $('#type').attr('href');
var folder = $('#folder').attr('href');
calli.saveResourceAs(event, local, type, folder);
});
});
</script>
</head>
Expand Down Expand Up @@ -124,8 +133,7 @@
</div>
<div class="form-group">
<button id="save" type="submit" class="btn btn-primary">Save</button>
<button id="saveas" type="button" class="btn btn-info" rev="calli:hasComponent" resource="?folder"
onclick="calli.saveResourceAs(event, calli.slugify($('#label').val()), calli.getCallimachusUrl('types/Concept'), this.getAttribute('resource'))">Save as...</button>
<button id="saveas" type="button" class="btn btn-info">Save as...</button>
<button id="cancel" type="button" onclick="window.location.replace('?view')" class="btn btn-default">Cancel</button>
<button id="delete" type="button" onclick="calli.deleteResource(event)" class="btn btn-danger">Delete</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion webapp/templates/facebook-create.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<div class="form-group">
<label for="label">Label</label>
<div>
<input type="text" class="form-control" id="label" value="{rdfs:label}" required="required" />
<input type="text" class="form-control" id="label" value="{rdfs:label}" required="required" autofocus="autofocus" />
</div>
</div>
<div class="form-group">
Expand Down
19 changes: 11 additions & 8 deletions webapp/templates/folder-edit.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@
<script type="text/javascript">
// <![CDATA[
jQuery(function($){
$('#pattern').change(function(){
$('span.pattern').attr('content', this.value);
$('#pattern').change(function(event){
$('span.pattern').remove();
var type = $('#type').prop('value');
if (event.target.value && type) {
$(event.target).parent().append($('<span/>', {
"class": "pattern",
property: type,
content: event.target.value
}));
}
});
$('#type').change(function(){
if (this.value) {
$('span.pattern').remove();
$('#pattern').parent().append('<span class="pattern" />');
$('span.pattern').attr('property', this.value);
$('#pattern').change();
}
$('#pattern').change();
});
$('span.pattern[property]').each(function(){
if (this.getAttribute('content')) {
Expand Down
16 changes: 8 additions & 8 deletions webapp/templates/invited-user-view.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@
<label for="message">Welcome message</label>
<div>
<textarea id="body" name="body" class="form-control col-md-5" required="required" rows="10">Hello {rdfs:label},
This is a reminder that a new account has been created for you. Use the
link below to pick a password or other authentication options.
@@REGISTRATION_URL@@
Enjoy!
</textarea>

This is a reminder that a new account has been created for you. Use the
link below to pick a password or other authentication options.

@@REGISTRATION_URL@@

Enjoy!
</textarea>
</div>
</div>
</fieldset>
Expand Down
2 changes: 1 addition & 1 deletion webapp/templates/openid-create.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<div class="form-group">
<label for="label">Label</label>
<div>
<input type="text" class="form-control" id="label" value="{rdfs:label}" required="required" />
<input type="text" class="form-control" id="label" value="{rdfs:label}" required="required" autofocus="autofocus" />
</div>
</div>
<div class="form-group">
Expand Down
19 changes: 11 additions & 8 deletions webapp/templates/realm-edit.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
<script type="text/javascript">
// <![CDATA[
jQuery(function($){
$('#pattern').change(function(){
$('span.pattern').attr('content', this.value);
$('#pattern').change(function(event){
$('span.pattern').remove();
var type = $('#type').prop('value');
if (event.target.value && type) {
$(event.target).parent().append($('<span/>', {
"class": "pattern",
property: type,
content: event.target.value
}));
}
});
$('#type').change(function(){
if (this.value) {
$('span.pattern').remove();
$('#pattern').parent().append('<span class="pattern" />');
$('span.pattern').attr('property', this.value);
$('#pattern').change();
}
$('#pattern').change();
});
$('span.pattern[property]').each(function(){
if (this.getAttribute('content')) {
Expand Down
2 changes: 1 addition & 1 deletion webapp/types/invited-user.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ rdfs:label a rdf:Property.
//# email the link to the new user
var fromUser = this.FindUserCreator();
if (!fromUser || !fromUser.sendMessage)
throw new BadRequest("Could not find administrator");
fromUser = this;
fromUser.sendMessage(subject + '\\n' + body, this.rdfsLabel + " <" + this.calliEmail + ">");
return this;
""".
Expand Down
Loading

0 comments on commit 2a07287

Please sign in to comment.