Quantcast
Channel: SCN : Popular Discussions - Java Development
Viewing all articles
Browse latest Browse all 518

Adding Function Imports to OData Services

$
0
0

Hello,

 

I try to add a Function Import in my OData service but it doesn't appear in the &metadata, so I can't access it.

I am following this tutorial : https://olingo.apache.org/doc/odata2/tutorials/jpafunctionimport.html

 

So, I have created a class wich contains the logic part :

 

public class MobileAppService {  @EdmFunctionImport(name = "GetApiValidity",            returnType = @ReturnType(type = Type.SIMPLE, isCollection = false),            httpMethod = HttpMethod.GET)  public int getApiValidity( ) {       return 123;  }
}

Another class to register the annotated Java methods :

 

public class LucEdmExtension implements JPAEdmExtension {  @Override  public void extendWithOperation(JPAEdmSchemaView view) {       view.registerOperations(MobileAppService.class, null);  }
}

Finally I have registered this last class in the ODataJPAContext :

 

@Override  public ODataJPAContext initializeODataJPAContext()                 throws ODataJPARuntimeException {       ODataJPAContext oDataJPAContext = this.getODataJPAContext();       try {            EntityManagerFactory emf = Utility.getEntityManagerFactory();            oDataJPAContext.setEntityManagerFactory(emf);            oDataJPAContext.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);            oDataJPAContext.setJPAEdmExtension(new LucEdmExtension());            return oDataJPAContext;       } catch (Exception e) {            throw new RuntimeException(e);       }  }

As far as I know, it should be enough to get this kind of metadata :

 

<EntityContainer Name="ODataEntityContainer" m:IsDefaultEntityContainer="true">    . . .     <FunctionImport Name="GetApiValidity" ReturnType=""Edm.Int32"" m:HttpMethod="GET"></FunctionImport>     . . .</EntityContainer>

But I have nothing related with Function Import... Could you please help me ?

I am using a class of type EdmProvider to configure all other services, should I add something in this class for the Function Import ?

 

I am using OData 2.0 version.

 

Thanks a lot,

 

François


Viewing all articles
Browse latest Browse all 518

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>