camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Cook <ralph.c...@accesspointinc.com>
Subject trouble with camel spring web example
Date Mon, 05 Jun 2017 14:06:13 GMT
I am trying to work through an example from the camel website, namely camel-example-servlet-tomcat.
I want to get a web application working that takes input from a web service request and uses
it as the data with which to start a camel route. I am running Tomcat 7.0.63, Netbeans 8.02,
Windows 10 Pro. Java 1.7, Maven 3.0.4.

I can build the application; when I run it the initial page appears, with the link that's
supposed to invoke the camel-based route; on clicking that link, or on entering any variation
of its URL, I get 404, resource not available.

I tried copying the source for CamelHttpTransportServlet to another class and configuring
that one as CamelServlet, so that I could set breakpoints and see what is happening. I can
hit breakpoints there but still don't know why it isn't working.

I do not understand what part of this invokes .start() on Camel, and wonder if I'm missing
some step that does that. One difficulty I have with the documentation is that it seems to
treat all the examples as a block, invoking parent poms and giving instructions on compiling
all of them together; I didn't want to do this but finally attempted it; it requires not only
a more recent version of Maven than we use in my shop but a more recent version of Java, so
that route is really frought. This example is so simple, surely someone can tell me what I'm
doing wrong.

I have the following web.xml:

---

        <web-app version="1.1"
                 xmlns="http://www.springframework.org/schema/beans"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns:camel="http://camel.apache.org/schema/spring"
                 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">

            <context-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>classpath:camel-config.xml</param-value>
            </context-param>

            <listener>
                <!-- listener-class>org.apache.camel.component.servletlistener.SimpleCamelServletContextListener</listener-class
-->
                <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
            </listener>

            <servlet>
                <servlet-name>CamelServlet</servlet-name>
                <servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
                <!--init-param>
                        <param-name>contextConfigLocation</param-name>
                        <param-value>classpath:camel-config.xml</param-value>
                </init-param  -->

                <load-on-startup>1</load-on-startup>
            </servlet>

            <!-- all our webservices are mapped under this URI pattern -->
            <servlet-mapping>
                <servlet-name>CamelServlet</servlet-name>
                <url-pattern>/camel/*</url-pattern>
            </servlet-mapping>

        </web-app>

---

and the following camel-config.xml

        <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"
            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"
        >

          <camelContext xmlns="http://camel.apache.org/schema/spring">

            <route id="helloRoute">
              <!-- incoming requests from the servlet is routed -->
              <from uri="servlet:CamelServlet"/>
              <choice>
                <when>
                  <!-- is there a header with the key name? -->
                  <header>name</header>
                  <!-- yes so return back a message to the user -->
                  <transform>
                    <simple>Hi I am ${sysenv.HOSTNAME}. Hello ${header.name} how are
you today?</simple>
                  </transform>
                </when>
                <otherwise>
                  <!-- if no name parameter then output a syntax to the user -->
                  <transform>
                    <constant>Add a name parameter to uri, eg ?name=foo</constant>
                  </transform>
                </otherwise>
              </choice>
            </route>

          </camelContext>

        </beans>

---

Here's the pom.xml as well; I don't think it's related but of course don't know.

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <groupId>com.api</groupId>
        <artifactId>CamelOne</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>war</packaging>

        <name>CamelOne</name>

        <properties>
            <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <cxf-version>2.6.1</cxf-version>
            <camel-version>2.16.0</camel-version>
            <spring-version>4.1.6.RELEASE</spring-version>
            <!--log4j-version></log4j-version-->
        </properties>

        <dependencies>
            <!-- Camel -->
            <dependency><groupId>org.apache.camel</groupId>     <artifactId>camel-core</artifactId>
            <version>${camel-version}</version>    </dependency>
            <dependency><groupId>org.apache.camel</groupId>     <artifactId>camel-spring</artifactId>
          <version>${camel-version}</version>    </dependency>
            <dependency><groupId>org.apache.camel</groupId>     <artifactId>camel-servlet</artifactId>
         <version>${camel-version}</version>    </dependency>
            <dependency><groupId>org.apache.camel</groupId>     <artifactId>camel-servletlistener</artifactId>
 <version>${camel-version}</version>    </dependency>
            <!-- spring -->
            <dependency><groupId>org.springframework</groupId>  <artifactId>spring-web</artifactId>
    <version>${spring-version}</version>    </dependency>

            <dependency><groupId>javax.servlet</groupId>        <artifactId>javax.servlet-api</artifactId><version>3.1.0</version>
             </dependency>

            <!-- logging -->
            <!--dependency><groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api
          </artifactId>   <version>log4j-version</version> <scope>runtime</scope>
 </dependency-->
            <!--dependency><groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core
         </artifactId>   <version>log4j-version</version> <scope>runtime</scope>
 </dependency-->
            <!--dependency><groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl
   </artifactId>   <version>log4j-version</version> <scope>runtime</scope>
 </dependency-->

        </dependencies>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3.2</version>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                        <compilerArguments>
                            <endorseddirs>${endorsed.dir}</endorseddirs>
                        </compilerArguments>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.3</version>
                    <configuration>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.1</version>
                    <executions>
                        <execution>
                            <phase>validate</phase>
                            <goals>
                                <goal>copy</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${endorsed.dir}</outputDirectory>
                                <silent>true</silent>
                                <artifactItems>
                                    <artifactItem>
                                        <groupId>javax</groupId>
                                        <artifactId>javaee-endorsed-api</artifactId>
                                        <version>6.0</version>
                                        <type>jar</type>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <!-- CXF wsdl2java generator, will plugin to the compile goal -->
                <plugin>
                    <groupId>org.apache.cxf</groupId>
                    <artifactId>cxf-codegen-plugin</artifactId>
                    <version>${cxf-version}</version>
                    <executions>
                        <execution>
                            <id>generate-sources</id>
                            <phase>generate-sources</phase>
                            <configuration>
                                <sourceRoot>${basedir}/target/generated-sources/cxf/</sourceRoot>
                                <wsdlOptions>
                                    <wsdlOption>
                                        <wsdl>${basedir}/src/main/webapp/WEB-INF/wsdl/report_incident.wsdl</wsdl>
                                    </wsdlOption>
                                </wsdlOptions>
                            </configuration>
                            <goals>
                                <goal>wsdl2java</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>

    </project>

The contents of this email and any attachments to it may contain Customer Proprietary Network
Information (CPNI) as defined by the FCC and/or privileged and confidential information from
Access Point, Inc. Any and all of this information is only for the viewing or use of the intended
recipient. If you are not the intended recipient, you are hereby notified that any disclosure,
copying, distribution or use of, or the taking of any action in reliance upon, the information
contained in this e-mail, or any of the attachments to this e-mail, is strictly prohibited
and that this e-mail and all of the attachments to this e-mail, if any, must be immediately
returned to Access Point, Inc. or destroyed and, in either case, this e-mail and all attachments
to this e-mail must be immediately deleted from your computer without making any copies hereof.
If you have received this e-mail in error, please notify Access Point, Inc. by e-mail immediately.

Mime
View raw message