Using the Policy Annotation

3-16 Programming Advanced Features of JAX-RPC Web Services for Oracle WebLogic Server This echo method concatenates the saved message from helloWorld onto the end of the provided message, and returns it. WebMethod ReliabilityBufferretryCount=10, retryDelay=10 seconds public String echoString input2 { System.out.println Hello World + input2 + onewaySavedInput; return input + onewaySavedInput; } } In the example, the custom ReliableHelloWorldPolicy.xml policy file is attached to the Web service at the class level, which means that the policy file is applied to all public operations of the Web service. The policy file is applied only to the request Web service message as required by the reliable messaging feature and it is attached to the WSDL file. For information about the pre-packaged policies available and creating a custom policy, see Section 3.5, Creating the Web Service Reliable Messaging WS-Policy File . The JMS queue that WebLogic Server uses internally to enable the Web service reliable messaging has a JNDI name of webservices.reliable.queue, as specified by the BufferQueue annotation. The helloWorld method has been marked with both the WebMethod and Oneway JWS annotations, which means it is a public operation called helloWorld. Because of the Policy annotation, the operation can be invoked reliably. The Web services runtime attempts to deliver reliable messages to the service a maximum of 10 times, at 10-second intervals, as described by the ReliabilityBuffer annotation. The message may require re-delivery if, for example, the transaction is rolled back or otherwise does not commit. The echo method has been marked with the WebMethod and JWS annotation, which means it is a public operation called echo. Because of the Policy annotation, the operation can be invoked reliably. It uses the same reliability buffer configuration as the helloWorld method.

3.6.1 Using the Policy Annotation

Use the Policy annotation in your JWS file to specify that the Web service has a WS-Policy file attached to it that contains reliable messaging assertions. WebLogic Server delivers a set of pre-packaged WS-Policy files, as described in Appendix A, Pre-Packaged WS-Policy Files for Reliable Messaging. Follow the following guidelines when using the Policy annotation for Web service reliable messaging: ■ Use the uri attribute to specify the build-time location of the policy file, as follows: – If you have created your own WS-Policy file, specify its location relative to the JWS file. For example: Policyuri=ReliableHelloWorldPolicy.xml, direction=Policy.Direction.both, attachToWsdl=true Using Web Services Reliable Messaging 3-17 In this example, the ReliableHelloWorldPolicy.xml file is located in the same directory as the JWS file. – To specify one of the pre-packaged WS-Policy files or a WS-Policy file that is packaged in a shared Java EE library, use the policy: prefix along with the name and path of the policy file. This syntax tells the jwsc Ant task at build-time not to look for an actual file on the file system, but rather, that the Web service will retrieve the WS-Policy file from WebLogic Server at the time the service is deployed. – To specify that the policy file is published on the Web, use the http: prefix along with the URL, as shown in the following example: Policyuri=http:someSite.compoliciesmypolicy.xml direction=Policy.Direction.both, attachToWsdl=true ■ By default, WS-Policy files are applied to both the request inbound and response outbound SOAP messages. You can change this default behavior with the direction attribute by setting the attribute to Policy.Direction.inbound or Policy.Direction.outbound. ■ You can specify whether the Web service requires the operations to be invoked reliably and have the responses delivered reliably using the wsp:optional attribute within the policy file specified by uri. If the optional attribute is set to false for outbound on any operation, then: – The client must provide an offer sequence wsrm: Offer... as described in the WS-ReliableMessaging specification at http:docs.oasis-open.orgws-rxwsrm200702wsrm-1.1-spec -os-01.pdf for use when sending reliable responses. – Responses will be sent reliably for all operations requiring a response. If the optional attribute is set to true for outbound on all operations, then: – The client is not required to provide an offer sequence. – Responses will be sent reliably if the client provides an offer sequence; otherwise, responses will be sent non-reliably. ■ Set the attachToWsdl attribute of the Policy annotation to specify whether the policy file should be attached to the WSDL file that describes the public contract of the Web service. Typically, you want to publicly publish the policy so that client applications know the reliable messaging capabilities of the Web service. For this reason, the default value of this attribute is true. Note: Shared Java EE libraries are useful when you want to share a WS-Policy file with multiple Web services that are packaged in different Enterprise applications. As long as the WS-Policy file is located in the META-INFpolicies or WEB-INFpolicies directory of the shared Java EE library, you can specify the policy file in the same way as if it were packaged in the same archive at the Web service. See Creating Shared Java EE Libraries and Optional Packages in Developing Applications for Oracle WebLogic Server for information about creating libraries and setting up your environment so the Web service can locate the policy files. 3-18 Programming Advanced Features of JAX-RPC Web Services for Oracle WebLogic Server For more information about the Policy annotation, see weblogic.jws.Policy in WebLogic Web Services Reference for Oracle WebLogic Server.

3.6.2 Using the Oneway Annotation