-
Notifications
You must be signed in to change notification settings - Fork 18
/
SparqlDescribeProcessor.java
73 lines (65 loc) · 2.72 KB
/
SparqlDescribeProcessor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Copyright 2014 DuraSpace, Inc.
*
* 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.
*/
package org.fcrepo.camel.processor;
import static org.apache.camel.Exchange.HTTP_METHOD;
import static org.apache.camel.Exchange.CONTENT_TYPE;
import static org.apache.camel.Exchange.ACCEPT_CONTENT_TYPE;
import static org.fcrepo.camel.FedoraEndpoint.FCREPO_BASE_URL;
import static org.fcrepo.camel.FedoraEndpoint.FCREPO_IDENTIFIER;
import static org.fcrepo.jms.headers.DefaultMessageFactory.BASE_URL_HEADER_NAME;
import static org.fcrepo.jms.headers.DefaultMessageFactory.IDENTIFIER_HEADER_NAME;
import org.apache.camel.Processor;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
/**
* Represents a Processor class that formulates a Sparql DESCRIBE query
* that is ready to be POSTed to a Sparql endpoint.
*
* The processor expects the following headers:
* org.fcrepo.jms.identifier
* org.fcrepo.jms.baseURL
* each of which can be overridden with the following:
* FCREPO_IDENTIFIER
* FCREPO_BASE_URL
*
* @author Aaron Coburn
* @since November 6, 2014
*/
public class SparqlDescribeProcessor implements Processor {
/**
* Define how this message should be processed
*/
public void process(final Exchange exchange) throws Exception {
final Message in = exchange.getIn();
String subject = null;
if (in.getHeader(FCREPO_BASE_URL) != null) {
subject = in.getHeader(FCREPO_BASE_URL, String.class);
} else if (in.getHeader(BASE_URL_HEADER_NAME) != null) {
subject = in.getHeader(BASE_URL_HEADER_NAME, String.class);
} else {
throw new Exception("No baseURL header available!");
}
if (in.getHeader(FCREPO_IDENTIFIER) != null) {
subject += in.getHeader(FCREPO_IDENTIFIER);
} else if (in.getHeader(IDENTIFIER_HEADER_NAME) != null) {
subject += in.getHeader(IDENTIFIER_HEADER_NAME);
}
exchange.getIn().setBody("query=DESCRIBE <" + subject + ">");
exchange.getIn().setHeader(HTTP_METHOD, "POST");
exchange.getIn().setHeader(ACCEPT_CONTENT_TYPE, "application/rdf+xml");
exchange.getIn().setHeader(CONTENT_TYPE, "application/x-www-form-urlencoded");
}
}