0

URI から ID を取得し、それを条件として SQL 要求に入れます 結果を XML 形式にした後

これは機能です:

package com.mycompany.camel.blueprint;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
public class Testws {
    @GET
    @Path("/test/{id}")
    @Produces(MediaType.APPLICATION_XML)
    public Integer getAssets(@PathParam("id") int id){

        return id;
    }
  }

これはルートです:

<camelContext id="camel"    xmlns="http://camel.apache.org/schema/blueprint">
     <route>
       <from uri="cxfrs://bean://rsServer"/>
       <log message="${body}"/>
       <convertBodyTo type="java.lang.Integer"/>
       <to uri="sql:select * from customers where id=:#${body}?exchangePattern=InOut&amp;dataSource=moodleDB"/>
            </route>    </camelContext>

次のエラー: http://localhost:5070/route/test/1

This page contains the following errors:

error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.

xml ドキュメントを取得するにはどうすればよいですか? ありがとう ?

4

1 に答える 1

0

cxfrs を使用してキャメル ルートから xml を返すには、いくつかのものが必要です。

  • クラスの @XmlRootElement で注釈が付けられた顧客オブジェクトと、jaxb にマーシャリング方法を伝えるその他の xml 注釈
  • 次のように cxf サーバーで定義された xml プロバイダー:

    <cxf:rsServer id="rsServer" address="${url}">
        <cxf:serviceBeans>
            <bean class="com.mycompany.camel.blueprint.Testws"/>
        </cxf:serviceBeans>
        <cxf:providers>
            <bean class="com.fasterxml.jackson.jaxrs.xml.JacksonJaxbJsonProvider"/>
        </cxf:providers>
    </cxf:rsServer>
    

SQL 呼び出しからの応答を顧客オブジェクトのリストに処理する必要があります。その後、cxf はこのプロバイダーを使用して xml にマーシャリングできます。

これを使用するには、jackson-jaxrs-xml-provider への依存関係が必要になります。

于 2015-10-11T19:52:54.463 に答える