All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.spring.camel-context.xml Maven / Gradle / Ivy

The newest version!
<?xml version="1.0" encoding="UTF-8"?>
<!--

    Unless explicitly acquired and licensed from Licensor under another license, the contents of
    this file are subject to the Reciprocal Public License ("RPL") Version 1.5, or subsequent
    versions as allowed by the RPL, and You may not copy or use this file in either source code
    or executable form, except in compliance with the terms and conditions of the RPL

    All software distributed under the RPL is provided strictly on an "AS IS" basis, WITHOUT
    WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, AND LICENSOR HEREBY DISCLAIMS ALL SUCH
    WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
    PARTICULAR PURPOSE, QUIET ENJOYMENT, OR NON-INFRINGEMENT. See the RPL for specific language
    governing rights and limitations under the RPL.

    http://opensource.org/licenses/RPL-1.5

    Copyright 2012-2017 Open Justice Broker Consortium

-->
<!-- Configures the Camel Context -->

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:camel="http://camel.apache.org/schema/spring"
	xmlns:cxf="http://camel.apache.org/schema/cxf" 
	xmlns:lexspd="http://usdoj.gov/leisp/lexs/publishdiscover/3.1"
	xmlns:lexs="http://usdoj.gov/leisp/lexs/3.1"
	xmlns:ndex-response="java:com.raytheon.ndex.ai.webservice"
	xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
       http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
       http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
       ">
	<!-- needed cxf imports -->
	<import resource="classpath:META-INF/cxf/cxf.xml" />
	
	<!-- Error handlers in case of submission errors -->
	<import resource="error-handlers.xml" />
	
	<camel:camelContext xmlns="http://camel.apache.org/schema/spring" id="ndex-submission-service-intermediary">
		<camel:routeContextRef ref="errorHandlerRoutes"/>
		
		<endpoint id="ndexFileDropDir"
			uri="file:///${NDExSubmission.FileSubmissionRoot}/input?idempotent=true&amp;moveFailed=${NDExSubmission.FileSubmissionRoot}/error&amp;move=processed/" />

		<endpoint id="ndexSubmissionSuccessDir"
			uri="file:///${NDExSubmission.FileSubmissionRoot}/ndexSubmissionResponse/success/" />

		<endpoint id="ndexSubmissionErrorDir"
			uri="file:///${NDExSubmission.FileSubmissionRoot}/ndexSubmissionResponse/error/" />

		<endpoint id="ndexSubmissionTestDir"
			uri="file:///${NDExSubmission.FileSubmissionRoot}/ndexSubmissionResponse/test/" />

		<endpoint id="ndexSubmissionDeadLetterDir"
			uri="file:///${NDExSubmission.FileSubmissionRoot}/deadletter/" />

		<endpoint id="ndexWebserviceEndpoint"
			uri="https4://${NDExSubmission.N-DexActualServiceEndpoint}" />
			
		<endpoint id="ndexWebserviceFacadeEndpoint"
			uri="cxf:bean:N-DexSubmissionServiceFacade?dataFormat=PAYLOAD&amp;loggingFeatureEnabled=${NDExSubmission.ndexSubmissionServiceIntermediaryCxflogging}" />
			

		<!-- N-DEx File Drop Handler -->
		<camel:route>
			<camel:from
				uri="ndexFileDropDir" />
			<camel:to uri="direct:processNDExSubmission"/>	
		</camel:route>		

		<!-- N-DEx Web Service Handler -->
		<camel:route>
			<camel:from
				uri="ndexWebserviceFacadeEndpoint" />
			<camel:to uri="direct:processNDExSubmission"/>	
		</camel:route>		

		<camel:route>
			<camel:from uri="direct:processNDExSubmission"/>			
			<camel:log message="Recieved N-DEx web service invocation" />

			<!-- Here we remove all existing headers to get rid of WS-Security and HTTP headers that interfere with the exchange -->
			<camel:removeHeaders pattern="*"/>

			<!--  Agency ORI header is needed to create the 'file name' parameter -->
			<camel:setHeader headerName="AgencyORI">
				<camel:xpath>//lexs:DataItemPackage/lexs:PackageMetadata/lexs:DataOwnerMetadata/lexs:DataOwnerIdentifier/lexs:ORI/text()</camel:xpath>
			</camel:setHeader>

			<!--  Incident ID is used to correlate requests and responses -->
			<camel:setHeader headerName="IncidentID">
				<camel:xpath>//lexs:DataItemPackage/lexs:PackageMetadata/lexs:DataItemID/text()</camel:xpath>
			</camel:setHeader>

			<camel:log message="Agency ORI: ${in.headers.AgencyORI}"/>
			<camel:log message="Incident ID: ${in.headers.IncidentID}"/>

			<!-- Set the file name here based off incident ID so we have the Incident number in case of dead letter failure -->
			<camel:setHeader headerName="CamelFileName"><camel:simple>INCIDENT_${in.headers.IncidentID}_DATE_${date:now:yyyyMMdd}_${date:now:HHmmssSS}.xml</camel:simple></camel:setHeader>

			<camel:setHeader headerName="CamelFileName">
	            <method bean="NDExUtils" method="createNdexFormatFileName"/>
			</camel:setHeader>

			<!-- This function will set the header 'ndexTestORI' -->
			<camel:to
				uri="bean:ndexORIProcessor?method=confirmNdexTestOri"/>

			<!-- If this is an N-DEx 'test' ORI, this processor prefixes with TEST_ so it doesn't go into production -->
			<camel:filter>
				<camel:simple>${in.header.ndexTestORI} == 'true'</camel:simple>
				<camel:setHeader headerName="CamelFileName">
		            <method bean="NDExUtils" method="createNDexTestFileName"/>
				</camel:setHeader>
			</camel:filter>
				
			<!-- The method 'createNDexMessage' uses this variable to create the N-DEx paylaod -->
			<camel:setHeader headerName="submittingAgencyName">
				<simple>{{NDExSubmission.submittingAgencyName}}</simple>
			</camel:setHeader>
				
			<!-- We use this XSLT to put all namespaces in the root of the doPublish message to accommodate the ingester -->	
			<camel:to uri="xslt:xslt/doPublishRoot.xsl"/>
							
			<camel:log message="Body after camel set body: ${body}" loggingLevel="DEBUG"/>
			
			<camel:convertBodyTo type="java.lang.String"/>
			
			<camel:to
				uri="bean:NDExUtils?method=createNDExMessage" />
				
			<!-- When attempting to connect with CXF, was receiving exception: Caused by: java.net.SocketTimeoutException: Read timed out -->
			<!-- Tried to troubleshoot with N-DEx techs.  To get it working switching to posting Soap message over HTTPS with camel HTTP component -->
			<!-- To do this, wrap message as soap message and send to HTTP endpoint. -->	
			<camel:to uri="xslt:xslt/SOAPWrapper.xsl"/>	
			
			<camel:removeHeader headerName="AgencyORI"/>
			<camel:removeHeader headerName="submittingAgencyName"/>

