Skip to main content

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="http://xmlns.oracle.com/adfm/configuration"
  version="11.1.2.60.17" id="DataControls"
  Package="za.co.transcode.adf.prj.model">
  <AdapterDataControl id="YourModelService" 
    FactoryClass="oracle.adf.model.adapter.DataControlFactoryImpl"
    ImplDef="oracle.adfinternal.model.adapter.webservice.WSDefinition"
    SupportsTransactions="false"
    SupportsSortCollection="true" SupportsResetState="true"
    SupportsRangesize="true"
    SupportsFindMode="true" SupportsUpdates="true"
    Definition="za.co.transcode.adf.prj.model.YourModelService"
    BeanClass="za.co.transcode.adf.prj.model.YourModelService"
    xmlns="http://xmlns.oracle.com/adfm/datacontrol">
    <Source>
      <definition xmlns="http://xmlns.oracle.com/adfm/adapter/webservice" 
      name="YourModelService" version="1.0"
      provider="za.co.transcode.adf.prj.model.YourSOAPProvider"
      wsdl="http://127.0.0.1:7101/Your-Model-context-root/YourAppModuleService?WSDL"
      UsePersistedStructure="false"> 



2) Implement your own SOAP Provider link this one.


package za.co.transcode.adf.prj.model;

import java.net.URL;

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.j2ee.ws.model.soap.SoapPortImpl;

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() {

    super();
  }

  public void init(Map map) {

    super.init(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(
"http://10.10.10.10:7001/Your-Model-context-root/YourAppModuleService?WSDL"));
    } catch(Exception e) {
      e.printStackTrace();
    }
  }
  private WSOperation findServiceOperation(String operationName) throws AdapterException {
    Iterator portIterator = mOperations.keySet().iterator();
    while(portIterator.hasNext()) {
      String portName = (String) portIterator.next();
      List operations = (List) mOperations.get(portName);
      Iterator operationIter = operations.iterator();
      while(operationIter.hasNext()) {
        WSOperation operation = (WSOperation) operationIter.next();
        if(operation.getName().equalsIgnoreCase(operationName))
          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);
    }
    soap.setAddressUrl(url);
  }

  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(), "http://10.10.10.10:7001/Your-Model-context-root/YourAppModuleService");
    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.

1) http://forums.oracle.com/forums/thread.jspa?messageID=9393754&tstart=0
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.

Comments

Popular posts from this blog

MANIFEST.MF merge JDeveloper for an executable jar

Goto your project > properties. Then click on deployment in the menu. Edit or add a jar deployment profile. Fill in the details under jar options (select Include manifest and give it a main class name) Also remember that the merge functionality only works with a BLANK line at the end of the merge file. REALLY this caught me. My merge file contents: Class-Path: commons-codec-1.3.jar [...empty line here CRLF...]

JBO-25013: TooManyObjectsException

oracle.jbo.TooManyObjectsException: JBO-25013: Too many objects match the primary key oracle.jbo.Key[Key null ]. Ok so for you it may be trying to insert a duplicate record this should explain your problem (also check trigger they could be the cause.) NOTE: You can also try to create a new duplicate EO if you have a page with two VO's using the same EO. This could sort your problems. For me I needed to add a launch listener on my LOV and clear the cache of my vo. LOV <af:inputListOfValues id="NameId" popupTitle="#{bindings.Name.hints.label}" value="#{bindings.RolName1.inputValue}" label="#{bindings.RolName1.hints.label}" model="#{bindings.RolName1.listOfValuesModel}" required="#{bindings.RolName1.hints.mandatory}" columns="#{bindings.RolName1.hints.displayWidth}" shortDesc="#{bindings.RolName1.hints.tooltip}" launchPopupListener="#{backingBeanScope.backingBean.launchPop...

ADF Encountered deferred syntax #{ in template text.

OracleJSP error: oracle.jsp.parse.JspParseException:  Error: Encountered deferred syntax #{ in template text.  If intended as a literal, escape it or set directive  deferredSyntaxAllowedAsLiteral This normally happens when you have some tag lib dependancy problems but this was  not the case for me... My problem: For some reason my model project had web stuff in it(public html etc)  so I had to remove the public html stuff from my project and manually edit the Model.jpr project file and remove the tag lib entries at the bottom o the file. Go figure.