cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache CXF > Using WS-Policy in CXF projects
Date Mon, 20 Feb 2012 15:05:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/15/_/styles/combined.css?spaceKey=CXF&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/CXF/Using+WS-Policy+in+CXF+projects">Using
WS-Policy in CXF projects</a></h2>
    <h4>Page  <b>added</b> by             <a href="https://cwiki.apache.org/confluence/display/~ashakirin">Andrei
Shakirin</a>
    </h4>
         <br/>
    <div class="notificationGreySide">
         <p>WS-Policy provides flexible mechanism to activate desired functionality
on the client or service sides. Article describes how to define policies in custom CXF projects,
implement policy-aware interceptors and explains some aspects of internal CXF design regarding
WS-Policy.</p>

<h1><a name="UsingWS-PolicyinCXFprojects-Howtodefinepolicies"></a>How to
define policies</h1>
<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>

<h2><a name="UsingWS-PolicyinCXFprojects-WSDLPolicyattachment"></a>WSDL
Policy attachment</h2>
<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>

<h2><a name="UsingWS-PolicyinCXFprojects-Springconfiguration"></a>Spring
configuration</h2>
<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>

<h2><a name="UsingWS-PolicyinCXFprojects-Dynamicallyviamessageproperty"></a>Dynamically
via message property</h2>
<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 PolicyInInterceptor
or PolicyOutInterceptor. 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/CXF/Using+WS-Policy+in+CXF+projects">View
Online</a>
              |
       <a href="https://cwiki.apache.org/confluence/display/CXF/Using+WS-Policy+in+CXF+projects?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message