Friday, October 10, 2014

SOA Suite 12c: Getting started with the Spring Component

The Oracle SOA Suite Spring component has been present since SOA Suite 11.1.1.3 (11gR1 PS2). This component allows easy integration of Java code with other SOA Suite components such as (among others) BPEL, BPM and Business Rules. In SOA Suite 12c (12.1.3.0) this component is still present. In This blog post I will provide a short example on how it can be used and how the first problem I encountered with this component can be avoided.


Implementation

First create a SOA Application and an empty project. Next create a Java class with a public method and extract an interface with the public method. You can also supply JARs in the SCA-INF/lib folder of the project with the class/interface.


The result in this example. The Java class extends the interface.

 package nl.amis.smeetsm.springapp;  
 import org.eclipse.persistence.Version;  
 public class EclipselinkUtils implements IEclipselinkUtils {  
   public String getVersion() {  
     return Version.getVersion().toString();  
   }  
 }  

 package nl.amis.smeetsm.springapp;  
 public interface IEclipselinkUtils {  
   String getVersion();  
 }  

Next drag the Spring component from the component palette to the composite editor.


Give your new component an understandable name. Open the component. Paste the following (specific to this example);

   <sca:service name="EclipselinkUtilsService" target="impl" type="nl.amis.smeetsm.springapp.IEclipselinkUtils">  
     <interface.java interface="nl.amis.smeetsm.springapp.IEclipselinkUtils"/>  
   </sca:service>  
   <bean name="impl" class="nl.amis.smeetsm.springapp.EclipselinkUtils"/>  

On the following page; http://www.oracle.com/technetwork/articles/soa/jellema-events-soasuite-1902429.html at 'Implementing the Spring Bean' you can find more explanation on how to provide services and references in a Spring Component.

Next in the composite editor, drag the service interface to the services lane and indicate you want a webservice.


Compile and deploy.

