0

XML ペイロードを提供する単純なリソース クラスに基づいて構築された RESTful API のシードとして、サンプルの Camel ルートを作成しようとしています。

私が抱えている問題は、GET が機能していることです (XML の一部を構築するだけです) が、POST は次のエラーを返します:-

JAXBException occurred : ParseError at [row,col]:[1,1]
Message: Premature end of file.. ParseError at [row,col]:[1,1]
Message: Premature end of file..

XMLを定義するために、xjcを介してXSDから構築されたクラスを使用しています。GET によって返された XML を POST にコピーしても失敗するため、XML ペイロード構造の問題ではないことはわかっています。とはいえ、JAXB が最初の文字について不平を言っていることを考えると、エンコーディングについて不平を言っているのだろうかと思います。cURL と Chrome Postman の両方をクライアントとして使用しましたが、どちらも同じ応答を受け取りました。

newCustomerPOST メソッド ( ) が着信 XML ペイロードを解析できるようにする単純な注釈または設定が欠けているだけだと思います。

これが私のルートXMLです:-

<?xml version="1.0" encoding="UTF-8"?>
<blueprint
    xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
    xmlns:cxf="http://cxf.apache.org/blueprint/core"
    xmlns:camel="http://camel.apache.org/schema/blueprint"
    xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
">

    <camelContext id="goochjs-cameltest-customer" trace="false" xmlns="http://camel.apache.org/schema/blueprint">

        <route id="jetty">
            <from uri="jetty:http://0.0.0.0:8892/rest?matchOnUriPrefix=true" />
            <log logName="goochjs" loggingLevel="INFO" message="Request received 1: ${body}" />
            <to uri="cxfbean:customerResource" />
        </route>
    </camelContext>

    <bean id="customerResource" class="org.goochjs.cameltest.CustomerResourceImpl" />
</blueprint>

...そして私のリソース クラス...

package org.goochjs.cameltest;

import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/customers")
public class CustomerResourceImpl {

    @POST
    @Path("/{type}")
    public Response newCustomer(Customer customer, @PathParam("type") String type, @QueryParam("active") @DefaultValue("true") boolean active) {
        return Response.ok(type).build();
    }

    @GET
    @Path("/{type}")
    public Response getCustomer(@PathParam("type") String type) {
        Customer output = new Customer();
        output.setId(987654);
        output.setName("Willy Wonka");

        return Response.ok(output).build();
    }
}

最後に、サンプル XML を次に示します。

<?xml version="1.0" encoding="UTF-8"?>
<Customer>
    <name>Willy Wonka</name>
    <id>987654</id>
</Customer>

ご指摘ありがとうございます。確認しやすい場合は、プロジェクト全体が私の github サイトにパッケージ化されています。

J.

4

1 に答える 1

0

何時間も頭を悩ませた後、私はこれを解決しました。問題は、メッセージ本文がリソース クラスに提示されていないことでした。streamCache="true"Camel XML 内のルート ノードに追加したところ、機能し始めました。

Camel サイトの関連ページは次のとおりです - http://camel.apache.org/stream-caching.html

fromエンドポイントとして使用するパターンcxfrs://はこれを暗黙的に行うと思います。しかし、ブループリント XML 内でこれを機能させることができませんでした。そのため、事前に Jetty をデプロイしました。

J.

于 2013-04-23T15:40:44.450 に答える