This is second post in series of ‘CoreSync - Sync Sitecore Content’. Today we will walk through the ‘Item Web API’ and figure out what we need to customize and what to introduce new in order to extend this web service.
Let’s state the clear objectives what we do extend in Sitecore Item Web API service, answers are as follows:
Now as my objectives are clear, I need to first understand the existing code culture, details and flow. So that I can introduce the new processor on similar lines. To start doing it, service config file and tool ‘IL Spy’ come very handy. ‘Item Web API’ introduce couple of processor in ‘httpRequestBegin’ pipelines which make sure that how the upcoming request will be routed to further appropriate pipeline processors. So as shown in Figure 1.1, it is my first clue. I need to introduce new processor and need to evolve the way context properties resolves.
As you can see in Figure 1.1 highlighted in red rectangle, I commented out ‘Sitecore.ItemWebApi.Pipelines.HttpRequest.LaunchRequest, Sitecore.ItemWebApi’ and replaced it with my own processor ‘Custom.ItemWebAPI.Pipelines.HttpRequest.LaunchRequest, Custom.ItemWebAPI’. Figure 1.2 which tells what I replaced in new class.
During the course of writing this customization I realize I need a way where I can have better way to resolve the routine context properties so for that I have created a public static class named ‘Functions’ in namespace ‘Custom.ItemWebAPI.Pipelines.Common’ which provide me the functions like GetItem(), GetLanguage() etc., These same functions I have used in the above class.
What is in this class?
But yet I didn’t find the way to resolve my new processor, so as stated in ‘LaunchRequest’ class I need to look into ‘itemWebApiRequest’ pipeline. Where I find my next clue, as you can see in below snap there are three processor which I replaced with my custom processor, the most important processor(highlighted in yellow rectangle in Figure 1.3) is ‘Custom.ItemWebAPI.Pipelines.Request.CustomResolveAction’ because here is the magic where I can introduce new processor (here it is called action like create, update etc.,).
Rest of the processor I need to replace as I need to find the custom way to resolve items and pass necessary parameters to new processors. In ‘CustomResolveAction’ class I introduced couple of new functions which will suit my needs and also introduced new request verb for version processor (action). Also I need to have full media capabilities and enhanced the existing media update capability. Figure 1.4 which reflects the changes in comparison with old class structure.
Figure 1.5 shows how we had introduced new verb. We also need to distinguish new type of create facility where GUID can be retained and still need to persist existing create facility.
Will explain in detail what I have written in above two new processor in detail and there concepts. Till then Happy New year & Happy Coding to all of my friends.
Let’s state the clear objectives what we do extend in Sitecore Item Web API service, answers are as follows:
- Add a processor which should allow to create the Item numbered or language versions.
- Add a processor which should allow to create the new item while specifying the GUID for the new item.
Now as my objectives are clear, I need to first understand the existing code culture, details and flow. So that I can introduce the new processor on similar lines. To start doing it, service config file and tool ‘IL Spy’ come very handy. ‘Item Web API’ introduce couple of processor in ‘httpRequestBegin’ pipelines which make sure that how the upcoming request will be routed to further appropriate pipeline processors. So as shown in Figure 1.1, it is my first clue. I need to introduce new processor and need to evolve the way context properties resolves.
Figure -1.1 |
As you can see in Figure 1.1 highlighted in red rectangle, I commented out ‘Sitecore.ItemWebApi.Pipelines.HttpRequest.LaunchRequest, Sitecore.ItemWebApi’ and replaced it with my own processor ‘Custom.ItemWebAPI.Pipelines.HttpRequest.LaunchRequest, Custom.ItemWebAPI’. Figure 1.2 which tells what I replaced in new class.
Figure -1.2 |
During the course of writing this customization I realize I need a way where I can have better way to resolve the routine context properties so for that I have created a public static class named ‘Functions’ in namespace ‘Custom.ItemWebAPI.Pipelines.Common’ which provide me the functions like GetItem(), GetLanguage() etc., These same functions I have used in the above class.
What is in this class?
- You can find the code shared in GitHub. But for overview I write couple of overrides to GetItem() functions where I can get the item based on various parameters and you can call those as per your convenience.
But yet I didn’t find the way to resolve my new processor, so as stated in ‘LaunchRequest’ class I need to look into ‘itemWebApiRequest’ pipeline. Where I find my next clue, as you can see in below snap there are three processor which I replaced with my custom processor, the most important processor(highlighted in yellow rectangle in Figure 1.3) is ‘Custom.ItemWebAPI.Pipelines.Request.CustomResolveAction’ because here is the magic where I can introduce new processor (here it is called action like create, update etc.,).
Figure - 1.3 |
Rest of the processor I need to replace as I need to find the custom way to resolve items and pass necessary parameters to new processors. In ‘CustomResolveAction’ class I introduced couple of new functions which will suit my needs and also introduced new request verb for version processor (action). Also I need to have full media capabilities and enhanced the existing media update capability. Figure 1.4 which reflects the changes in comparison with old class structure.
Figure 1.4 |
Figure 1.5 shows how we had introduced new verb. We also need to distinguish new type of create facility where GUID can be retained and still need to persist existing create facility.
Figure - 1.5 |
Will explain in detail what I have written in above two new processor in detail and there concepts. Till then Happy New year & Happy Coding to all of my friends.
No comments:
Post a Comment