이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 160. XmlRpc


XmlRpc Component

Available as of Camel 2.11
This component provides a dataformat for xml, which allows serialization and deserialization of request messages and response message using Apache XmlRpc's bindary dataformat. You can also invoke the XMLRPC Service through the camel-xmlrpc producer.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-xmlrpc</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>
Copy to Clipboard Toggle word wrap

XmlRpc Overview

It's a spec and a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet.
It's remote procedure calling using HTTP as the transport and XML as the encoding. XML-RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted, processed and returned.
An example of a typical XML-RPC request would be:
<?xml version="1.0"?>
<methodCall>
  <methodName>examples.getStateName</methodName>
  <params>
    <param>
        <value><i4>40</i4></value>
    </param>
  </params>
</methodCall>
Copy to Clipboard Toggle word wrap
An example of a typical XML-RPC response would be:
<?xml version="1.0"?>
<methodResponse>
  <params>
    <param>
        <value><string>South Dakota</string></value>
    </param>
  </params>
</methodResponse>
Copy to Clipboard Toggle word wrap
A typical XML-RPC fault would be:
<?xml version="1.0"?>
<methodResponse>
  <fault>
    <value>
      <struct>
        <member>
          <name>faultCode</name>
          <value><int>4</int></value>
        </member>
        <member>
          <name>faultString</name>
          <value><string>Too many parameters.</string></value>
        </member>
      </struct>
    </value>
  </fault>
</methodResponse>
Copy to Clipboard Toggle word wrap

URI format

xmlrpc://serverUri[?options]
Copy to Clipboard Toggle word wrap

Options

Expand
Property Default Description
basicEncoding null Sets the encoding for basic authentication, null means UTF-8 is chosen.
basicUserName null The user name for basic authentication.
basicPassword null The password for basic authentication.
clientConfigurer null The reference id of the XmlRpcClient configurer which implement the interface of XmlRpcClientConfigurer to setup the XmlRpcClient as user wants. The value should be start with "#" such as "#myConfigurer"
connectionTimeout 0 Set the connection timeout in milliseconds, 0 is to disable it
contentLengthOptional false whether a "Content-Length" header may be omitted. The XML-RPC specification demands, that such a header be present.
enabledForExceptions false whether the response should contain a "faultCause" element in case of errors. The "faultCause" is an exception, which the server has trapped and written into a byte stream as a serializable object.
enabledForExtensions false whether extensions are enabled. By default, the client or server is strictly compliant to the XML-RPC specification and extensions are disabled.
encoding null Sets the requests encoding, null means UTF-8 is chosen.
gzipCompressing false Whether gzip compression is being used for transmitting the request.
gzipRequesting false Whether gzip compression is being used for transmitting the request.
replyTimeout 0 Set the reply timeout in milliseconds, 0 is to disable it.
userAgent null The http user agent header to set when doing xmlrpc requests

Message Headers

Camel XmlRpc uses these headers.
Expand
Header Description
CamelXmlRpcMethodName The XmlRpc method name which will be use for invoking the XmlRpc server.

Using the XmlRpc data format

As the XmlRpc message could be request or response, when you use the XmlRpcDataFormat, you need to specify the dataformat is for request or not.
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">

    <!-- we define the xml rpc data formats to be used -->
    <dataFormats>
        <xmlrpc id="xmlrpcRequest" request="true"/>
        <xmlrpc id="xmlrpcResponse" request="false"/>
    </dataFormats>

    <route>
        <from uri="direct:request"/>
        <marshal ref="xmlrpcRequest"/>
        <unmarshal>
           <xmlrpc request="true"/>
        </unmarshal>
        <to uri="mock:request" />
    </route>

    <route>
        <from uri="direct:response"/>
        <marshal>
            <xmlrpc request="false"/>
        </marshal>
        <unmarshal ref="xmlrpcResponse"/>
        <to uri="mock:response" />
    </route>
</camelContext>
Copy to Clipboard Toggle word wrap

Invoke XmlRpc Service from Client

To invoke the XmlRpc service, you need to specify the methodName on the message header and put the parameters into the message body like below code, then you can get the result message as you want. If the fault message is return, you should get an exception which cause if XmlRpcException.
   String response = template.requestBodyAndHeader(xmlRpcServiceAddress, new Object[]{"me"}, XmlRpcConstants.METHOD_NAME, "hello", String.class);
Copy to Clipboard Toggle word wrap

How to configure the XmlRpcClient with Java code

camel-xmlrpc provides a pluggable strategy for configuring the XmlRpcClient used by the component, user just to implement the XmlRpcClientConfigurer interface and can configure the XmlRpcClient as he wants. The clientConfigure instance reference can be set through the uri option clientConfigure.
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;

public class MyClientConfigurer implements XmlRpcClientConfigurer {

    @Override
    public void configureXmlRpcClient(XmlRpcClient client) {
        // get the configure first
        XmlRpcClientConfigImpl clientConfig = (XmlRpcClientConfigImpl)client.getClientConfig();
        // change the value of clientConfig
        clientConfig.setEnabledForExtensions(true);
        // set the option on the XmlRpcClient
        client.setMaxThreads(10);
    }

}
Copy to Clipboard Toggle word wrap
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat