我需要以编程方式(使用类中介),设置外发消息的格式。我知道我可以通过设置地址的格式属性,例如
,在xml中完成<address uri="http://localhost/servicetest/test.svc/soap" format="soap11">
但是我需要以编程方式设置它,因为我在WSO2 Api Manager中,所以我无法修改自动生成的api配置。
我也知道我可以使用高级配置在api发布者中设置它,但是我需要在某些条件的基础上在运行时设置它。
如何在运行时更改此属性?
更新
如果我按照Jean-Michel的建议将axis2属性设置为text / xml,则消息将以xml但不是soap的形式发送,而且有些数字会在发送的xml之后显示:
TID: [0] [AM] [2015-04-14 12:36:28,873] DEBUG {org.apache.synapse.transport.http.wire} - << "POST http://localhost/servicetest/test.svc/rest/test1/test2 HTTP/1.1[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 12:36:28,873] DEBUG {org.apache.synapse.transport.http.wire} - << "PD_SUBSCRIBER: admin@applicationprovider.it[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 12:36:28,873] DEBUG {org.apache.synapse.transport.http.wire} - << "PD_API_VERSION: rest[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 12:36:28,873] DEBUG {org.apache.synapse.transport.http.wire} - << "PD_API_PUBLISHER: admin@serviceprovider.it[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 12:36:28,873] DEBUG {org.apache.synapse.transport.http.wire} - << "PD_APPLICATION_ID: 1[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 12:36:28,873] DEBUG {org.apache.synapse.transport.http.wire} - << "Content-Type: application/json[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 12:36:28,874] DEBUG {org.apache.synapse.transport.http.wire} - << "Accept: */*[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 12:36:28,874] DEBUG {org.apache.synapse.transport.http.wire} - << "PD_API_NAME: rest[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 12:36:28,874] DEBUG {org.apache.synapse.transport.http.wire} - << "PD_APPLICATION_NAME: DefaultApplication[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 12:36:28,874] DEBUG {org.apache.synapse.transport.http.wire} - << "Transfer-Encoding: chunked[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 12:36:28,874] DEBUG {org.apache.synapse.transport.http.wire} - << "Host: localhost:80[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 12:36:28,874] DEBUG {org.apache.synapse.transport.http.wire} - << "Connection: Keep-Alive[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 12:36:28,874] DEBUG {org.apache.synapse.transport.http.wire} - << "User-Agent: Synapse-PT-HttpComponents-NIO[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 12:36:28,874] DEBUG {org.apache.synapse.transport.http.wire} - << "[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 12:36:28,874] DEBUG {org.apache.synapse.transport.http.wire} - << "15[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 12:36:28,874] DEBUG {org.apache.synapse.transport.http.wire} - << "<Prop1>prova1</Prop1>[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 12:36:28,874] DEBUG {org.apache.synapse.transport.http.wire} - << "0[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 12:36:28,874] DEBUG {org.apache.synapse.transport.http.wire} - << "[\r][\n]" {org.apache.synapse.transport.http.wire}
更新2
我设法通过以编程方式将messageType与setDoingREST结合使用来获取休息:
((Axis2MessageContext) msgCtx).getAxis2MessageContext().setDoingREST(false);
((Axis2MessageContext) msgCtx).getAxis2MessageContext().setProperty("messageType","text/xml");
但我仍然得到一些奇怪的输出......
TID: [0] [AM] [2015-04-14 16:07:04,438] DEBUG {org.apache.synapse.transport.http.wire} - << "POST http://localhost/servicetest/test.svc/rest/test1/test2 HTTP/1.1[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 16:07:04,438] DEBUG {org.apache.synapse.transport.http.wire} - << "PD_SUBSCRIBER: admin@applicationprovider.it[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 16:07:04,438] DEBUG {org.apache.synapse.transport.http.wire} - << "PD_API_VERSION: rest2[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 16:07:04,438] DEBUG {org.apache.synapse.transport.http.wire} - << "PD_API_PUBLISHER: admin@serviceprovider.it[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 16:07:04,438] DEBUG {org.apache.synapse.transport.http.wire} - << "PD_APPLICATION_ID: 1[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 16:07:04,438] DEBUG {org.apache.synapse.transport.http.wire} - << "Content-Type: application/json[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 16:07:04,438] DEBUG {org.apache.synapse.transport.http.wire} - << "Accept: */*[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 16:07:04,438] DEBUG {org.apache.synapse.transport.http.wire} - << "PD_API_NAME: rest[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 16:07:04,438] DEBUG {org.apache.synapse.transport.http.wire} - << "PD_APPLICATION_NAME: DefaultApplication[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 16:07:04,438] DEBUG {org.apache.synapse.transport.http.wire} - << "Transfer-Encoding: chunked[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 16:07:04,438] DEBUG {org.apache.synapse.transport.http.wire} - << "Host: localhost:80[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 16:07:04,438] DEBUG {org.apache.synapse.transport.http.wire} - << "Connection: Keep-Alive[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 16:07:04,438] DEBUG {org.apache.synapse.transport.http.wire} - << "User-Agent: Synapse-PT-HttpComponents-NIO[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 16:07:04,438] DEBUG {org.apache.synapse.transport.http.wire} - << "[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 16:07:04,438] DEBUG {org.apache.synapse.transport.http.wire} - << "b5[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 16:07:04,438] DEBUG {org.apache.synapse.transport.http.wire} - << "<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><Prop1>prova1</Prop1></soapenv:Body></soapenv:Envelope>[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 16:07:04,438] DEBUG {org.apache.synapse.transport.http.wire} - << "0[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [AM] [2015-04-14 16:07:04,438] DEBUG {org.apache.synapse.transport.http.wire} - << "[\r][\n]" {org.apache.synapse.transport.http.wire}
答案 0 :(得分:1)
在WSO2 ESB中,您可以定义名为&#34; messageType &#34;的属性。在范围&#34; axis2 &#34;。如果您要发送 soap11 消息,请将其值设置为&#34; text / xml &#34;如果您要发送 soap12 消息,请将其值设置为&#34; application / soap + xml &#34;