Referencing custom core services with the Commerce Manager Client
Referencing custom core services with the Commerce Manager Client
Warning:
Build order and dependency resolution
To avoid build-time dependency resolution issues, you need to ensure the extension core is built before referencing custom services with the Commerce Manager Client.
If your CM client plugins needs to reference new or modified services in the core library extension, you need to do the following:
- Create a fragment for the com.elasticpath.cmclient.core plugin.
- Create a plugin-remote.xml file in the fragment's META-INF\conf directory.
- Add the service proxy bean definitions for the custom services to plugin-remote.xml.
- Add a HTTP proxy definition for the new service in ep-cmserver-plugin.xml.
For example, your core library extension defines a custom attribute service named com.extensions.service.attribute.ExtAttributeService. In com.elasticpath.cmclient.core/conf/spring/service/serviceCMClient, the service proxy bean for the out-of-the-box attributeService is defined as follows:
com.elasticpath.cmclient.core/src/main/resources/spring/service/serviceCMClient.xml <bean id="attributeService" class="com.elasticpath.cmclient.core.AuditHttpInvokerProxyFactoryBean"> <property name="serviceUrl"> <value>attributeService.remote</value> </property> <property name="serviceInterface"> <value>com.elasticpath.service.attribute.AttributeService</value> </property> </bean>
- In your fragment's plugin-remote.xml, your new service proxy bean definition might look similar to the following:
<bean id="attributeService" class="com.elasticpath.cmclient.core.EpHttpInvokerProxyFactoryBean"> <property name="serviceUrl"> <value>attributeService.remote</value> </property> <property name="serviceInterface"> <!-- reference custom service in core library extension: --> <value>com.extensions.service.attribute.ExtAttributeService</value> </property> </bean>
- In the Commerce Manager server's extension project, create an HTTP proxy definition for the new service in ep-cmserver-plugin.xml.
<bean id="httpAttributeService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter"> <property name="service"> <ref bean="attributeService"/commerce-legacy/> </property> <property name="serviceInterface"> <value>com.extensions.service.attribute.ExtAttributeService</value> </property> </bean>
- If you are creating a new service, not overriding an existing one, the mappings property of the SimpleUrlHandlerMapping bean must include the URL to the new service mapping in ep-cmserver-plugin.xml. For example, if attributeService is a new service, we add the following:
<bean id="SimpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" parent="AbstractSimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/commerce-legacy/attributeService.remote">httpAttributeService</prop> </props> </property> </bean>