camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > XmlRpc
Date Thu, 22 Nov 2012 06:03:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/XmlRpc">XmlRpc</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~njiang">willem
jiang</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        CAMEL-5814<br />
    </div>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h3.
URI format <br> <br>{code} <br>xmlrpc://serverUri[?options] <br>{code}
<br> <br>h3. Options <br>{div:class=confluenceTableSmall} <br>|| Property
|| Default || Description || <br>| {{basicEncoding}} | {{null}} | Sets the encoding
for basic authentication, null means UTF-8 is chosen. | <br>| {{basicUserName}} | {{null}}
| The user name for basic authentication. | <br>| {{basicPassword}} | {{null}} | The
password for basic authentication. | <br>| {{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 &quot;#&quot;
such as &quot;#myConfigurer&quot;| <br>| {{connectionTimeout}} | {{0}} | Set
the connection timeout in milliseconds, 0 is to disable it| <br>| {{contentLengthOptional}}
| {{false}} | whether a &quot;Content-Length&quot; header may be omitted. The XML-RPC
specification demands, that such a header be present. | <br>| {{enabledForExceptions}}
| {{false}} | whether the response should contain a &quot;faultCause&quot; element
in case of errors. The &quot;faultCause&quot; is an exception, which the server has
trapped and written into a byte stream as a serializable object. | <br>| {{enabledForExtensions}}|
{{false}} | whether extensions are enabled. By default, the client or server is strictly compliant
to the XML-RPC specification and extensions are disabled.| <br>| {{encoding}} | {{null}}
| Sets the requests encoding, null means UTF-8 is chosen. | <br>| {{gzipCompressing}}
| {{false}} | Whether gzip compression is being used for transmitting the request. | <br>|
{{gzipRequesting}} | {{false}} | Whether gzip compression is being used for transmitting the
request. | <br>| {{replyTimeout}} | {{0}} | Set the reply timeout in milliseconds, 0
is to disable it. | <br>| {{userAgent}} | {{null}} | The http user agent header to set
when doing xmlrpc requests | <br> <br>{div} <br> <br>h3. Message Headers
<br>Camel XmlRpc uses these headers. <br>{div:class=confluenceTableSmall} <br>||
Header || Description || <br>| {{CamelXmlRpcMethodName}} | The XmlRpc method name which
will be use for invoking the XmlRpc server. | <br>{div} <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. Using the XmlRpc data format <br>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. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >   String response = template.requestBodyAndHeader(xmlRpcServiceAddress,
new Object[]{&quot;me&quot;}, XmlRpcConstants.METHOD_NAME, &quot;hello&quot;,
String.class); <br>{code} <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
<br>h3. How to configure the XmlRpcClient with Java code <br>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.
<br> <br>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-xmlrpc/src/test/resources/org/apache/camel/component/xmlrpc/MyClientConfigurer.java}
<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="XmlRpc-XmlRpcComponent"></a>XmlRpc Component</h2>
<p><b>Available as of Camel 2.11</b></p>

<p>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.</p>

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt>
for this component:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span
class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-xmlrpc<span
class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same
version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

<h3><a name="XmlRpc-XmlRpcOverview"></a>XmlRpc Overview</h3>

<p>It's a <a href="http://xmlrpc.scripting.com/spec" class="external-link" rel="nofollow">spec</a>
and a set of implementations that allow software running on disparate operating systems, running
in different environments to make procedure calls over the Internet. </p>

<p>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.</p>

<p>An example of a typical XML-RPC request would be:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;?xml version=<span class="code-quote">"1.0"</span>?&gt;
&lt;methodCall&gt;
  &lt;methodName&gt;examples.getStateName&lt;/methodName&gt;
  &lt;params&gt;
    &lt;param&gt;
        &lt;value&gt;&lt;i4&gt;40&lt;/i4&gt;&lt;/value&gt;
    &lt;/param&gt;
  &lt;/params&gt;
&lt;/methodCall&gt;
</pre>
</div></div>

<p>An example of a typical XML-RPC response would be:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;?xml version=<span class="code-quote">"1.0"</span>?&gt;
&lt;methodResponse&gt;
  &lt;params&gt;
    &lt;param&gt;
        &lt;value&gt;&lt;string&gt;South Dakota&lt;/string&gt;&lt;/value&gt;
    &lt;/param&gt;
  &lt;/params&gt;
&lt;/methodResponse&gt;
</pre>
</div></div>

<p>A typical XML-RPC fault would be:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;?xml version=<span class="code-quote">"1.0"</span>?&gt;
&lt;methodResponse&gt;
  &lt;fault&gt;
    &lt;value&gt;
      &lt;struct&gt;
        &lt;member&gt;
          &lt;name&gt;faultCode&lt;/name&gt;
          &lt;value&gt;&lt;<span class="code-object">int</span>&gt;4&lt;/<span
class="code-object">int</span>&gt;&lt;/value&gt;
        &lt;/member&gt;
        &lt;member&gt;
          &lt;name&gt;faultString&lt;/name&gt;
          &lt;value&gt;&lt;string&gt;Too many parameters.&lt;/string&gt;&lt;/value&gt;
        &lt;/member&gt;
      &lt;/struct&gt;
    &lt;/value&gt;
  &lt;/fault&gt;
&lt;/methodResponse&gt;
</pre>
</div></div>

<h3><a name="XmlRpc-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
xmlrpc:<span class="code-comment">//serverUri[?options]</span>
</pre>
</div></div>

<h3><a name="XmlRpc-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>basicEncoding</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Sets the encoding for basic authentication, null means UTF-8
is chosen. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>basicUserName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The user name for basic authentication. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>basicPassword</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The password for basic authentication. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>clientConfigurer</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> 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"</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>connectionTimeout</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> Set the connection timeout in milliseconds, 0 is to disable
it</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>contentLengthOptional</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> whether a "Content-Length" header may be omitted. The XML-RPC
specification demands, that such a header be present. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>enabledForExceptions</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> 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. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>enabledForExtensions</tt></td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> whether extensions are enabled. By default, the client or
server is strictly compliant to the XML-RPC specification and extensions are disabled.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>encoding</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Sets the requests encoding, null means UTF-8 is chosen. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>gzipCompressing</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Whether gzip compression is being used for transmitting the
request. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>gzipRequesting</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Whether gzip compression is being used for transmitting the
request. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>replyTimeout</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> Set the reply timeout in milliseconds, 0 is to disable it.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>userAgent</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The http user agent header to set when doing xmlrpc requests
</td>
</tr>
</tbody></table>
</div>

</div>

<h3><a name="XmlRpc-MessageHeaders"></a>Message Headers</h3>
<p>Camel XmlRpc uses these headers.</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelXmlRpcMethodName</tt> </td>
<td class='confluenceTd'> The XmlRpc method name which will be use for invoking the
XmlRpc server. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="XmlRpc-UsingtheXmlRpcdataformat"></a>Using the XmlRpc data
format</h3>
<p>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.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">&lt;camelContext id=<span class="code-quote">"camel"</span>
xmlns=<span class="code-quote">"http:<span class="code-comment">//camel.apache.org/schema/spring"</span>&gt;
</span>
    &lt;!-- we define the xml rpc data formats to be used --&gt;
    &lt;dataFormats&gt;
        &lt;xmlrpc id=<span class="code-quote">"xmlrpcRequest"</span> request=<span
class="code-quote">"<span class="code-keyword">true</span>"</span>/&gt;
        &lt;xmlrpc id=<span class="code-quote">"xmlrpcResponse"</span> request=<span
class="code-quote">"<span class="code-keyword">false</span>"</span>/&gt;
    &lt;/dataFormats&gt;

    &lt;route&gt;
        &lt;from uri=<span class="code-quote">"direct:request"</span>/&gt;
        &lt;marshal ref=<span class="code-quote">"xmlrpcRequest"</span>/&gt;
        &lt;unmarshal&gt;
           &lt;xmlrpc request=<span class="code-quote">"<span class="code-keyword">true</span>"</span>/&gt;
        &lt;/unmarshal&gt;
        &lt;to uri=<span class="code-quote">"mock:request"</span> /&gt;
    &lt;/route&gt;

    &lt;route&gt;
        &lt;from uri=<span class="code-quote">"direct:response"</span>/&gt;
        &lt;marshal&gt;
            &lt;xmlrpc request=<span class="code-quote">"<span class="code-keyword">false</span>"</span>/&gt;
        &lt;/marshal&gt;
        &lt;unmarshal ref=<span class="code-quote">"xmlrpcResponse"</span>/&gt;
        &lt;to uri=<span class="code-quote">"mock:response"</span> /&gt;
    &lt;/route&gt;
&lt;/camelContext&gt;
</pre>
</div></div>

<h3><a name="XmlRpc-InvokeXmlRpcServicefromClient"></a>Invoke XmlRpc Service
from Client</h3>
<p>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.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
   <span class="code-object">String</span> response = template.requestBodyAndHeader(xmlRpcServiceAddress,
<span class="code-keyword">new</span> <span class="code-object">Object</span>[]{<span
class="code-quote">"me"</span>}, XmlRpcConstants.METHOD_NAME, <span class="code-quote">"hello"</span>,
<span class="code-object">String</span>.class);
</pre>
</div></div>

<h3><a name="XmlRpc-HowtoconfiguretheXmlRpcClientwithJavacode"></a>How to
configure the XmlRpcClient with Java code</h3>
<p>camel-xmlrpc provides a pluggable strategy for configuring the XmlRpcClient used
by the component, user just to implement the <b>XmlRpcClientConfigurer</b> interface
and can configure the XmlRpcClient as he wants. The clientConfigure instance reference can
be set through the uri option clientConfigure.</p>

<div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException:
Index: 20, Size: 20</span> </div>


    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/XmlRpc">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=30742733&revisedVersion=2&originalVersion=1">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/XmlRpc?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message