Rest based web services is a relatively new feature added in the OUAF framework. It is a new addition and still a lot of changes are coming up continuously in newer versions of the framework. It will take some time for the changes to stabilize.
Depending on which version of the OUAF framework, there may be variations in how you access REST web service.
This blog is targeted at providing some insight into how to access REST based web services in the OUAF framework.
Accessing REST Web services
Framework version 4.4.0.2 - FW V4.4.0.2.0 (C2M V2.7.0.3.0)
This is the old way of accessing REST web services. This has changed in recent version. Documenting this in case anyone is trying to access REST web services in old versions of the product.
There are three steps you need to follow to access a REST web service in this version.
Authentication:
This is done by invoking j_security_check and passing the username and password of C2M login user in j_username and j_password parameters respectively.
Get Rest Token:
This is done by invoking ‘/restSecurityToken’ url. You will get the Rest security token in the response header with the key ‘OUAF-Security-Token’.
Invoke Rest WebService (Set Token in Header in this request):
Set the token received in the earlier request in the header for the session. Call the actual REST api that you want to invoke.
Am using python to demonstrate accessing of REST web service. Alternatively you can use POSTMAN or SOAPUI also.
Using requests module in python for accessing web service.
Run the python file using command “python retrieveSAtypesold.py”
As seen below the output of the rest call is displayed
Framework version 4.4.0.3 - FW V4.4.0.3.0 (C2M V2.8.0.0.0)
In this framework version, the Rest module has been moved to a separate web container (rest.war) having target URL as ‘ouaf/rest’. Hence it can have its own authentication separate from the main web container having target URL ‘/ouaf’.
Hence the steps for accessing REST web service is different.
You no longer need to authenticate by calling ‘j_security_check’ now. (If you hit ‘j_security_check’ you will get authentication error and will be logged out, as cis.jsp has been modified to not allow direct access to j_security_check.)
You can specify the authentication to use for the REST web container. This would be different from the authentication specified for the root web container.
By default the framework provides you Oracle Web Services Manager (OWSM) option. You can enable that by setting below parameter to true in ENVIRON.INI file
OWSM_PROTECTION_FOR_REST_SERVICES=true
Will provide more details for accessing REST web service using OWSM later. OWSM provides support for token based security also.
Currently I am setting the authentication to ‘BASIC’, for the rest web container, for demo purposes.
You can do this by modifying “web.xml.rest.template” file in the folder ‘$SPLEBASE/templates’ folder.
Add the following snippet to the file
You can use any valid authentication allowed by weblogic for the web container.
Accessing REST Web service:
Am using python to demonstrate accessing of REST web service. Alternatively you can use POSTMAN or SOAPUI also.
Have created a new REST inbound web service in C2M. Am accessing an out of box business service ‘C1-ALL-SATYP’ in the operation. Have set the URI component of IWS to ‘/demo’. Have set the URI component of IWS to ‘satypes’.
Have set resource category to ‘Customer Information’
As seen below the IWS is created.
Click on ‘View Specification’ to view details of REST webservice in open API format
Expand the service and execute it. You will see the result below.
You can access the REST URL in the ‘Request URL’ window below for quick access.
The URL of the REST webservices is composed of the following parts:
http://server:port/ouaf/rest/apis/{Owner URI component}/{resource Category URI component}/{IWS URI component}/{Operation URI component}
Sample URL: http://localhost:6700/ouaf/rest/apis/cm/customers/demo/satypes
Extendable lookup for Resource category Extendable lookup (F1-RESTResourceCategory)
As seen below the URI component for resource category ‘Customer information’ is ‘/customers’
Extendable lookup - Owner Configuration for REST Services (F1-RESTOwnerURLComponent)
Similarly for owner uri component the value is ‘/cm’
Using requests module in python for accessing web service.
First set following headers – ‘Accept’ and ‘Content-Type’ to ‘application/json’
Also as authentication is set to BASIC, use HTTPBasicAuth for providing authentication as shown below. Set the username and password for C2M application in that.
Run the python file using command “python retrieveSAtypes.py”
As seen below the output of the web service is displayed on the command prompt.
looks good.. waiting for the day when I can use these to invoke service !!
ReplyDeletegood work Sreeneeth.
Hi Sreeneeth,
ReplyDeleteGood day, I followed your guide for configuring Rest on C2M 2.8 but I'm still seeing ${service.url} as my Computed URL when clicking View Specification. My ENVIRON.INI is already configured but my web.xml.rest.template is not. After applying the changes, I started the C2M Server but it's still the same. Do I need to run InitialSetup.cmd or any other process for these settings to take effect?
Thank you so much for this guide and any further help is appreciated.
You need to run initialsetup after any changes is made to environ.ini file.. also update the ear files on weblogic after running initialsetup.
Deletehi Sreeneeth, I am still having the same issue after running initialsetup and updating ear files. I am on C2M version 2.9
Deletehi Sreeneeth, I still have the same issue after running initialsetup and updating ear files. is there any config I need to do?
Deletehi Sreeneeth, I was able to resolve this issue on my end by adding a value on configureEnv #55: URI for Variable F1_BASE_REST_URL. then running initialsetup and updating ear files.
DeleteI have encountered the following error:
ReplyDelete<Could not load user defined filter in web.xml: oracle.wsm.agent.handler.servlet.SecurityFilter.
java.lang.SecurityException: WSM-06303: The method "getRepositoryAccessor" was not called with the required permission "oracle.wsm.policymanager.accessor.IRepositoryAccessor".
Do I need to configure anything else for Oracle Web Services Manager (OWSM) being worked on C2M version 2.9?
You can ignore this error
DeleteHi,
ReplyDeleteI have encounter <Could not load user defined filter in web.xml: oracle.wsm.agent.handler.servlet.SecurityFilter.
java.lang.SecurityException: WSM-06303 : The method "getRepositoryAccessor" was not called with required permission "oracle.wsm.policymanager.accessor.IRepositoryAccessor". Do I need to set any other OSWM configurations.
Thank you
Hi, you can ignore this error that comes in logs. Are you facing any other difficulty in connecting to the RESt webservice
DeleteI am getting HTTP/1.1 401 Unauthorized response when using https and no response on http
DeleteAdditionally, I was unable to run iwsDeploy.cmd or with -d so had used the option -b and manually deployed the webservices jar
on C2M 2.9 configEnv , under option 50 and 52 the following options do I need to populate these values , if so may I know what are the expected values
50. Advanced Environment Miscellaneous Configuration,
IWS Deployment Target:
Web Admin Server Host:
52. Advanced Web Application Configuration
Deploy XAI Application Module: false
Web Application Cache Settings: off
Web Server Port Number:
CSRF Protection For REST Services: false
OWSM Protection For REST Services: true
Thanks for your time and any help is much apperciated
Iwsdeploy is needed only for SoAp webservices not REST.. have you set some authentication type for your REST container. In above blog I have shown example of setting it to BASIC..
DeleteI did follow those steps and added the auth setting as BASIC
DeleteI encountered connection refused when running the python, how do I fix?
ReplyDeleteCheck if you are able to submit the request from application front end as shown in above blog
Deleteyes I am able to in IWS view spec.
DeleteI think I am unable to connect in python due to my environment is using secured 'https'. would you know how to fix this?
This comment has been removed by the author.
ReplyDelete