调用骆驼的Restlet制片给人一种异常 [英] Invoking Camel restlet producer giving an exception
问题描述
我工作的一个示例应用程序使用骆驼路由调用一个RESTful Web服务。其余的服务是安全的。 I codeD这样的
I am working on a sample application to invoke a RESTful web service using camel routing. And the REST service is secured. I coded like this
from("file:data/source?noop=true")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.HTTP_METHOD, "POST");
exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/xml");
exchange.getIn().setHeader(RestletConstants.RESTLET_LOGIN, "xxxx");
exchange.getIn().setHeader(RestletConstants.RESTLET_PASSWORD, "xxxx");
}
})
.to("restlet:http://xxxx/xxxx/batch/query-by-hwid.xml");
我刚采摘的XML文件从端点是输入或身体REST服务。并通过这个XML的REST服务之前,我对安全设置的标头。但我不能打的服务,这是给我一个异常说
I am just picking xml file in from endpoint which is input or body to the REST service. And before passing this xml to the REST service, am setting up the headers for security. But am not able to hit the service and it is giving me an exception saying
org.apache.camel.component.restlet.RestletOperationException: Restlet operation failed invoking http://xxxx/xxxxx/batch/query-by-hwid.xml with statusCode: 405 /n responseBody:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Draft//EN">
<HTML>
<HEAD>
<TITLE>Error 405--Method Not Allowed</TITLE>
<META NAME="GENERATOR" CONTENT="WebLogic Server">
</HEAD>
<BODY bgcolor="white">
<FONT FACE=Helvetica><BR CLEAR=all>
<TABLE border=0 cellspacing=5><TR><TD><BR CLEAR=all>
<FONT FACE="Helvetica" COLOR="black" SIZE="3"><H2>Error 405--Method Not Allowed</H2>
</FONT></TD></TR>
</TABLE>
<TABLE border=0 width=100% cellpadding=10><TR><TD VALIGN=top WIDTH=100% BGCOLOR=white><FONT FACE="Courier New"><FONT FACE="Helvetica" SIZE="3"><H3>From RFC 2068 <i>Hypertext Transfer Protocol -- HTTP/1.1</i>:</H3>
</FONT><FONT FACE="Helvetica" SIZE="3"><H4>10.4.6 405 Method Not Allowed</H4>
</FONT><P><FONT FACE="Courier New">The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response MUST include an Allow header containing a list of valid methods for the requested resource.</FONT></P>
</FONT></TD></TR>
</TABLE>
</BODY>
</HTML>
我应该心存感激,如果你可以在此提供一些线索。谢谢。
我使用的骆驼版本:2.13
I will be thankful if you can shed some light on this. Thank you. I am using Camel Version : 2.13.
推荐答案
REST服务通常需要并使用Accept头。
Rest services usually requires and use the Accept header.
所以,你应该设置这个头文件
So you should set this header
exchange.getIn().setHeader("Accept", "application/xml");
这篇关于调用骆驼的Restlet制片给人一种异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!