<!-- 			<camel:setHeader headerName="operationName"><constant>submitNDExIEPD1_0</constant></camel:setHeader> -->
<!-- 			<camel:setHeader headerName="operationNamespace"><constant>urn://com.raytheon.ndex.ai.webservice</constant></camel:setHeader> -->
<!-- 			<camel:to uri="cxf:bean:N-DexActualServiceEndpoint?dataFormat=PAYLOAD&amp;synchronous=true;"/> -->

			<camel:log message="About to invoke N-DEx web service"/>

			<camel:filter>
				<camel:simple>${in.header.ndexTestORI} == 'true'</camel:simple>
				<camel:wireTap uri="ndexSubmissionTestDir"/>
			</camel:filter>


			<camel:to uri="direct:callNdexService"/>
			
			<camel:convertBodyTo type="java.lang.String"/>
			
			<camel:log message="This is the HTTP response code: ${in.headers.CamelHttpResponseCode}"/>
			<camel:log message="This is the response: ${body}"/>
			
			<camel:setHeader headerName="fileLevelResultCode"><camel:xpath>//ndex-response:FileLevelResultCode/text()</camel:xpath></camel:setHeader>
			<camel:setHeader headerName="filelevelMessage"><camel:xpath>//ndex-response:FileLevelResultMessage/text()</camel:xpath></camel:setHeader>

			<camel:log message="File Level Result Code: ${in.headers.fileLevelResultCode}"/>
			<camel:log message="File Level Message: ${in.headers.filelevelMessage}"/>

			<camel:choice>
				<camel:when>
					<camel:simple>${in.headers.fileLevelResultCode} == '0' and ${in.headers.filelevelMessage} == 'success'</camel:simple>
					<camel:log message="Succesful N-DEx Submission, Incident ID: ${in.headers.IncidentID}"/>	
					<!-- We have succesfully submitted so we want to put the file in a subfolder with today's date -->
					<camel:setHeader headerName="CamelFileName"><camel:simple>${date:now:yyyyMMdd}/INCIDENT_${in.headers.IncidentID}_DATE_${date:now:yyyyMMdd}_${date:now:HHmmssSS}.xml</camel:simple></camel:setHeader>
					<camel:to uri="ndexSubmissionSuccessDir"/>
				</camel:when>								
				<camel:otherwise>
					<camel:log message="N-DEx Submission error, Incident ID: ${in.headers.IncidentID}"/>
					<camel:to uri="ndexSubmissionErrorDir"/>
				</camel:otherwise>
			</camel:choice>
			
		</camel:route>

		<!-- Call N-DEx in a separate route so it has its own error handler -->		
		<camel:route errorHandlerRef="ndexDeadLetterErrorHandler">
			<camel:from uri="direct:callNdexService"/>
			
			<camel:log message="\n\nAbout to invoke N-DEx with this payload: ${body} \n\n"/>
			
			<camel:to uri="ndexWebserviceEndpoint"/>
		</camel:route>
		
        <route id="recordCheck" autoStartup="{{NDExSubmission.performRecordCheck}}">
			<camel:from
				uri="quartz2://ndexIntermediary/recordCheck?cron={{NDExSubmission.recordCheckCronExpression}}" />
		
			<camel:log message="Firing quartz timer to check for n-dex submissions" />
		
			<filter>
				<method ref="fileAndDirectoryVerificationProcessor" method="doesDirectoryWithFilesExist" />
				<camel:log message="Submissions sent today, stop route" />
				<camel:stop />
			</filter>
		
			<!-- If we get here the route was not stopped by the filter -->
		
			<camel:setHeader headerName="to">
				<constant>{{NDExSubmission.emailNotificationRecipientMessageError}}</constant>
			</camel:setHeader>
		
			<camel:setHeader headerName="subject">
				<constant>Check broker to see if there are n-dex submissions.</constant>
			</camel:setHeader>
		
			<to uri="deadLetterMail" />
            	
        </route>
		
		
	</camel:camelContext>

	<bean id="uniqueIDGeneratorBean" class="org.ojbc.util.ndex.util.UniqueIDGenerator"/>
	
	<bean id ="ndexORIProcessor" class="org.ojbc.processor.NdexORIProcessor">
		<constructor-arg type="java.lang.String">
			<value>${ndexTestORIs}</value>
		</constructor-arg>
	</bean>

	<bean id="NDExUtils" class="org.ojbc.util.camel.helper.NDexUtils">
		<property name="uniqueIDGenerator" ref="uniqueIDGeneratorBean"/>
	</bean>

	<camel:sslContextParameters id="sslContextParameters">
		<camel:trustManagers>
			<camel:keyStore resource="{{NDExSubmission.ndexClientTruststoreLocation}}"
				password="{{NDExSubmission.ndexTruststorePassword}}" />
		</camel:trustManagers>

		<camel:keyManagers keyPassword="{{NDExSubmission.ndexClientKeypassword}}">
			<camel:keyStore resource="{{NDExSubmission.ndexClientKeystoreLocation}}"
				password="{{NDExSubmission.ndexClientKeystorePassword}}" />
		</camel:keyManagers>
		
	</camel:sslContextParameters>
	
    <bean id="https4" class="org.apache.camel.component.http4.HttpComponent">
      <property name="sslContextParameters" ref="sslContextParameters"/>
      <property name="x509HostnameVerifier">
        <bean class="org.apache.http.conn.ssl.AllowAllHostnameVerifier"/>
      </property>
    </bean>	
    
    <bean id="fileAndDirectoryVerificationProcessor" class="org.ojbc.util.camel.processor.FileAndDirectoryVerificationProcessor">
    	<property name="directoryPath" value="${NDExSubmission.FileSubmissionRoot}/ndexSubmissionResponse/success/"/>
    </bean>

</beans>




© 2015 - 2025 Weber Informatics LLC | Privacy Policy