为 websocket 服务器定义 servicemix xml



我尝试在servicemix中仅使用XML开发Websocket服务器,但我无法使其工作。甚至没有接近。

我有一个基于 rest 的示例,我想把它变成一个 websocket 服务器。

我已经尝试了一些事情,但结果总是我得到一个完全没有连接的 404 回来。我假设我必须像使用 http 服务一样注册 websocket 服务,但我找不到任何文档如何以与我的示例类似的方式执行此操作。

任何建议将不胜感激。

下面是示例:

<?xml version="1.0" encoding="UTF-8"?>
<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:camel="http://camel.apache.org/schema/spring"
  xmlns:util="http://www.springframework.org/schema/util"
  xmlns:osgi="http://www.springframework.org/schema/osgi"
  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://www.springframework.org/schema/util
     http://www.springframework.org/schema/util/spring-util.xsd
     http://www.springframework.org/schema/context
     http://www.springframework.org/schema/context/spring-context.xsd
     http://www.springframework.org/schema/osgi
     http://www.springframework.org/schema/osgi/spring-osgi.xsd">
  <osgi:reference id="httpService" interface="org.osgi.service.http.HttpService"/>
  <bean id="SelectCamelServlet"
    class="org.apache.camel.component.servlet.CamelHttpTransportServlet">
  </bean>
  <bean class="org.apache.camel.component.servlet.osgi.OsgiServletRegisterer"
    init-method="register"
    destroy-method="unregister">
    <property name="alias" value="/cmsa"/>
    <property name="httpService" ref="httpService"/>
    <property name="servlet" ref="SelectCamelServlet"/>
    <property name="servletName" value="SelectCamelServlet"/>
  </bean>
<bean id="datasource"
    class="org.apache.commons.dbcp2.BasicDataSource">
    <property name="driverClassName" value="org.postgresql.Driver"/>
    <property name="url" value="jdbc:postgresql://localhost/postgres"/>
    <property name="username" value="postgres"/>
    <property name="password" value="postgres"/>
  </bean>
  <!-- Configure the Camel SqlComponent to use the JDBC datasource. -->
  <bean id="sqlcomponent"
    class="org.apache.camel.component.sql.SqlComponent">
    <property name="dataSource" ref="datasource"/>
  </bean>
  <!-- Configure a camelContext with logic. -->
  <camelContext useMDCLogging="true" xmlns="http://camel.apache.org/schema/spring">
    <restConfiguration bindingMode="json" component="servlet">
      <endpointProperty key="servletName" value="SelectCamelServlet" />
      <dataFormatProperty key="prettyPrint" value="false"/>
    </restConfiguration>
    <rest path="/density">
      <get uri="">
        <to pattern="InOut" uri="direct:get" />
      </get>
    </rest>
    <!-- Configure a route that reads an argument from http (GET),
         uses that in a query and returns the dataset in JSON format. -->
    <route id="oefenen_route">
      <from uri="direct:get"/>
      <!-- Specify content-type to control the body's character encoding.
           If this is omitted, the body's data is base64 encoded. -->
     <setHeader headerName="Content-Type">
        <simple>application/json; charset=utf-8</simple>
      </setHeader>
      <!-- Run the query. -->
      <to uri="sqlcomponent:select sensor, aantal as density from cmsa order by sensor?
               outputType=SelectList&amp;
               greedy=true&amp;
               useIterator=false"/>
    </route>
  </camelContext>
</beans>

我解决了自己的问题如下:

<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:camel="http://camel.apache.org/schema/spring"
  xmlns:util="http://www.springframework.org/schema/util"
  xmlns:osgi="http://www.springframework.org/schema/osgi"
  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://www.springframework.org/schema/util
     http://www.springframework.org/schema/util/spring-util.xsd
     http://www.springframework.org/schema/context
     http://www.springframework.org/schema/context/spring-context.xsd
     http://www.springframework.org/schema/osgi
     http://www.springframework.org/schema/osgi/spring-osgi.xsd">
  <osgi:reference id="wsService" interface="org.osgi.service.http.HttpService"/>
  <bean id="CamelWsServlet"
    class="org.apache.camel.component.atmosphere.websocket.CamelWebSocketServlet">
  </bean>
  <bean class="org.apache.camel.component.servlet.osgi.OsgiServletRegisterer"
    init-method="register"
    destroy-method="unregister">
    <property name="alias" value="/websocket"/>
    <property name="httpService" ref="wsService"/>
    <property name="servlet" ref="CamelWsServlet"/>
    <property name="servletName" value="CamelWsServlet"/>
  </bean>
  <camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="atmosphere-websocket:///hola"/>
        <to uri="atmosphere-websocket:///hola?sendToAll=true"/>
    </route>
  </camelContext>
</beans>

第二个列表回答了我的问题。我做的几乎与第一个列表中相同,只是使用的类不同。如果我将其作为 xml 文件放在 servicemix 部署目录中,这工作正常。

最新更新