OSB-12c : Get list of all public repositories using osb12c
Hello Everyone,
In this post, i am going to demonstrate how we can get all public repositories for a particular account from Bitbucket.
I assume that most of us deal with various kinds of SCM(Source Control Management) systems, it is also called as "Version controls" like SVN, Git, GitHub, Bitbucket or old age CVS etc.
Here we are referring to Bitbucket, which is one of popular VCs(Version Control). It is a distributed version control system unlike SVN(SVN is centralized version control system).
If you want to learn more about bitbucket, you can refer below "link".
I have used OSB-12c JDeveloper to design services and deployed same in WebLogic 12c server.
use-case
---------------
We need to design OSB service, which invokes REST APIs provided by Bitbucket to get a list of all repositories of a particular account.
Implementation:
----------------
1. Create proxy service and construct Bitbucket REST URL in that proxy service.
2. Create business service
3. Invoke business service in proxy service using "Routing".
4. Add "Routing-Options" in order to pick backend URL at run time[Dynamically].
5. Deploy service into local WebLogic server, and test it.
steps :
------------------------------
1. Create an OSB project and two folders within the project.
ProxyServices: It hosts all our proxy services and pipelines.
BusinessServices: It hosts all business services.
Note: By mistake, I have named by OSB project as "Create_Jenkins_Job", whereas it has to be "List_Repositories".
Name of Proxy : ListRepoProxyService
Transport: http
Select service type as 'Any XML'
service type: Any XML
In this step, End Point URL of service generated automatically.
Next Add a 'pipeline node',and stage in Request Pipeline part.
Name of stage: Save_Incoming_Body
Add an 'Assign' action with below deatils.
value : $body
variable : incomingBody
Next, add one more stage, and name it as "Construct BitBucket URL stage".
Name of Stage: Construct_Bitbucket_URL_stage
Add an 'Assign' action with below details
value : data($body/BitBucketRequest/UserName) //This will fetch username from incoming request.
variable : userName
Next, add one more 'Assign' node with below details
Value: "https://api.bitbucket.org/2.0/repositories/" //This is generic bitbucket url to fetch repos. //It will remain same, the only username will get // appended to this.
Variable: url
Next, add one more 'Assign' node with below details
value : fn:concat($url,$userName) //username gets appended to url.
variable : BitBucketUrl
Next, add ''Route Node" and add 'Routing' inside route node.
select business service "Route_To_Bitbucket.bix" //Remember
//Type of Business Service: REST
//Protocol of Business Service: Http
Next, add 'Routing-Options' inside route node with below details
URI: BitbucketUrl
Qos: Exactly Once
Mode: Request-Response
Verb: GET //It is imp to mention HTTP method when invoking REST service
Accept: application/json //Output of REST call will be in JSON format.
Next, in Response Action of Routing add an Assign action to capture output response.
value : $body
Variable : BitbucketResponse
Deploy this OSB project into local WebLogic server.
URL :- http://localhost:7001/servicebus
Test proxy service with below request. Please use below request format as i have hardcoded this(apologies this is very bad practice). In real time we can create XSDs and we can give XSD structure as input.
Request Format :
<BitBucketRequest>
<UserName>*****</UserName>
<Password></Password>
<AccessToken></AccessToken>
</BitBucketRequest>
Note: Remember Username should be valid username which is registered with Bitbucket and has some repos in it.
Eg: <UserName>Mark1991<UserName>
Once you hit green 'Run' button, you will get a response in JSON format. This Response contains all of your Repos details.
Note: Please disable HostName verification in WebLogic console for osb_server.
you can find HostName verification in below path in WebLogic console.
Home -> servers -> <Your servestr> -> SSL -> Advanced -> HostName Verification.
From drop down list select 'None' for HostName verification to disable it.













Comments
Post a Comment