To my own surprise (this was a simple example), the deployment failed.

 <Line 43, Column 57>: XML-24509: (Error) Duplicated definition for: 'identifiedType'  
 <Line 60, Column 28>: XML-24509: (Error) Duplicated definition for: 'beans'  
 <Line 157, Column 34>: XML-24509: (Error) Duplicated definition for: 'description'  
 <Line 169, Column 29>: XML-24509: (Error) Duplicated definition for: 'import'  
 <Line 191, Column 28>: XML-24509: (Error) Duplicated definition for: 'alias'  
 <Line 220, Column 33>: XML-24509: (Error) Duplicated definition for: 'beanElements'  
 <Line 235, Column 44>: XML-24509: (Error) Duplicated definition for: 'beanAttributes'  
 <Line 510, Column 43>: XML-24509: (Error) Duplicated definition for: 'meta'  
 <Line 518, Column 35>: XML-24509: (Error) Duplicated definition for: 'metaType'  
 <Line 535, Column 27>: XML-24509: (Error) Duplicated definition for: 'bean'  
 <Line 555, Column 38>: XML-24509: (Error) Duplicated definition for: 'constructor-arg'  
 <Line 623, Column 51>: XML-24509: (Error) Duplicated definition for: 'property'  
 <Line 634, Column 32>: XML-24509: (Error) Duplicated definition for: 'qualifier'  
 <Line 650, Column 48>: XML-24509: (Error) Duplicated definition for: 'attribute'  
 <Line 660, Column 36>: XML-24509: (Error) Duplicated definition for: 'lookup-method'  
 <Line 696, Column 38>: XML-24509: (Error) Duplicated definition for: 'replaced-method'  
 <Line 733, Column 31>: XML-24509: (Error) Duplicated definition for: 'arg-type'  
 <Line 760, Column 26>: XML-24509: (Error) Duplicated definition for: 'ref'  
 <Line 798, Column 28>: XML-24509: (Error) Duplicated definition for: 'idref'  
 <Line 832, Column 28>: XML-24509: (Error) Duplicated definition for: 'value'  
 <Line 860, Column 27>: XML-24509: (Error) Duplicated definition for: 'null'  
 <Line 874, Column 39>: XML-24509: (Error) Duplicated definition for: 'collectionElements'  
 <Line 892, Column 27>: XML-24509: (Error) Duplicated definition for: 'list'  
 <Line 915, Column 26>: XML-24509: (Error) Duplicated definition for: 'set'  
 <Line 936, Column 26>: XML-24509: (Error) Duplicated definition for: 'map'  
 <Line 957, Column 45>: XML-24509: (Error) Duplicated definition for: 'entry'  
 <Line 966, Column 28>: XML-24509: (Error) Duplicated definition for: 'props'  
 <Line 988, Column 26>: XML-24509: (Error) Duplicated definition for: 'key'  
 <Line 999, Column 27>: XML-24509: (Error) Duplicated definition for: 'prop'  
 <Line 1018, Column 39>: XML-24509: (Error) Duplicated definition for: 'propertyType'  
 <Line 1061, Column 41>: XML-24509: (Error) Duplicated definition for: 'collectionType'  
 <Line 1073, Column 40>: XML-24509: (Error) Duplicated definition for: 'listOrSetType'  
 <Line 1082, Column 34>: XML-24509: (Error) Duplicated definition for: 'mapType'  
 <Line 1104, Column 36>: XML-24509: (Error) Duplicated definition for: 'entryType'  
 <Line 1143, Column 36>: XML-24509: (Error) Duplicated definition for: 'propsType'  
 <Line 1156, Column 45>: XML-24509: (Error) Duplicated definition for: 'defaultable-boolean'  
 <Line 17, Column 33>: XML-24509: (Error) Duplicated definition for: 'annotation'  
 <Line 36, Column 45>: XML-24509: (Error) Duplicated definition for: 'typedParameterType'  
 <Line 40, Column 38>: XML-24509: (Error) Duplicated definition for: 'exportsType'  
 <Line 63, Column 45>: XML-24509: (Error) Duplicated definition for: 'registersScopeType'  
 <Oct 8, 2014 7:01:13 PM CEST> <Error> <ServletContext-/soa-infra> <BEA-000000> <Error during deployment  
 oracle.fabric.common.FabricException: Deployment Failed: Error occurred during deployment of component: EclipselinkUtilsSpring to service engine: implementation.spring, for composite: StringProject: SCA Engine deployment failure.: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 6 in XML document from URL [oramds:/deployed-composites/default/StringProject_rev1.0/Spring/EclipselinkUtilsSpring.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 1523; <Line 6, Column 1523>: XML-24500: (Error) Can not build schema 'http://www.springframework.org/schema/util' located at 'http://www.springframework.org/schema/util/spring-util.xsd'  
      at oracle.integration.platform.blocks.deploy.StandaloneCompositeDeploymentCoordinatorImpl.coordinateCompositeDeployment(StandaloneCompositeDeploymentCoordinatorImpl.java:109)  
      at oracle.integration.platform.blocks.deploy.StandaloneCompositeDeploymentCoordinatorImpl.coordinateCompositeDeployment(StandaloneCompositeDeploymentCoordinatorImpl.java:70)  
      at oracle.integration.platform.blocks.deploy.servlet.BaseDeployProcessor.deployNewComposite(BaseDeployProcessor.java:514)  
      at oracle.integration.platform.blocks.deploy.servlet.BaseDeployProcessor.deploySARs(BaseDeployProcessor.java:305)  
      at oracle.integration.platform.blocks.deploy.servlet.BaseDeployProcessor.deploySARs(BaseDeployProcessor.java:157)  
      Truncated. see log file for complete stacktrace  

To work around this you need to replace the line in the Spring XML file:

 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://xmlns.oracle.com/weblogic/weblogic-sca META-INF/weblogic-sca.xsd">  

with the much shorter line

 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://xmlns.oracle.com/weblogic/weblogic-sca META-INF/weblogic-sca.xsd">  

Something with the XML parser supplied with Weblogic server 12.1.3 apparently... (see http://stackoverflow.com/questions/5005901/duplicated-definition-for-identifiedtype)

After deployment you can test the service to confirm it works.



Conclusion

The Spring component allows easy integration with other SOA components. In release 12c, the error in 11g when a Java class is not compiled yet (see http://javaoraclesoa.blogspot.nl/2012/03/file-processing-using-spring-component.html) does not occur anymore, which is nice. However we get a different error in return. Luckily it is easily solved and we can enjoy this nice feature.

I've not yet found a way to give preference to a local class over the application server classes. I could alter the classpath of the entire server or soainfra but that could have other less pleasant side-effects. Maybe I´ll figure this one out in a later blogpost.

No comments:

Post a Comment