Friday 7 October 2016

Apache Camel - https Rest

Problem:

Hi Guys I have assigned an task on adding https for Rest in Apache Camel. I spent more time on this to get ti working , finally achieved. I thought of sharing with community  for easy to go.

Solution:


  1. We need to add SSL Context Parameters
  2. Add "CamelContextId" to SSLContextParameters Section.
  3. Add "Id" to SSLContextParameters which it later can be linked to where ever we need in the Camel Context defined.

   

 <sslcontextparameters camelcontextid="RestLab" id="sslContext_rest" xmlns="http://camel.apache.org/schema/spring">
  <keymanagers keypassword="keypassword">
   <keystore password="keystorePassword" resource="yourKeystore.jks">
   </keystore>
  </keymanagers>
  <serverparameters clientauthentication="WANT">
   <clientparameters>
    <ciphersuitesfilter>
     <include>.* </include>
    </ciphersuitesfilter>
   </clientparameters>
  </serverparameters>
 </sslcontextparameters>

 <camelcontext id="RestLab">
  <restconfiguration bindingmode="auto" component="restlet" enablecors="true" port="8080" scheme="https">

   <endpointproperty key="sslContextParameters" value="#sslContext_rest">
    <corsheaders key="Access-Control-Allow-Origin" value="*">
     <corsheaders key="Access-Control-Allow-Headers" value="Origin, Accept, X-Requested-With,
                                Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers">
      <corsheaders key="Access-Control-Allow-Methods" value="PUT,POST,GET,DELETE,OPTIONS">
      </corsheaders>
     </corsheaders>
    </corsheaders>
   </endpointproperty>
  </restconfiguration>
 </camelcontext>
 



XML Assistance in Eclipse - Apache Camel or for Any XSD

Problem:
I have a problem with xml assistance while writing camel routes and tried all the ways I didn't able to get it .


Solution:
In order to get assistance from eclipse using "ctrl+space" , you have to add namespace prefix for expected namespace . Then Eclipse will give you xml assistance.

Error:
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

<camel:sslContextParameters camelContextId="" id="">
<camel:cipherSuites ></camel:cipherSuites>
</camel:sslContextParameters>
<!-- No XMl Assistance here  ->


</beans>



Solved:

<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

<camel:sslContextParameters camelContextId="" id="">
<camel:cipherSuites ></camel:cipherSuites>
</camel:sslContextParameters>

<!--  XML Assistance working here -->

</beans>