3 Replies Latest reply on Sep 25, 2013 7:52 PM by Keith Babo

    How to handle HTTP multipart data

    Paulo Sigrist Newbie

      Hello all!


      I'm starting with JBoss SwitchYard and I want to replace a old system we have here. The system integrates with others receiving a HTTP Post Multipart form. The content is a Json and a zip file. My service must split this post and save into the file system. I used to do this with Apache Camel, using the servlet component, routing to the file component.


      I did try with SwitchYard, and created something like this:


      <?xml version="1.0" encoding="UTF-8"?>
      <switchyard xmlns="urn:switchyard-config:switchyard:1.0" xmlns:bean="urn:switchyard-component-bean:config:1.0" xmlns:camel="urn:switchyard-component-camel-core:config:1.0" xmlns:http="urn:switchyard-component-http:config:1.0" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" name="rat-receiver" targetNamespace="urn:com.sigrist:rat-receiver:1.0">
        <sca:composite name="rat-receiver" targetNamespace="urn:com.sigrist:rat-receiver:1.0">
          <sca:component name="DataReceiverBean">
            <bean:implementation.bean class="com.sigrist.receiver.DataReceiverBean"/>
            <sca:service name="DataReceiver">
              <sca:interface.java interface="com.sigrist.receiver.DataReceiver"/>
          <sca:service name="DataReceiver" promote="DataReceiverBean/DataReceiver">
            <sca:interface.java interface="com.sigrist.receiver.DataReceiver"/>
            <camel:binding.uri name="camel1" configURI="servlet:///data?servletName=CamelHttpMultipartServlet">
              <operationSelector operationName="foo2"/>
              <camel:messageComposer class="com.sigrist.receiver.MyCustomMessageComposer"/>


      But when I started JBoss, I receive the error messsage:


      Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: servlet:///data?servletName=CamelHttpMultipartServlet due to: No component found with scheme: servlet


      My pom.xml has the camel-servlet component, but looks like it is not register into camel context used by SwitchYard.


      Another try was to use the HTTP Binding. I received the multipart data, but the format is a StringReader, and I need to parse manually the data. I wanted to use something ready, like the ServletFileUpload from the apache commons file upload.


      How can I handle this kind of data with SwitchYard?


      Thanks in advanced


        • 1. Re: How to handle HTTP multipart data
          Keith Babo Master

          Sorry for the late reply.  Notifications from the forums have been a bit spotty lately, so I'm only seeing some of these posts when I actually cruise through the discussion list.


          If you are using a Camel component not shipped with SwitchYard, then using the Camel URI gateway (as you are doing) is the right way to go.  In addition to using the URI in your switchyard.xml, you'll need to do two things:


          1) Package the Camel component you are using as a module in JBoss AS 7.  You can find many examples in the SwitchYard distribution already under modules/system/layers/soa/org/apache/camel/components.  This basically involves creating a directory and module.xml and then adding whatever jars are required for the component.


          2) Add an entry to the extension components list in standalone.xml with the name of the module you added, e.g.


          <subsystem xmlns="urn:jboss:domain:switchyard:1.0">
               <!--- content snipped for brevity -->
                    <extension identifier="org.apache.camel.mvel"/>
                    <extension identifier="org.apache.camel.ognl"/>
                    <extension identifier="org.apache.camel.jaxb"/>
                    <extension identifier="org.apache.camel.soap"/>
                    <!-- name of the module you packaged for the Camel Servlet component -->
                    <extension identifier="org.apache.camel.servlet"/>




          1 of 1 people found this helpful
          • 2. Re: Re: How to handle HTTP multipart data
            Paulo Sigrist Newbie

            Hi Keith,


            thanks for your reply!


            I had a suspicion that I should load the camel component as modules. I did what you told me and it's working now. I created two new modules into $JBOSS_HOME/modules/layers/soa/org/apache/camel called http and servlet. Added the extensions entries into standalone-full.xml. After started JBOSS, I can see the routes loaded into Camel:


            13:33:30,585 INFO  [org.switchyard.common.camel.SwitchYardCamelContext] (MSC service thread 1-8) Apache Camel 1.0.0.Final (CamelContext: camel-1) started in 0.390 seconds
            13:33:30,804 INFO  [org.apache.camel.impl.converter.DefaultTypeConverter] (MSC service thread 1-8) Loaded 179 type converters
            13:33:32,206 INFO  [org.switchyard.common.camel.SwitchYardCamelContext] (MSC service thread 1-8) Route: direct:{urn:com.sigrist.receiver:data-receiver:1.0}DataReceiver started and consuming from: Endpoint[direct://%7Burn:com.sigrist.receiver:data-receiver:1.0%7DDataReceiver]
            13:33:32,637 INFO  [org.switchyard.common.camel.SwitchYardCamelContext] (MSC service thread 1-8) Route: V1CamelBindingModel/DataReceiver@camel1#-1699414500 started and consuming from: Endpoint[servlet://data]
            13:33:32,677 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS018559: Deployed "data-receiver.jar" (runtime-name : "data-receiver.jar")


            The problem now is when I try to call the servlet I got the 404 Page not found from the server.

            What I think it is missing now is the servlet configuration, required by the camel-servlet component :


                <display-name>Camel Http Transport Servlet</display-name>



            Is it possible to add this configuration into the the SY component?





            • 3. Re: How to handle HTTP multipart data
              Keith Babo Master

              I have no experience with the Camel servlet component, so keep that in mind when considering the advice I offer. ;-) 


              Digging around in the camel-servlet code and looking at some of the examples available on the Camel site, it looks like a Camel servlet is registered via web.xml and uses an in-memory registry to communicate with servlet consumer endpoints in Camel routes.  In order for this to work with a SwitchYard application, you would need to package your SY app as a WAR and then include a web.xml containing the servlet mapping you included above.  That *should* allow the servlet to register a context with JBoss Web during deployment.  The communication between the Camel servlet and the camel-servlet endpoint (which you are using as a service binding) would then happen as usual via the in-memory registry.