cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrei Shakirin (Confluence)" <conflue...@apache.org>
Subject [CONF] Apache CXF Documentation > How to Define Policies
Date Mon, 28 Oct 2013 14:44:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/en/2176/1/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 (4)</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" >Client: <br>{code:xml} <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">&lt;beans
xmlns=&quot;http://www.springframework.org/schema/beans&quot; <br>       xmlns:jaxws=&quot;http://cxf.apache.org/jaxws&quot;
<br>       xmlns:cxf=&quot;http://cxf.apache.org/core&quot; <br>     
 xmlns:p=&quot;http://cxf.apache.org/policy&quot; <br>       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
<br>       xsi:schemaLocation=&quot; <br>http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
<br>http://cxf.apache.org/policy http://cxf.apache.org/schemas/policy.xsd <br>http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd&quot; <br>http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd&quot;&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >    &lt;jaxws:client id=&quot;CRMServiceClient&quot;
name=&quot;{http://services.talend.org/CRMService}CRMServiceProvider&quot;
            xmlns:serviceNamespace=&quot;http://services.talend.org/CRMService&quot;
            serviceClass=&quot;org.talend.services.crmservice.CRMService&quot;
            serviceName=&quot;serviceNamespace:CRMServiceProvider&quot;
            endpointName=&quot;serviceNamespace:CRMServicePort&quot;
            address=&quot;${endpoint.prefix}/CRMServiceProvider&quot;&gt;
            &lt;jaxws:features&gt;
                &lt;p:policies&gt;
                    &lt;wsp:PolicyReference URI=&quot;classpath:/saml.policy&quot;/&gt;
                &lt;/p:policies&gt;
            &lt;/jaxws:features&gt;
    &lt;/jaxws:client&gt; <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">&lt;/beans&gt;
<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br>Service:
<br>{code:xml} <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">&lt;beans
xmlns=&quot;http://www.springframework.org/schema/beans&quot; <br>       xmlns:jaxws=&quot;http://cxf.apache.org/jaxws&quot;
<br>       xmlns:cxf=&quot;http://cxf.apache.org/core&quot; <br>     
 xmlns:p=&quot;http://cxf.apache.org/policy&quot; <br>       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
<br>       xsi:schemaLocation=&quot; <br>http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
<br>http://cxf.apache.org/policy http://cxf.apache.org/schemas/policy.xsd <br>http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd&quot; <br>http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd&quot;&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >    &lt;jaxws:endpoint id=&quot;CRMService&quot;
            xmlns:serviceNamespace=&quot;http://services.talend.org/CRMService&quot;
            serviceName=&quot;serviceNamespace:CRMServiceProvider&quot;
            endpointName=&quot;serviceNamespace:CRMServicePort&quot;
            implementor=&quot;#CRMServiceBean&quot;
            address=&quot;/CRMServiceProvider&quot;&gt;
            &lt;jaxws:features&gt;
                &lt;p:policies&gt;
                    &lt;wsp:PolicyReference URI=&quot;classpath:/saml.policy&quot;/&gt;
                &lt;/p:policies&gt;
            &lt;/jaxws:features&gt;
    &lt;/jaxws:endpoint&gt; <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">&lt;/beans&gt;
<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <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="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;wsdl:definitions name="HelloWorld" targetNamespace="http://apache.org/hello_world_soap_http"

…
&lt;wsdl:service name="SOAPService"&gt;
    &lt;wsdl:port binding="tns:Greeter_SOAPBinding" name="SoapPort"&gt;
        &lt;soap:address location="http://localhost:9000/SoapContext/SoapPort"/&gt;
        &lt;wsp:Policy xmlns:wsp="http://www.w3.org/ns/ws-policy"&gt;
             &lt;wsam:Addressing xmlns:wsam="http://www.w3.org/2007/02/addressing/metadata"&gt;
                 &lt;wsp:Policy/&gt;
              &lt;/wsam:Addressing&gt;
         &lt;/wsp:Policy&gt;
    &lt;/wsdl:port&gt;
&lt;/wsdl:service&gt;
&lt;/wsdl:definitions&gt;
</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. CXF will recognize and use configured WS-Policies:<br/>
Client:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xmlns:cxf="http://cxf.apache.org/core"
       xmlns:p="http://cxf.apache.org/policy"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/policy http://cxf.apache.org/schemas/policy.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"&gt;
    &lt;jaxws:client id="CRMServiceClient" name="{http://services.talend.org/CRMService}CRMServiceProvider"
            xmlns:serviceNamespace="http://services.talend.org/CRMService"
            serviceClass="org.talend.services.crmservice.CRMService"
            serviceName="serviceNamespace:CRMServiceProvider"
            endpointName="serviceNamespace:CRMServicePort"
            address="${endpoint.prefix}/CRMServiceProvider"&gt;
            &lt;jaxws:features&gt;
                &lt;p:policies&gt;
                    &lt;wsp:PolicyReference URI="classpath:/saml.policy"/&gt;
                &lt;/p:policies&gt;
            &lt;/jaxws:features&gt;
    &lt;/jaxws:client&gt;
&lt;/beans&gt;
</pre>
</div></div>

<p>Service:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xmlns:cxf="http://cxf.apache.org/core"
       xmlns:p="http://cxf.apache.org/policy"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/policy http://cxf.apache.org/schemas/policy.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"&gt;
    &lt;jaxws:endpoint id="CRMService"
            xmlns:serviceNamespace="http://services.talend.org/CRMService"
            serviceName="serviceNamespace:CRMServiceProvider"
            endpointName="serviceNamespace:CRMServicePort"
            implementor="#CRMServiceBean"
            address="/CRMServiceProvider"&gt;
            &lt;jaxws:features&gt;
                &lt;p:policies&gt;
                    &lt;wsp:PolicyReference URI="classpath:/saml.policy"/&gt;
                &lt;/p:policies&gt;
            &lt;/jaxws:features&gt;
    &lt;/jaxws:endpoint&gt;
&lt;/beans&gt;
</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;" class="grey">
                        <a href="https://cwiki.apache.org/confluence/users/removespacenotification.action?spaceKey=CXF20DOC">Stop
watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://cwiki.apache.org/confluence/users/editmyemailsettings.action">Change
email 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=4&originalVersion=3">View
Changes</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message