/* * Copyright (C) 2015 * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.cleverbus.component.asynchchild; import java.util.Map; import java.util.UUID; import org.cleverbus.api.entity.BindingTypeEnum; import org.apache.camel.Endpoint; import org.apache.camel.impl.DefaultComponent; import org.apache.camel.util.ObjectHelper; import org.springframework.util.Assert; /** * Apache Camel component "asynch-child" for creating asynchronous child message. * Asynchronous child message can be created from synchronous or asynchronous message. If from synch. message * then {@link BindingTypeEnum#SOFT SOFT} binding is set. * * <p/> * Syntax: {@code asynch-child:service:operation[?options]}, where * <ul> * <li>message service name, e.g. "customer". * <li>operation name, e.g. "createCustomer" * </ul> * * And options are: * <ul> * <li>correlationId (can be empty, by default ID is generated by {@link UUID#randomUUID()}) * <li>sourceSystem (can be empty, source system, e.g. "CRM". * If not defined then {@value AsynchChildProducer#DEFAULT_EXTERNAL_SYSTEM} is used) * <li>bindingType (can be empty, possible values are {@link BindingTypeEnum#HARD HARD} (default) * and {@link BindingTypeEnum#SOFT SOFT}) * <li>objectId (can be empty, ID that will be changed during message processing) * <li>funnelValue (can be empty, funnel value) * </ul> * * @author <a href="mailto:petr.juza@cleverlance.com">Petr Juza</a> */ public class AsynchChildComponent extends DefaultComponent { @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { AsynchChildEndpoint endpoint = new AsynchChildEndpoint(uri, this); // parse URI - "service:operation" String endpointURI = ObjectHelper.after(uri, ":"); if (endpointURI != null && endpointURI.startsWith("//")) { endpointURI = endpointURI.substring(2); } Assert.hasText(endpointURI, "Asynch-child endpoint URI must not be empty"); // endpointURI = "service:operation" String serviceName = ObjectHelper.before(endpointURI, ":"); String operationName = ObjectHelper.after(endpointURI, ":"); if (operationName != null && operationName.contains("?")) { operationName = ObjectHelper.before(operationName, "?"); } Assert.hasText(serviceName, "Service name can't be empty for asynch-child component"); Assert.hasText(operationName, "Operation name can't be empty for asynch-child component"); endpoint.setService(serviceName); endpoint.setOperationName(operationName); setProperties(endpoint, parameters); return endpoint; } @Override protected void validateURI(String uri, String path, Map<String, Object> parameters) { super.validateURI(uri, path, parameters); } }