Monday, August 8, 2011

ADF Webservice data control HACK: DONT TRY THIS AT HOME

I really wanted to be able to do things with my ADF service implementation based web service data control:

1) Change configuration of the wsdl location dynamically for each environment.
2) Make sure that I could add to the results of the web service with ADF. (createNewRow)

The first point: This is hard to do because the url is looked up from the bindings and wsdl. You could do this at build time and build an artifact for each environment but I didnt want to.

The second point: The result created by the ws data control was an XMLHandler$DataCollection wich did not implement the add method - I got a Not supported exception.

So here is the solution very ugly but hey well (this is a work in progress so shout if you want more code/ explanation):

1) Override the SOAPProvider in the DataControls.dcx

<DataControlConfigs xmlns=""
  version="" id="DataControls"
  <AdapterDataControl id="YourModelService" 
    SupportsSortCollection="true" SupportsResetState="true"
    SupportsFindMode="true" SupportsUpdates="true"
      <definition xmlns="" 
      name="YourModelService" version="1.0"

2) Implement your own SOAP Provider link this one.



import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import oracle.adf.model.adapter.AdapterException;
import oracle.adf.model.connection.webservice.api.WebServiceConnection;
import oracle.adf.model.connection.webservice.impl.WebServiceConnectionImpl;

import oracle.adfinternal.model.adapter.webservice.WSOperation;
import oracle.adfinternal.model.adapter.webservice.provider.WSProvider;
import oracle.adfinternal.model.adapter.webservice.provider.soap.SOAPProvider;
import oracle.adfinternal.model.adapter.webservice.resource.WSDCResource;
import oracle.adfinternal.model.adapter.webservice.resource.WSDCResourceBundle;


import oracle.webservices.model.Operation;
import oracle.webservices.model.Port;
import oracle.webservices.model.soap.SoapPort;

public class YourSOAPProvider extends SOAPProvider {
  Map mOperations;

  public YourSOAPProvider() {


  public void init(Map map) {

    mOperations = (Map) map.get(WSProvider.PROVIDER_OPERATIONS);
    WebServiceConnection conn = (WebServiceConnection) map.get(WSProvider.PROVIDER_CONNECTION);
    try {
//@TODO look this up from an external propeties file
      ((WebServiceConnectionImpl) conn).setWsdlUrl(
new URL(
    } catch(Exception e) {
  private WSOperation findServiceOperation(String operationName) throws AdapterException {
    Iterator portIterator = mOperations.keySet().iterator();
    while(portIterator.hasNext()) {
      String portName = (String);
      List operations = (List) mOperations.get(portName);
      Iterator operationIter = operations.iterator();
      while(operationIter.hasNext()) {
        WSOperation operation = (WSOperation);
          return operation;

    // Fatal Error if the operation to invoke could not be found
    throw new AdapterException(WSDCResourceBundle.class, WSDCResource.ERR_NOSUCH_OPERATION,
        new Object[] { operationName });

  public void setUrl(Port port, String url) {
    SoapPort soap = getSoapExt(port);
    if(soap == null) {
      soap = new SoapPortImpl();
      port.addExtension(SoapPort.EXTENSION_TYPE, soap);

  protected static SoapPort getSoapExt(Port port) {
    return (SoapPort) port.getExtension(SoapPort.EXTENSION_TYPE);

  public Object execute(String string, Map map) throws AdapterException {
    Operation oper = findServiceOperation(string).getOperation();
//@TODO look this up from an external propeties file
    setUrl(oper.getPort(), "");
    Object resp = super.execute(string, map);
    if(resp != null && resp instanceof Collection && ((Collection) resp).size() > 0) {
      Object resp1 = (Object) ((Collection) resp).iterator().next();
      if(resp1 != null && resp1 instanceof Map && ((Map) resp1).size() > 0) {
        Object key = ((Map) resp1).keySet().iterator().next();
        Object resp2 = ((Map) resp1).get(key);
        if(resp2 != null && resp2 instanceof Collection && ((Collection) resp2).size() > 0) {
          Collection replacedCollection = replaceCollection((Collection) resp2);
          ((Map) resp1).put(key, replacedCollection);
          Object resp3 = ((Collection) resp2).iterator().next();
    return resp;

  private Collection replaceCollection(Collection objects) {
    return new ArrayList(objects);

NB: remember we may have to do this all again when a new release happens so it is better to follow the tried and tested solutions to these problems.

2) Use two iterators (based on create for the form and the findresults for the other) instead of writing to the results. Or create two screens a search and a create screen.

No comments:

Post a Comment