001/**
002 * Copyright 2015 DuraSpace, Inc.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.fcrepo.camel.processor;
017
018import static java.net.URLEncoder.encode;
019
020import java.io.IOException;
021
022import org.apache.camel.Exchange;
023import org.apache.camel.Message;
024import org.apache.camel.Processor;
025
026/**
027 * Represents a Processor class that formulates a Sparql DESCRIBE query
028 * that is ready to be POSTed to a Sparql endpoint.
029 *
030 * The processor expects the following headers:
031 *      org.fcrepo.jms.identifier
032 *      org.fcrepo.jms.baseURL
033 * each of which can be overridden with the following:
034 *      FCREPO_IDENTIFIER
035 *      FCREPO_BASE_URL
036 *
037 * @author Aaron Coburn
038 * @since November 6, 2014
039 */
040public class SparqlDescribeProcessor implements Processor {
041    /**
042     *  Define how this message should be processed
043     *
044     *  @param exchange the current camel message exchange
045     */
046    public void process(final Exchange exchange) throws IOException {
047
048        final Message in = exchange.getIn();
049        final String subject = ProcessorUtils.getSubjectUri(in);
050
051        exchange.getIn().setBody("query=" + encode("DESCRIBE <" + subject + ">", "UTF-8"));
052        exchange.getIn().setHeader(Exchange.HTTP_METHOD, "POST");
053        exchange.getIn().setHeader(Exchange.ACCEPT_CONTENT_TYPE, "application/rdf+xml");
054        exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/x-www-form-urlencoded");
055    }
056}