Both properties and policies can be used to associate configuration data with an
endpoint. The essential difference between them is that properties are
a Fuse Services Framework specific configuration mechanism whereas policies are a
standard WSDL configuration mechanism. Policies typically originate from WS specifications
and standards and they are normally set by defining wsdl:policy
elements that appear in the WSDL contract. By contrast, properties are Apache CXF-specific and they are
normally set by defining jaxws:properties
elements in
the Fuse Services Framework Spring configuration file.
It is also possible, however, to define property settings and WSDL policy settings in Java using annotations, as described here.
The @EndpointProperty
annotation is defined by the
org.apache.cxf.annotations.EndpointProperty
interface. It is placed on the
SEI.
This annotation adds Apache CXF-specific configuration settings to an endpoint. Endpoint
properties can also be specified in a Spring configuration file. For example, to configure
WS-Security on an endpoint, you could add endpoint properties using the
jaxws:properties
element in a Spring configuration file as follows:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" ... > <jaxws:endpoint id="MyService" address="https://localhost:9001/MyService" serviceName="interop:MyService" endpointName="interop:MyServiceEndpoint" implementor="com.foo.MyService"> <jaxws:properties> <entry key="ws-security.callback-handler" value="interop.client.UTPasswordCallback"/> <entry key="ws-security.signature.properties" value="etc/keystore.properties"/> <entry key="ws-security.encryption.properties" value="etc/truststore.properties"/> <entry key="ws-security.encryption.username" value="useReqSigCert"/> </jaxws:properties> </jaxws:endpoint> </beans>
Alternatively, you could specify the preceding configuration settings in Java by adding
@EndpointProperty
annotations to the SEI, as shown in Example 1.16.
Example 1.16. Configuring WS-Security Using @EndpointProperty Annotations
@WebService @EndpointProperty(name="ws-security.callback-handler" value="interop.client.UTPasswordCallback") @EndpointProperty(name="ws-security.signature.properties" value="etc/keystore.properties") @EndpointProperty(name="ws-security.encryption.properties" value="etc/truststore.properties") @EndpointProperty(name="ws-security.encryption.username" value="useReqSigCert") public interface HelloWorld { String sayHi(@WebParam(name = "text") String text); }
The @EndpointProperties
annotation is defined by the
org.apache.cxf.annotations.EndpointProperties
interface. It is placed on the
SEI.
This annotation provides a way of grouping multiple @EndpointProperty
annotations into a list. Using @EndpointProperties
, it is possible to re-write
Example 1.16 as shown in Example 1.17.
Example 1.17. Configuring WS-Security Using an @EndpointProperties Annotation
@WebService @EndpointProperties( { @EndpointProperty(name="ws-security.callback-handler" value="interop.client.UTPasswordCallback"), @EndpointProperty(name="ws-security.signature.properties" value="etc/keystore.properties"), @EndpointProperty(name="ws-security.encryption.properties" value="etc/truststore.properties"), @EndpointProperty(name="ws-security.encryption.username" value="useReqSigCert") }) public interface HelloWorld { String sayHi(@WebParam(name = "text") String text); }
The @Policy
annotation is defined by the
org.apache.cxf.annotations.Policy
interface. It can be placed on the SEI or
the SEI methods.
This annotation is used to associate a WSDL policy with an SEI or an SEI method. The
policy is specified by providing a URI that references an XML file containing a standard
wsdl:policy
element. If a WSDL contract is to be generated from the SEI (for
example, using the java2ws
command-line tool), you can specify whether or not
you want to include this policy in the WSDL.
Table 1.13 shows the properties
supported by the @Policy
annotation.
Table 1.13. @Policy Properties
Property | Description |
---|---|
uri | (Required) The location of the file containing the policy definition. |
includeInWSDL | (Optional) Whether to include the policy in the generated
contract, when generating WSDL. Default is true . |
placement | (Optional) Specifies where in the WSDL file this documentation is to appear. For the list of possible placement values, see Placement in the WSDL contract. |
faultClass | (Optional) If the placement is set to be
BINDING_OPERATION_FAULT or PORT_TYPE_OPERATION_FAULT ,
you must also set this property to specify which fault this policy applies to. The
value is the Java class that represents the fault. |
The @Policies
annotation is defined by the
org.apache.cxf.annotations.Policies
interface. It can be placed on the SEI or
thse SEI methods.
This annotation provides a way of grouping multiple @Policy
annotations
into a list.
To specify where the policy should appear in the WSDL contract, you can specify the
placement
property, which is of type Policy.Placement
. The
placement can have one of the following values:
Policy.Placement.BINDING Policy.Placement.BINDING_OPERATION Policy.Placement.BINDING_OPERATION_FAULT Policy.Placement.BINDING_OPERATION_INPUT Policy.Placement.BINDING_OPERATION_OUTPUT Policy.Placement.DEFAULT Policy.Placement.PORT_TYPE Policy.Placement.PORT_TYPE_OPERATION Policy.Placement.PORT_TYPE_OPERATION_FAULT Policy.Placement.PORT_TYPE_OPERATION_INPUT Policy.Placement.PORT_TYPE_OPERATION_OUTPUT Policy.Placement.SERVICE Policy.Placement.SERVICE_PORT
The following example shows how to associate WSDL policies with the
HelloWorld
SEI and how to associate a policy with the sayHi
method. The policies themselves are stored in XML files in the file system, under the
annotationpolicies
directory.
@WebService @Policy(uri = "annotationpolicies/TestImplPolicy.xml", placement = Policy.Placement.SERVICE_PORT), @Policy(uri = "annotationpolicies/TestPortTypePolicy.xml", placement = Policy.Placement.PORT_TYPE) public interface HelloWorld { @Policy(uri = "annotationpolicies/TestOperationPTPolicy.xml", placement = Policy.Placement.PORT_TYPE_OPERATION), String sayHi(@WebParam(name = "text") String text); }
You can use the @Policies
annotation to group multiple @Policy
annotations into a list, as shown in the following example:
@WebService @Policies({ @Policy(uri = "annotationpolicies/TestImplPolicy.xml", placement = Policy.Placement.SERVICE_PORT), @Policy(uri = "annotationpolicies/TestPortTypePolicy.xml", placement = Policy.Placement.PORT_TYPE) }) public interface HelloWorld { @Policy(uri = "annotationpolicies/TestOperationPTPolicy.xml", placement = Policy.Placement.PORT_TYPE_OPERATION), String sayHi(@WebParam(name = "text") String text); }