How to access the WS SOAP message using WS DC

A frequent requirement is to access the SOAP message of a service to e.g. set SOAP header information required by a service for passing license keys or authentication information. In Java, the SOAPMessage class gives you access to the SoapPart, SOAPEnvenlope, SOAPBody and the SOAPHeader using code like shown below:

SOAPPart       sp = soapMessage.getSOAPPart();

SOAPEnvelope   se = soapMessage.getEnvelope();

SOAPBody       sb = soapMessage.getBody();

SOAPHeader     sh = soapMessage.getHeader();


See: http://download.oracle.com/javaee/1.4/api/javax/xml/soap/SOAPMessage.html


To access incoming and outgoing SOAP messages when using the Oracle ADF WS Data Control, you need to override the default SOAP provider that is configured in the DataControls.dcx file of the WS Data Control project.

<Source>
      <definition xmlns=
http://xmlns.oracle.com/adfm/adapter/webservice
                  name="PojoWsDC" version="1.0"                        provider=
     "oracle.adfinternal.model.adapter.webservice.provider.soap.SOAPProvider"

To change the provider class, extend the default “SOAPProvider” provider class as shown in an example below

public class CustomSOAProvider extends SOAPProvider {
    public CustomSOAProvider() {
        super();
    }

    //expose protected method to public
    public void handleRequest(SOAPMessage soapMessage) throws AdapterException   
    {       
      super.handleRequest(soapMessage);
    }
    //Expose protetcted method to public
    public void handleResponse(SOAPMessage soapMessage) throws AdapterException   
    {
        super.handleResponse(soapMessage);
    }  
}

Change the DataControls.dcx configuration to use your custom provider, for example

<Source>
  <definition xmlns=
http://xmlns.oracle.com/adfm/adapter/webservice
              name="PojoWsDC" version="1.0"
               provider="adf.sample.wsdc.CustomSOAProvider"

You can access the custom SOAP provider from a managed bean, which also allows you to expose its functionality to Expression Language. Before you can access the custom SOAP provider from a managed bean, you need to know the name of the Data Control that is used to access the Web Service. The name of the Data Control is defined in the DataControls.cpx file where it can be looked up. The file is located in the ViewController project.

The Data Control name can also be looked up in the Data Controls palette. This however requires that the name indicates that it accesses a Web Service Data Control, as otherwise it will be hard to tell.

You use the following code to access the custom SOAP provider from Java in a managed bean:

BindingContext bctx = BindingContext.getCurrent();
DataControl dc = bctx.findDataControl("PojoWsDC");    
WSDataControl wsdc = (WSDataControl) dc.getDataProvider();      
CustomSOAProvider customSoapProvider =
                  (CustomSOAProvider)  wsdc.getProvider();

If you are using JDeveloper 11.1.1.4 or later, because the SOAPProvider class is in an ADF internal package, you need to be aware of the ADF internal Java class audit rule and how to switch it off:

http://blogs.oracle.com/jdevotnharvest/2011/03/internal_package_import_errors_and_how_to_switch_them_off.html

But why do you need to create a custom SOAPProvider extending the default provider?

The default SOAPProvider class has the handleRequest and handleResponse methods defined as protected for security reasons. To make these methods available for the ViewController to use, you need to expose them as public methods, which is what the custom SOAPProvider class primarily is for.

Note: I filed an ER for a public access to the SOAPProvider class.

Comments:

Post a Comment:
Comments are closed for this entry.
About

A blog on Oracle JDeveloper, ADF, MAF, MCS and other mobile and web topics inspired by questions and answers posted on the OTN forums.



Frank Nimphius

Search

Archives
« March 2015
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    
       
Today