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.reindexing; 017 018import java.net.URL; 019 020import org.apache.camel.Exchange; 021import org.apache.camel.Message; 022import org.apache.camel.Processor; 023import org.fcrepo.camel.FcrepoHeaders; 024 025/** 026 * A processor that converts the body of a message 027 * (which should be a full fedora resource URI) into 028 * the corresponding CamelFcrepoIdentifier value. 029 * 030 * @author Aaron Coburn 031 */ 032public class PathProcessor implements Processor { 033 034 /** 035 * Convert the message body into an appropriate IDENTIFIER value 036 * 037 * @param exchange the current message exchange 038 */ 039 public void process(final Exchange exchange) throws Exception { 040 final Message in = exchange.getIn(); 041 042 final URL fullPath = new URL(in.getBody(String.class)); 043 final String base = in.getHeader(FcrepoHeaders.FCREPO_BASE_URL, String.class); 044 final URL baseUrl = new URL(base.startsWith("http") ? base : "http://" + base); 045 046 in.setHeader(FcrepoHeaders.FCREPO_IDENTIFIER, fullPath.getPath().substring(baseUrl.getPath().length())); 047 048 in.removeHeader("JMSCorrelationID"); 049 } 050}