Sunday, May 28, 2017

Apache Maven and SOA 11g. Preparing Environment.

Good time of the day, It's time to resume the story of the happy marriage between SOA Studio 11g and Apache Maven.  This post will guide you trough environment configuration. During the process we will go through:

  • JDeveloper 11g extension configuration 
  • WebLogic Maven plugin configuration
  • Plugin and libraries installation. 
  • Configure External tools.
The actual configuration will take much less time than you would read this document because I have prepared scripts for you.  And good news it's lifetime configuration (for your workstation of course). Although, I presume that you have:
  • Oracle SOA Studio 11g (  installed and configured;
  • Your workstation has Internet access, or at least you have access to extensions and maven repository replicas. 
  • You know you Oracle Fusion Middleware directory name. If you don't it's location where you see folders similar to the screenshot below: 

Configure JDeveloper Extensions

You may have Apache Maven installed on your workstation, especially if you work under Linux and of course, it's the latest greatest one. However we should always keep in mind compatibility, so Let's use Maven, which will work for sure with our JDK and JDeveloper. If you'd make such thing and it will work with the latest maven releases, please let me know. 
Okay, Maven plugin installation is dull:
  1.  Start Oracle JDeveloper
  2. From the main menu select Help -> “Check For Updates …”
  3. In the Source list check  "Open Source and Partners Extensions" 
  4.  Locate and select 2 extensions with the name like  “Developer Preview: Maven*”
  5. Complete installation and restart IDE. 
To validate the installation 
  1.   Open command line window or shell terminal on the Linux box.
  2.  Go to your JDeveloper installation home  (in my case it’s C:\Oracle\Middleware\JDeveloper)
    C> cd \Oracle\Middleware\JDeveloper
  3. Check if you have your maven 2.1 installed and configured:
C:\Oracle\Middleware\jdeveloper>apache-maven-2.1.0\bin\mvn –version
Apache Maven 2.1.0 (r755702; 2009-03-18 15:10:27-0400)
Java version: 1.7.0_55
Java home: C:\Oracle\sqldeveloper.40\jdk\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7" version: "6.1" arch: "amd64" Family: "windows"

Before you continue with the further configuration, let's check what JRE/JDK is available in your system by default. For me, it's Java 7 and it will not work for SOA projects because default JDK for is JDK 1.6.  You can fix it with the environment variable JAVA_HOME which will point to the JDK from the Oracle Middleware. I prefer change JDK only for the maven script.  Steps are easy:

  1. Go to Maven extension bin folder 
  2.  Copy mvn or mvn.bat file to mvn6 or mvn6.bat (OS-depended)
  3.  Open mvn6 for edit and  add the new line in position 35 or 34:
  4. Save file and retest
    C:>cd \Oracle\Middleware\jdeveloper\apache-maven-2.1.0\bin\
    C>mvn6 --version
    Apache Maven 2.1.0 (r755702; 2009-03-18 15:10:27-0400)
    Java version: 1.6.0_24
    Java home: C:\Oracle\Middleware\jdk160_24\jre
    Default locale: en_US, platform encoding: Cp1252
    OS name: "windows 7" version: "6.1" arch: "amd64" Family: "windows"
Worth to notice, that you may create $HOME/.mavenrc for Mac/Linux or %USERPROFILE%\mavenrc_pre.bat for Window and keep all Maven related environment configuration settings there.

Configure WebLogic plugin

For the start, we prepare plugin archive and classes required for the plugin installation. 
Let's start from the session environment configuration:
  1. Set environment variables:

    C:>SET FMW_HOME=C:\Oracle\Middleware
    C:>SET MVN_HOME=%ORACLE_HOME%\apache-maven-2.1.0
    C:>SET WLS_HOME=%FMW_HOME%\wlserver_10.3
    C:>SET JAVA_HOME=%FMW_HOME%\jdk160_24
  2. Generate full client library:
    C:>cd %WLS_HOME%\server\lib\
    C:>%JAVA_HOME%\bin\java -jar %WLS_HOME%\server\lib\wljarbuilder.jar -profile wlfullclient
  3. Generate Maven plugin library:
                C:>%JAVA_HOME%\bin\java -jar %WLS_HOME%\server\lib\wljarbuilder.jar –profile weblogic-maven-plugin
  4. Extract plugin model user jar tool or archiver program like 7-zip. Additional details could be found in Oracle Documentation.  Or just use wls-pom.xml from the script repository. 
  5. Install libraries required by the plugin at runtime:

    C:>%MVN_HOME%\bin\mvn install:install-file -DartifactId=cryptoj -Dversion=1.0 -Dpackaging=jar -Dfile=%FMW_HOME%\modules\cryptoj.jar -DgeneratePom=true
    C:>%MVN_HOME%\bin\mvn install:install-file -DgroupId=weblogic -DartifactId=weblogic -Dversion=10.3.6 -Dpackaging=jar -Dfile=%WLS_HOME%\server\lib\weblogic.jar
    C:>%MVN_HOME%\bin\mvn install:install-file -DgroupId=weblogic -DartifactId=weblogic -Dversion=10.3.6  -Dpackaging=jar -Dfile=%WLS_HOME%\server\lib\wlfullclient.jar 
    C:>%MVN_HOME%\bin\mvn install:install-file -DgroupId=weblogic -DartifactId=webservices -Dversion=10.3.6  -Dpackaging=jar -Dfile=%WLS_HOME%\server\lib\webservices.jar

  6. Install WebLogic Maven plugin:

    C:>%MVN_HOME%\bin\mvn install:install-file -Dfile=weblogic-maven-plugin.jar -DpomFile=pom.xml
  7. Test plugin configuration:
    C:>%MVN_HOME%\bin\mvn  weblogic:help
Successful output should looks like this one:

Configure External Tools. 

JDeveloper Maven extension adds project and application support however, it's bound rather to the project that application. So, I normally create 3 additional external tools, all of them call maven with 3 major goals: clean, build and install. I'll guide you through the first one, Create the rest on your own. 

  1. From the JDeveloper main menu select Tools/External Tools… 
  2. Click on the “New …” button
  3. Select External Program as a tool type
  4. Specify program parameters as below. Don't forget to use substitutions, it will make your tools project unaware.
  5. Click Next button.
  6. Give the caption for the command, ToolTip text and select icon for the command to show.  Maven icons could be found in  ${}\jdev\extensions\oracle.jdeveloper.maven.jar, as on the screenshot below.
  7. Click Next. 
  8. I prefer to have all Maven tools in one click distance and add buttons to the Main Toolbar. Also, don't forget to mark "Save All" as before starts action. 
  9. Save External tool and repeat steps 1-9 for the other Maven goals. 
At this point, you have configured and integrated:

  • SOA Studio 11g with the Maven extension;
  • Apache Maven 2.1 installed with JDeveloper. 
  • Configured local repository with the Weblogic plugin
  • Universal external tools to clean, package and install applications.
Next time I'll show you how to build Web applications with Apache Maven. 

So long and thanks for all the fish! 

Wednesday, May 24, 2017

Mysterious ORAMED-01007 and the lack of the creativity.

I'm still working on the mega posts regarding Maven and SOA Studio 11g, it will be there in few days. Meanwhile, I have run into stupid rather than a mysterious situation. But let's start from the beginning. I have a composite, which gets master-detail records and transforms them to the normalized message using a mediator component. I've created a service with 2 parts request, resulting message, transformation, and yadda-yadda-yadda. Compile, deploy, test  and bada-boom:
<part name="detail">
<detail>ORAMED-01007:[Header variable declaration not valid]Header variable "" not recognized.
Possible Fix:Header variable should be of the format $in.header.<prefix>_<root-elem>.
Fix the header variable.
SOA Studio doesn't give you any clues, the project is compiled and deployed with no single warning. Finally, I have realized where I've been wrong. Look at this picture, and never do like this. If can't find what is wrong with the WSDL definition, check the answer below:

The solution is simple: Do not use "header" as a message part name. Regarding the Oracle documentation, this name is reserved for the SOAP headers access. And you will not figure it out until your component throws a runtime exception.

The moral is simple: name your variables with some creativity, and don't use reserved words in the SOA Composites. 

Wednesday, May 17, 2017

Apache Maven and SOA 11g.

I know it's time to go into the Clouds with the SOA Suite Service or at least upgrade your system to the SOA suite 12c and get all the CI perks out f the box.
Yeah, it sounds great as a sales pitch but in reality, you have good old 11g production system and upgrade project (not upgrade) in the "barely foreseeable future". It doesn't matter you can't use some of the automated techniques today (men, it would be a great improvement for your resume), it does mean you will spend some extra time for the initial application configuration.
Of course, you may google right away "soa 11g maven" and get some results with a bunch of copy-pastes "how to install Maven plugin and compile ADF application".  but I'm going to tell you the whole story in several parts:

Part I:   Preparing environment.
Part II:  Configure web applications
Part III: Configure J2EE applications
Part IV: Configure SOA Composites  

I will update this page with the URLs as soon as parts will be ready. I probably will not describe how to build and deploy ADF applications with Maven. There are documentation and some really great posts around.

Some MAVEN terms

I'm not going to complete with the Community and rephrase what it is and how it works. If you have no exposure with Maven or at least ANT. I would recommend you to stop right there and check Apache Maven Introductions 30 minutes long or the brief one because my descriptions and interpretations will be not exactly canonical. So let's go through some Maven terms:
Remote Repository - Some Service (local replica or global repository) which has descriptions for all available plugins and artifacts. From the SOA world - some service which helps you to find and download missed libraries or MAVEN plugins. In the reality, it's a way more complex set of services and processes, but we will use it as a yet another package manager.
  •  Local repository  - This one is more important, because all environment changes, downloaded libraries, and MAVEN plugins will be stashed here. Th local repository allows us to install our private artifacts and libraries without commits to the global services. Normally local repository resides under $HOME/.m2/repository folder (%USERPROFILE%\,m2\repository for the Windows platforms)
  •  Plugin - The building blocks of the Maven. Any Maven activity is a chin of the plugin(-s) executions. There are 2 types build and reporting plugins, and I will use and describe only building ones. 
  • POM (pom.xml) - Project Object Model is the most important item in the list. It describes the project, project dependencies, plugins and their execution steps.It allows you to tweak default Maven behavior (and we will do it a lot). In few words - POM describes plugins and their actions, which are required to build and install projects (archetypes in the Maven terms). 
  • Lifecycle - Formal name for the goals, targets or actions (pick your one you like). Instruction for Maven to perform some set of actions. For example, when you request clean - maven cleans all the target folders and prepares the project for the further actions. Next activity - compile will clean and compile your project. Next one build cleans, compiles and assembles your project into the package. Like I  said before, in reality, it's the heck of the simplification, but it's all we need to know to use maven with JDeveloper 11g.