cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache CXF Documentation > How to Define Policies
Date Wed, 07 Mar 2012 16:08:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CXF20DOC&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/CXF20DOC/How+to+Define+Policies">How
to Define Policies</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~ashakirin">Andrei
Shakirin</a>
    </h4>
        <br/>
                         <h4>Changes (0)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>There are basically 3 main possibilities to define WS-Policy in CXF projects:</p>
<ol>
	<li>WSDL Policy attachment</li>
	<li>Spring configuration</li>
	<li>Dynamically via message context property</li>
</ol>


<p>Let look into them in details. </p>

<h4><a name="HowtoDefinePolicies-WSDLPolicyattachment"></a>WSDL Policy attachment</h4>
<p>WS-Policies can be attached and referenced in WSDL elements. <a href="http://www.w3.org/TR/ws-policy-attach/"
class="external-link" rel="nofollow">Web Services Policy 1.5 - Attachment </a> standard
describes all possible alternatives. WS-Policies can be placed inside WSDL itself or referenced
as external documents. CXF will automatically recognize, read and use policies defined or
referenced in WSDL. Sample of attached policy is shown below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
&lt;wsdl:definitions name=<span class="code-quote">"HelloWorld"</span> targetNamespace=<span
class="code-quote">"http://apache.org/hello_world_soap_http"</span> 
…
<span class="code-tag">&lt;wsdl:service name=<span class="code-quote">"SOAPService"</span>&gt;</span>
    <span class="code-tag">&lt;wsdl:port binding=<span class="code-quote">"tns:Greeter_SOAPBinding"</span>
name=<span class="code-quote">"SoapPort"</span>&gt;</span>
        <span class="code-tag">&lt;soap:address location=<span class="code-quote">"http://localhost:9000/SoapContext/SoapPort"</span>/&gt;</span>
        <span class="code-tag">&lt;wsp:Policy <span class="code-keyword">xmlns:wsp</span>=<span
class="code-quote">"http://www.w3.org/ns/ws-policy"</span>&gt;</span>
             <span class="code-tag">&lt;wsam:Addressing <span class="code-keyword">xmlns:wsam</span>=<span
class="code-quote">"http://www.w3.org/2007/02/addressing/metadata"</span>&gt;</span>
                 <span class="code-tag">&lt;wsp:Policy/&gt;</span>
              <span class="code-tag">&lt;/wsam:Addressing&gt;</span>
         <span class="code-tag">&lt;/wsp:Policy&gt;</span>
    <span class="code-tag">&lt;/wsdl:port&gt;</span>
<span class="code-tag">&lt;/wsdl:service&gt;</span>
<span class="code-tag">&lt;/wsdl:definitions&gt;</span>
</pre>
</div></div>

<h4><a name="HowtoDefinePolicies-Springconfiguration"></a>Spring configuration</h4>
<p>It is possible to define policies directly in Spring configuration of client and
service as jaxws feature. CFX will recognize and use configured WS-Policies:<br/>
Client:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
&lt;jaxws:client id=<span class="code-quote">"CRMServiceClient"</span> name=<span
class="code-quote">"{http://services.talend.org/CRMService}CRMServiceProvider"</span>
        <span class="code-keyword">xmlns:serviceNamespace</span>=<span class="code-quote">"http://services.talend.org/CRMService"</span>
        serviceClass=<span class="code-quote">"org.talend.services.crmservice.CRMService"</span>
        serviceName=<span class="code-quote">"serviceNamespace:CRMServiceProvider"</span>
        endpointName=<span class="code-quote">"serviceNamespace:CRMServicePort"</span>
        address=<span class="code-quote">"${endpoint.prefix}/CRMServiceProvider"</span>&gt;
        <span class="code-tag">&lt;jaxws:features&gt;</span>
            <span class="code-tag">&lt;p:policies&gt;</span>
                <span class="code-tag">&lt;wsp:PolicyReference URI=<span class="code-quote">"classpath:/saml.policy"</span>/&gt;</span>
            <span class="code-tag">&lt;/p:policies&gt;</span>
        <span class="code-tag">&lt;/jaxws:features&gt;</span>
<span class="code-tag">&lt;/jaxws:client&gt;</span>
</pre>
</div></div>

<p>Service:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
&lt;jaxws:endpoint id=<span class="code-quote">"CRMService"</span>
        <span class="code-keyword">xmlns:serviceNamespace</span>=<span class="code-quote">"http://services.talend.org/CRMService"</span>
        serviceName=<span class="code-quote">"serviceNamespace:CRMServiceProvider"</span>
        endpointName=<span class="code-quote">"serviceNamespace:CRMServicePort"</span>
        implementor=<span class="code-quote">"#CRMServiceBean"</span>
        address=<span class="code-quote">"/CRMServiceProvider"</span>&gt;
        <span class="code-tag">&lt;jaxws:features&gt;</span>
            <span class="code-tag">&lt;p:policies&gt;</span>
                <span class="code-tag">&lt;wsp:PolicyReference URI=<span class="code-quote">"classpath:/saml.policy"</span>/&gt;</span>
            <span class="code-tag">&lt;/p:policies&gt;</span>
        <span class="code-tag">&lt;/jaxws:features&gt;</span>
<span class="code-tag">&lt;/jaxws:endpoint&gt;</span>
</pre>
</div></div>

<h4><a name="HowtoDefinePolicies-Dynamicallyviamessageproperty"></a>Dynamically
via message property</h4>
<p>Sometimes policies cannot be configured statically, because they are obtained or
calculated dynamically for concrete message (for example using Policy Server or Service Registry).
For such cases CXF provide a possibility to load policy dynamically and set it into the message
context property. It can be done for example in custom interceptor that fulfils the following:</p>
<ol>
	<li>Get policy from external location and build it for current message.</li>
	<li>Parse WS-Policy XML using Neethi library.</li>
	<li>Store result Policy object into <em>PolicyConstants.POLICY_OVERRIDE</em>
message content property.<br/>
Important is that this custom policy interceptor is called before CXF <em>PolicyInInterceptor</em>
or <em>PolicyOutInterceptor</em>. Than CXF will automatically recognize Policy
stored into this property and use it with highest priority.</li>
</ol>


    </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/CXF20DOC/How+to+Define+Policies">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=27840374&revisedVersion=2&originalVersion=1">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CXF20DOC/How+to+Define+Policies?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message