Domain Value Maps in Oracle Service Bus

https://blogs.oracle.com/christomkins/entry/domain_value_maps_in_oracle_se

Advertisements

Using SAP Adapter with OSB 11g (PS3)

Using SAP Adapter with OSB 11g (PS3)

Overview

We see a lot of requests from the field for a sample project demonstrating the usage of SAP Adapter with OSB. A viewlet is made to address this request and is available on OTN.

As a supplement, a brief overview is presented here to outline the steps required to build such a simple project with OSB 11g and SAP Adapter for the PS3 release.

At the time of writing this note, PS3 was the latest release for the iWay Adapters. This note can, however, serve as a reference document for post-install steps, while working with later releases.

Install/Configure

The installation is fairly standard. So, we will skip the details here. The high level sequence is outlined below:

Database Install

  • Install Database – EE is recommended but XE is good enough for demo purposes.

OSB 11g PS3 Install

  • Install Weblogic w/OEPE for PS3 release
  • Install OSB 11g PS3 release, only choosing the OSB option

Adapter Install

  • Install Adapter PS2 in the OSB 11g PS3 Middleware home
  • Upgrade OPatch that came with the OSB 11g PS3 release
  • Apply Adapter Patch PS3

OSB Configuration

  • Create OSB Domain – a simple domain with Adminserver and one Managed Server

Adapter Configuration

  • Modify $ORACLE_HOME/3rdParty/ApplicationAdapters/iwafca.rar/META-INF/ra.xml
  • Deploy Adapter rar and JCA Test Servlet
  • Copy SAP specific libraries in
    • $ORACLE_HOME/3rdParty/ApplicationAdapters/lib (for Design-time)
    • $DOMAIN_HOME/lib (for Run-time)

Project Build – Design-Time

For building OSB projects with iWay Adapters, we use the design-time browser interface of OSB 11g and the Application Explorer design-time tool from iWay. The following sections highlight the overall sequence.

OSB Design Time – Part 1

First, create a place-holder project with appropriate folders in OSB, that can be used to export artifacts from the Application Explorer tool directly.

Application Explorer – iWay Design Time Tool

For iWay Adapters, we use the design-time tool Application Explorer for introspection of SAP repository objects and generate the metadata consisting of xsd/wsdl and jca binding files.

To launch Application Explorer, the environment has to be properly set by running the setDomainEnv script file created as part of the Weblogic server installation. A sample modified script to launch Application Explorer is shown below.

The rest of the process consists of the following key steps.

Define Configuration

Create JCA based configuration as opposed to iBSE, which is webservice based and strictly now used for backward compatibility purposes.

Define MySAP Adapter Target

Create the SAP endpoint target providing login credentials and server details.

Identify SAP Repository Object

Connect to remote SAP Repository and identify the object to be used for communication, e,g, BAPI, IDOC, RFC etc.

Export Artifacts to OSB Project

Select object, right-click and export WSDL, XSD and JCA binding information directly to pre-created OSB project.

OSB Design Time – Part 2

Go back to the OSB project created earlier to find the objects exported from Application Explorer. The following few steps complete the build process of the basic OSB project, so that it can be tested from within the OSB console.

Generate WSDL and Service

Generate WSDL and Service from the JCA Binding exported from Application Explorer and save them in a separate project sub-folder, e.g. BusinessServices.

This service and wsdl can now be further referred to build other proxy services and complex OSB projects. But for our purposes of using the SAP Adapter in OSB, the OSB project is complete and can be tested.

Testing – Run-Time

Without building a fully functional and meaningful OSB project with proper proxy services and pipelines, OSB console provides the capability to quickly test a business service from a test console. This can be compared to the similar capability found within Application Explorer. We will use the OSB test console here to validate the runtime access of SAP data from OSB.

OSB Test Console

Launch the test console by clicking the test icon under Actions category from the service generated earlier. Type in test data and click on Execute.

The response will come back from SAP and the results returned will be displayed in a separate window.

iWay SAP Adapters can thus be very conveniently used to generate services and the JCA binding information directly into an existing OSB project. Furthermore, the OSB test console can be launched to quickly validate the runtime testing of a newly built service with live data from SAP.

SSH X Forwarding xauth cookie MIT-MAGIC-COOKIE with SUDO handling

It’s been years since I stumbled across this, but today I was trying to launch a GUI from new Linux server and got this instead :(

X11 connection rejected because of wrong authentication.
Error: cannot open display: localhost:12.0

So, I dug out my notes and thought it would make sense to then blog it for next time!

Once an SSH connection is established, the server will  generate a random authorization (xauth) cookie and store it in ~./Xauthority on the server, known as a MIT-MAGIC-COOKIE-1 entry.

Every time you login, a new cookie is generated, and because I’m switching to another user, its lost.  In order to access the local display again, I need to add my cookie entry from the previous connection like this…

On this occasion, I was using my personal account to login initially, then “su” to the “oracle” account.

[garth@server1 ~]$ echo $DISPLAY
localhost:12.0

Fetch the magic cookie entry relevant to your local display:

[garth@server1 ~]$ echo xauth add `xauth list ${DISPLAY#localhost}`
xauth add server1.localdomain/unix:12 MIT-MAGIC-COOKIE-1 2928a6e16b7d6d57041dcee632764b72

Switch user to “oracle” and add the entry into your /home/oracle/.Xauthority file (by copying the ‘xauth add…’ line from above:

[garth@server1 ~]$ sudo su - oracle
[oracle@server1 garth]$ echo $DISPLAY
localhost:12.0
[oracle@server1 garth]$ xauth add server1.localdomain/unix:12 MIT-MAGIC-COOKIE-1 2928a6e16b7d6d57041dcee632764b72
xauth:  creating new authority file /home/oracle/.Xauthority

After this your X-session should work…try something like “xcalc” or “firefox” to test it first and you should be ready to go!

[oracle@server1 garth]$ xcalc
[oracle@server1 garth]$ cd /tmp/client
[oracle@server1 garth]$ ./runInstaller

Powermock – Mockito Integration Example

Powermock – Mockito Integration Example

Posted by: Ram Mokkapaty in Mockito April 1st, 2015

Most of the mocking frameworks in Java, including Mockito, cannot mock static methods or final classes. If we come across a situation where we need to test these components, we won’t be able to unless we re-factor the code and make them testable. For example:

Making private methods packaged or protected
Avoiding static methods

But re-factoring at the cost of good design may not always be the right solution.
In such scenarios, it makes sense to use a testing framework like Powermock which allows us to mock even the static, final and private methods.
Good thing about Powermock is that it doesn’t re-invent the testing framework and in fact enhances the testing frameworks like Easymock and Mockito.

In this article, we will see an integration example of Powermock and Mockito but first let’s do the setup.

Below are my setup details:

I am using Maven – the build tool
Eclipse as the IDE, version Luna 4.4.1.
JUnit is my testing framework.
Add Mockito and PowerMockito dependencies to our pom.xml.

1. Dependencies in pom.xml

Our dependencies consist of:

junit
mockito-core
powermock-api-mockito
powermock-module-junit4

pom.xml:
01
<project xmlns=”http://maven.apache.org/POM/4.0.0&#8243; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
02
xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”&gt;
03
<modelVersion>4.0.0</modelVersion>
04
<groupId>com.javacodegeeks.testng.maven</groupId>
05
<artifactId>testngMaven</artifactId>
06
<version>0.0.1-SNAPSHOT</version>
07
<dependencies>
08
<dependency>
09
<groupId>junit</groupId>
10
<artifactId>junit</artifactId>
11
<version>4.11</version>
12
<scope>test</scope>
13
</dependency>
14
<dependency>
15
<groupId>org.mockito</groupId>
16
<artifactId>mockito-core</artifactId>
17
<version>2.0.5-beta</version>
18
</dependency>
19
<dependency>
20
<groupId>org.powermock</groupId>
21
<artifactId>powermock-api-mockito</artifactId>
22
<version>1.6.2</version>
23
<scope>test</scope>
24
</dependency>
25
<dependency>
26
<groupId>org.powermock</groupId>
27
<artifactId>powermock-module-junit4</artifactId>
28
<version>1.6.2</version>
29
<scope>test</scope>
30
</dependency>
31
</dependencies>
32
</project>
2. System Under Test (SUT)

Our system under test is a system called SomeSystem which owns some services. A service is defined by Service interface which has couple of methods getName() and start(). If the start of the service is successful it will return 1 else 0.

One can add a Service to the SomeSystem using add(service) method. Our SubSystem has a start() method which will start the services it contains. On start of each service, ServiceListener is notified of the success or failure of the service.

SomeSystem:
01
package com.javacodegeeks.mockito;
02

03
import java.util.ArrayList;
04
import java.util.List;
05

06
public class SomeSystem {
07
private List services = new ArrayList();
08
private ServiceListener serviceListener;
09
private List events = new ArrayList();
10

11
public void start() {
12
for (Service service : services) {
13
boolean success = startServiceStaticWay(service) > 0;
14
notifyServiceListener(serviceListener, service, success);
15
addEvent(service, success);
16
}
17
}
18

19
private void addEvent(Service service, boolean success) {
20
events.add(getEvent(service.getName(), success));
21
}
22

23
private String getEvent(String serviceName, boolean success) {
24
return serviceName + (success ? “started” : “failed”);
25
}
26

27
public static void notifyServiceListener(ServiceListener serviceListener,
28
Service service, boolean success) {
29
if (serviceListener != null) {
30
if (success) {
31
serviceListener.onSuccess(service);
32
} else {
33
serviceListener.onFailure(service);
34
}
35
}
36
}
37

38
public void add(Service someService) {
39
services.add(someService);
40
}
41

42
public static int startServiceStaticWay(Service service) {
43
int returnCode = service.start();
44
return returnCode;
45
}
46

47
public void setServiceListener(ServiceListener serviceListener) {
48
this.serviceListener = serviceListener;
49
}
50

51
public List getEvents() {
52
return events;
53
}
54
}

Service:
1
package com.javacodegeeks.mockito;
2

3
public interface Service {
4
String getName();
5
int start();
6
}

ServiceListener:
1
package com.javacodegeeks.mockito;
2

3
public interface ServiceListener {
4
void onSuccess(Service service);
5
void onFailure(Service service);
6
}
3. Integrate PowerMockito and Mockito

In setupMock(), we will set up our system. We will create mock objects for Service and ServiceListener using Mockito.mock. Both are interfaces and we don’t have the actual implementations ready. Since SomeSystem is our SUT, we will create a spy object of it so that later we can stub some of its behavior.

Now let’s come to our first test startSystem:

We will stub service.start() using PowerMockito so that it returns 1.
Next, we start the system calling system.start()
Finally, we will verify the behavior using Mockito’s verify() API
1
Mockito.verify(serviceListener).onSuccess(service);

Notice that we stub using PowerMockito but verify using Mockito. This shows that Powermock doesn’t re-invent the wheel rather enhances the existing testing frameworks.

PowerMockitoIntegrationExample:
01
package com.javacodegeeks.mockito;
02

03
import org.junit.Before;
04
import org.junit.Test;
05
import org.junit.runner.RunWith;
06
import org.mockito.Mockito;
07
import org.powermock.api.mockito.PowerMockito;
08
import org.powermock.modules.junit4.PowerMockRunner;
09

10

11
@RunWith(PowerMockRunner.class)
12
public class PowerMockitoIntegrationExample {
13
private Service service;
14
private SomeSystem system;
15
private ServiceListener serviceListener;
16

17
@Before
18
public void setupMock() {
19
// Mock
20
service = Mockito.mock(Service.class);
21
serviceListener = Mockito.mock(ServiceListener.class);
22

23
system = Mockito.spy(new SomeSystem());
24
system.add(service);
25
system.setServiceListener(serviceListener);
26
}
27

28
@Test
29
public void startSystem() {
30
// Stub using Mockito and PowerMockito
31
p(“Stub using PowerMockito. service.start() should return 1 as we want start of the service to be successful”);
32
PowerMockito.when(service.start()).thenReturn(1);
33

34
// Run
35
p(“Start the system, should start the services in turn”);
36
system.start();
37

38
// Verify using Mockito
39
p(“Verify using Mockito that service started successfuly”);
40
Mockito.verify(serviceListener).onSuccess(service);
41

42
p(“Verifed. Service started successfully”);
43
}
44

45
private void p(String s) {
46
System.out.println(s);
47
}
48
}

Output:
1
Stub using PowerMockito. service.start() should return 1 as we want start of the service to be successful
2
Start the system, should start the services in turn
3
Verify using Mockito that service started successfuly
4
Verifed. Service started successfully
4. Mocking Static Method

The use of static methods goes against the Object Oriented concepts but in real world we still use a lot of static methods and there are times when it makes sense to use static methods. Nevertheless, the ability to mock static methods may come handy to us. In this example, we will stub a static non-void method.

In the beginning of test class you will notice @RunWith annotation that contains PowerMockRunner.class as value. This statement tells JUnit to execute the test using PowerMockRunner.

You may also see annotation @PrepareForTest which takes the class to be mocked. This is required when we want to mock final classes or methods which either final, private, static or native.

We will use PowerMockito.mockStatic statement which takes in the class to be mocked. It tells PowerMockito to mock all the static methods. We then stub the static method’s behavior.

For example, in stubStaticNonVoidMethod, we stub SomeSystem.startServiceStaticWay to return 1.
1
PowerMockito.when(SomeSystem.startServiceStaticWay(service)).thenReturn(1);

PowerMockitoStaticMethodExample:
01
package com.javacodegeeks.mockito;
02

03
import org.junit.Before;
04
import org.junit.Test;
05
import org.junit.runner.RunWith;
06
import org.mockito.Mockito;
07
import org.powermock.api.mockito.PowerMockito;
08
import org.powermock.modules.junit4.PowerMockRunner;
09

10

11
@RunWith(PowerMockRunner.class)
12
public class PowerMockitoStaticMethodExample {
13
private Service service;
14
private SomeSystem system;
15
private ServiceListener serviceListener;
16

17
@Before
18
public void setupMock() {
19
// Mock
20
service = Mockito.mock(Service.class);
21
serviceListener = Mockito.mock(ServiceListener.class);
22

23
system = new SomeSystem();
24
//system = Mockito.spy(new SomeSystem());
25
system.add(service);
26
system.setServiceListener(serviceListener);
27
}
28

29
@Test
30
public void stubStaticNonVoidMethod() {
31
// Stub static method startServiceStatic to start successfully
32
p(“Call mockStatic SomeSystem.class to enable static mocking”);
33
PowerMockito.mockStatic(SomeSystem.class);
34

35
p(“Stub static method startServiceStaticWay to return 1”);
36
PowerMockito.when(SomeSystem.startServiceStaticWay(service))
37
.thenReturn(1);
38

39
// Run
40
p(“Start the system, should start the services in turn”);
41
system.start();
42

43
// Verify success
44
p(“Verify using Mockito that service started successfuly”);
45
Mockito.verify(serviceListener).onSuccess(service);
46

47
// Stub static method startServiceStatic to fail
48
p(“Stub static method startServiceStaticWay to return 0”);
49
PowerMockito.when(SomeSystem.startServiceStaticWay(service))
50
.thenReturn(0);
51

52
// Run
53
p(“Start the system again”);
54
system.start();
55

56
// Verify failure
57
p(“Verify using Mockito that service has failed”);
58
Mockito.verify(serviceListener).onFailure(service);
59
}
60

61
private void p(String s) {
62
System.out.println(s);
63
}
64
}

Output:
1
Call mockStatic SomeSystem.class to enable static mocking
2
Stub static method startServiceStaticWay to return 1
3
Start the system, should start the services in turn
4
Verify using Mockito that service started successfuly
5
Stub static method startServiceStaticWay to return 0
6
Start the system again
7
Verify using Mockito that service has failed
5. Mocking static void Method

In this example, we will mock a void static method. The first step would be to call PowerMockito.mockStatic similar to the static non-void method. Since a void method doesn’t return anything, the earlier way of mocking static methods won’t work here.
1
PowerMockito.doNothing().when(SomeSystem.class);

Next, we will stub the behavior. After stubbing, we will call the static method on which it applies.
1
SomeSystem.notifyServiceListener(serviceListener, service, true);

We will follow similar style for verifying a static void method.
1
PowerMockito.verifyStatic();
2
SomeSystem.startServiceStaticWay(service);

PowerMockitoStaticVoidMethodExample:
01
package com.javacodegeeks.mockito;
02

03
import org.junit.Before;
04
import org.junit.Test;
05
import org.junit.runner.RunWith;
06
import org.mockito.Mockito;
07
import org.powermock.api.mockito.PowerMockito;
08
import org.powermock.core.classloader.annotations.PrepareForTest;
09
import org.powermock.modules.junit4.PowerMockRunner;
10

11

12
@RunWith(PowerMockRunner.class)
13
public class PowerMockitoStaticVoidMethodExample {
14
private Service service;
15
private SomeSystem system;
16
private ServiceListener serviceListener;
17

18
@Before
19
public void setupMock() {
20
service = Mockito.mock(Service.class);
21
serviceListener = Mockito.mock(ServiceListener.class);
22

23
system = new SomeSystem();
24
system.add(service);
25
system.setServiceListener(serviceListener);
26
}
27

28
@PrepareForTest({ SomeSystem.class })
29
@Test
30
public void stubStaticVoidMethod() {
31
p(“Call mockStatic SomeSystem.class to enable static mocking”);
32
PowerMockito.mockStatic(SomeSystem.class);
33

34
p(“Stub static void method SomeSystem.notifyServiceListener to do nothing”);
35
PowerMockito.doNothing().when(SomeSystem.class);
36
SomeSystem.notifyServiceListener(serviceListener, service, true);
37

38
p(“Stub using PowerMockito. service.start() should return 1 as we want start of the service to be successful”);
39
PowerMockito.when(service.start()).thenReturn(1);
40

41
p(“Start the system”);
42
system.start();
43

44
p(“Verify static method startServiceStaticWay(service) is called”);
45
PowerMockito.verifyStatic();
46
SomeSystem.startServiceStaticWay(service);
47

48
p(“Verify serviceListener.onSuccess(service) is not called as notifyServiceListener is stubbed to do nothing”);
49
Mockito.verify(serviceListener, Mockito.never()).onSuccess(service);
50
}
51

52
private void p(String s) {
53
System.out.println(s);
54
}
55
}

Output:
1
Call mockStatic SomeSystem.class to enable static mocking
2
Stub static void method SomeSystem.notifyServiceListener to do nothing
3
Stub using PowerMockito. service.start() should return 1 as we want start of the service to be successful
4
Start the system
5
Verify static method startServiceStaticWay(service) is called
6
Verify serviceListener.onSuccess(service) is not called as notifyServiceListener is stubbed to do nothing
6. Subbing Private Method

Using PowerMockito we can stub as well as verify private methods. In this example, I will show you how to stub a private method.

Our private method addEvent adds an event to the list. The event will tell us know whether a service started successfully or failed. Since we can’t access the private method, we will have to pass the SUT object, private method name along with the method arguments to PowerMockito.doNothing().when() method.

In test case stubPrivateMethodAddEvent, we stub addEvent to do nothing.
1
PowerMockito.doNothing().when(system, “addEvent”, service, true)

In test case stubPrivateMethodGetEventString, we stub getEvent to return some hardcoded string.
1
PowerMockito.when(system, “getEvent”, serviceA, true).thenReturn(serviceA_is_successful);

PowerMockitoStubPrivateMethodExample:
01
package com.javacodegeeks.mockito;
02

03

04
import org.junit.Before;
05
import org.junit.Test;
06
import org.junit.runner.RunWith;
07
import org.mockito.Mockito;
08
import org.powermock.api.mockito.PowerMockito;
09
import org.powermock.core.classloader.annotations.PrepareForTest;
10
import org.powermock.modules.junit4.PowerMockRunner;
11
import org.junit.Assert;
12

13

14
@PrepareForTest({ SomeSystem.class })
15
@RunWith(PowerMockRunner.class)
16
public class PowerMockitoStubPrivateMethodExample {
17
private Service service;
18
private SomeSystem system;
19
private ServiceListener serviceListener;
20

21
@Before
22
public void setupMock() {
23
// Mock
24
service = Mockito.mock(Service.class);
25
serviceListener = Mockito.mock(ServiceListener.class);
26

27
system = PowerMockito.spy(new SomeSystem());
28
system.add(service);
29
system.setServiceListener(serviceListener);
30
}
31

32
@Test
33
public void stubPrivateMethodAddEvent() throws Exception {
34
p(“Stub using PowerMockito. service.start() should return 1 as we want start of the service to be successful”);
35
PowerMockito.when(service.start()).thenReturn(1);
36

37
p(“Stub service name to return serviceA”);
38
Mockito.when(service.getName()).thenReturn(“serviceA”);
39

40
p(“Stub private addEvent to do nothing”);
41
PowerMockito.doNothing().when(system, “addEvent”, service, true);
42

43
p(“Start the system, should start the services in turn”);
44
system.start();
45

46
p(“Since we have stubbed addEvent, assert that system.getEvents() is empty”);
47
Assert.assertTrue(system.getEvents().isEmpty());
48
}
49

50
@Test
51
public void stubPrivateMethodGetEventString() throws Exception {
52
final String serviceA = “serviceA”;
53
final String serviceA_is_successful = serviceA + ” is successful”;
54
p(“Stub using PowerMockito. service.start() should return 1 as we want start of the service to be successful”);
55
PowerMockito.when(service.start()).thenReturn(1);
56

57
p(“Stub service name to return serviceA”);
58
Mockito.when(service.getName()).thenReturn(serviceA);
59

60
p(“Stub private addEvent to do nothing”);
61
PowerMockito.when(system, “getEvent”, serviceA, true).thenReturn(serviceA_is_successful);
62

63
p(“Start the system, should start the services in turn”);
64
system.start();
65

66
p(“Since we have stubbed getEvent, assert that system.getEvents() contains the event string”);
67
Assert.assertTrue(!system.getEvents().isEmpty());
68
Assert.assertEquals(serviceA_is_successful, system.getEvents().get(0));
69
System.out.println(system.getEvents());
70
}
71

72
private void p(String s) {
73
System.out.println(s);
74
}
75
}

In stubPrivateMethodAddEvent, since we have stubbed addEvent to do nothing, no events will added to the list.

In stubPrivateMethodGetEventString, we confirm that the event string we have returned is found in the events.

Output:
01
Test stubPrivateMethodAddEvent:
02
Stub using PowerMockito. service.start() should return 1 as we want start of the service to be successful
03
Stub service name to return serviceA
04
Stub private addEvent to do nothing
05
Start the system, should start the services in turn
06
Since we have stubbed addEvent, assert that system.getEvents() is empty
07

08
Test stubPrivateMethodGetEventString:
09
Stub using PowerMockito. service.start() should return 1 as we want start of the service to be successful
10
Stub service name to return serviceA
11
Stub private addEvent to do nothing
12
Start the system, should start the services in turn
13
Since we have stubbed getEvent, assert that system.getEvents() contains the event string
14
[serviceA is successful]
7. Verifying Private Method

Verification is similar to stubbing and PowerMockito allows us to verify even the private methods. The name of the method is passed to the PowerMockito.verifyPrivate along with its arguments.
1
PowerMockito.verifyPrivate(system).invoke(“addEvent”, new Object[] { service, true });

PowerMockitoVerifyPrivateMethodExample:
01
package com.javacodegeeks.mockito;
02

03

04
import org.junit.Before;
05
import org.junit.Test;
06
import org.junit.runner.RunWith;
07
import org.mockito.Mockito;
08
import org.powermock.api.mockito.PowerMockito;
09
import org.powermock.modules.junit4.PowerMockRunner;
10

11
@RunWith(PowerMockRunner.class)
12
public class PowerMockitoVerifyPrivateMethodExample {
13
private Service service;
14
private SomeSystem system;
15
private ServiceListener serviceListener;
16

17
@Before
18
public void setupMock() {
19
// Mock
20
service = Mockito.mock(Service.class);
21
serviceListener = Mockito.mock(ServiceListener.class);
22

23
system = Mockito.spy(new SomeSystem());
24
system.add(service);
25
system.setServiceListener(serviceListener);
26
}
27

28
@Test
29
public void verifyPrivateMethods() throws Exception {
30
p(“Stub using PowerMockito. service.start() should return 1 as we want start of the service to be successful”);
31
PowerMockito.when(service.start()).thenReturn(1);
32

33
p(“Stub service name to return serviceA”);
34
Mockito.when(service.getName()).thenReturn(“serviceA”);
35

36
p(“Start the system, should start the services in turn”);
37
system.start();
38

39
p(“Verify private method addEvent(service, true) is called”);
40
PowerMockito.verifyPrivate(system).invoke(“addEvent”,
41
new Object[] { service, true });
42
p(“Verified private method is called”);
43
}
44

45
private void p(String s) {
46
System.out.println(s);
47
}
48
}

Output:
1
Stub using PowerMockito. service.start() should return 1 as we want start of the service to be successful
2
Stub service name to return serviceA
3
Start the system, should start the services in turn
4
Verify private method addEvent(service, true) is called
5
Verified private method is called
8. Download Source Code

This example was about PowerMockito and Mockito integration.
Download
You can download the full source code of this example here: powerMockitoIntegration.zip

Java XPath Example: concat

We studied about Xpath normalize-space() method in the previous example. In this example, we will study how the concat(String s1, String s2, String... s3) method works.

The XPath-concat method works similar to the String#concat method. It joins two or more strings into a single string. The argument strings maybe two or more static strings and/or they may be two or more XPathExpression to evaluate. The output from the XPathExpressionis then concatenated and the resulting string is returned.

We will look at an example to see how the concat method works in practice:

Consider the XML file below:

cricketTeam_info.xml:

01 <?xml version="1.0" encoding="UTF-8"?>
02
03 <cricketers>
04     <cricketer type="righty">
05         <name>MS Dhoni</name>
06         <role>Captain</role>
07         <position>Wicket-Keeper</position>
08     </cricketer>
09     <cricketer type="lefty">
10         <name>Shikhar Dhawan</name>
11         <role>Batsman</role>
12         <position>Point</position>
13     </cricketer>
14     <cricketer type="righty">
15         <name>Virat Kohli</name>
16         <role>Batsman</role>
17         <position>cover</position>
18     </cricketer>
19     <cricketer type="righty">
20         <name>Shami</name>
21         <role>Bowler</role>
22         <position>SquareLeg</position>
23     </cricketer>
24     <cricketer type="lefty">
25         <name>Zaheer Khan</name>
26         <role>Bowler</role>
27         <position>FineLeg</position>
28     </cricketer>
29 </cricketers>

Now we will concat the attributes of two cricketers using the XPath concat method.

XpathNormalizeSpaceDemo.java:

01 import javax.xml.parsers.DocumentBuilder;
02 import javax.xml.parsers.DocumentBuilderFactory;
03 import javax.xml.xpath.XPath;
04 import javax.xml.xpath.XPathConstants;
05 import javax.xml.xpath.XPathExpression;
06 import javax.xml.xpath.XPathFactory;
07
08 import org.w3c.dom.Document;
09
10
11 public class XpathSubStringDemo
12 {
13         public static void main(String[] args) throws Exception
14         {
15
16                 DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
17                 documentBuilderFactory.setNamespaceAware(true);
18                 DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
19                 Document doc = documentBuilder.parse("src/cricketTeam_info.xml");
20
21                 XPathFactory xpathFactory = XPathFactory.newInstance();
22                 XPath xpath = xpathFactory.newXPath();
23
24                 //XPath concat example
25                 XPathExpression expr = xpath.compile("concat(//cricketer[name='Shami']/@type,//cricketer[name='Zaheer Khan']/@type)");
26                 String combination = (String) expr.evaluate(doc, XPathConstants.STRING);
27                 System.out.println("The concat result is : " + combination);
28
29
30         }
31 }

Output:

1 The concat result is : rightylefty

As you can see in the output, the result of the two Xpath expressions are concatenated producing output as rightylefty.

We can also concat static string with output of an XpathExpression or two static strings themselves. The snippet below demonstrates this:

1 XPathExpression expr = xpath.compile("concat('The handed-ness of ZKhan is : ',//cricketer[name='Zaheer Khan']/@type)");
2 String result = (String) expr.evaluate(doc, XPathConstants.STRING);
3 System.out.println(result);

In the above code-snippet, the concat method has:

1 The handed-ness of ZKhan is : lefty

Download the source code

Here we studied how the Xpath concat(String s1, String s2, String... s3) method works.

Download
You can download the source code of this example here: XPathConcatDemo.zip

Cordwood Flooring by Sunny in sunny Arizona

Cordwood Construction

Sunny Pettis Lutz  send some photos of her gorgeous, hand-made cordwood floor.  The following is a detailed list of how they made their floor with legal pickings from the state forest.   “Go out to the forest and harvest dead trees. In our area that means Juniper and Pine.  We are using Shaggy Bark Juniper and Alligator Bark Juniper.”

Sunny Pettiz Lutz Cordwood floor 7

Cordwood flooring by Sunny Pettis Lutz in Cornville, AZ 2 step by step instrucitonsRun each piece through the chop saw set at 1″.

Sunny Pettiz Lutz Cordwood floor 8

Prepare surface by sweeping and mopping clean. We are gluing directly onto our concreet slab.  Sand both sides using a belt sander.Begin to layout disks on the floor. Try to get them as close as possible. Work in 2′ sections.

Cordwood flooring by Sunny Pettis Lutz in Cornville, AZ 2 step by step instrucitons work on 2 foot section at a time

Glue the pieces down and firmly tamp them.  We’re using Loctite PL Premium Construction Adhesive.

Cordwood flooring by Sunny Pettis Lutz in Cornville, AZ

Sunny Pettiz Lutz Cordwood floor 6

Apply a light coat of polyurethane to the surface of the disks. (this is to prevent the grout from adhering to the tops)

Grout the spaces…

View original post 372 more words

SOA Suite 12c: Topology Suggestions

Original By jay.kasi on Dec 18, 2014

In this article, I make some suggestions and provide opinions on topologies for SOA Suite 12c that is commonly used and supported. Only the EDG topology is thoroughly tested by Oracle though.

  • One consideration when deciding on topologies is that Upgrade is always domain wide. All products deployed to the domain must release in the same release train and you should be willing to upgrade all of them at the same time.
  • Centralized administration is one factor but should not be the only reason to put two different products in the same domain. EM Cloud Control could be used as a solution for that.
  • Typically Service Bus and SOA Suite belong in different tiers in an end to end architecture so they would be in separate domains. This is true if Service Bus is being used on an enterprise scale routing to multiple SOA domains and other services. However if Service Bus is used primarily for mediating and providing routing for SOA Suite Composites in a domain, it would be in the same domain, but typically in separate clusters for optimum performance and scalability. However it  is possible starting in 12c to have Service Bus and SOA Suite in the same cluster.  The only possible reason for this is reducing memory and is uncommon.
  • Governance products like OER and UDDI should not be in a SOA Suite or Service Bus domain. They should be in a separate domain. OER should be in a separate domain from UDDI. UDDI is a third party product and putting it in the same domain may cause upgrade issues.
  • You can target multiple products to the same cluster by targeting the appropriate user extensible server group to  the servers in the cluster.
    1. SOA Suite is targeted to a server by targeting either the user extensible server group SOA-MGD-SVRS or SOA-MGD-SVRS-ONLY.
    2. Service Bus is targeted to a server by targeting either the user extensible server group OSB-MGD-SVRS-COMBINED or OSB-MGD-SVRS-ONLY.
    3. BAM is targeted to a server by targeting either the user extensible server group BAM12-MGD-SVRS or BAM12-MGD-SVRS-ONLY.
    4. MFT is targeted to a server by targeting either the user extensible server group MFT-MGD-SVRS or MFT-MGD-SVRS-ONLY.
    5. ESS is targeted to a server by targeting the user extensible server group ESS-MGD-SVRS. .
  •  BAM sometimes is used outside of SOA Suite and in this case it is typically in a separate domain from SOA Suite. However BAM should be in a separate cluster in the same domain as SOA Suite if it is primarily used with that SOA Suite instance. In BAM 12c, integration between SOA Suite and BAM is a tight integration and is best done in the same domain. BAM and SOA Suite should not be co-located in the same cluster because BAM uses Automatic Service Migration for HA while SOA Suite uses Whole Server Migration.
  • OWSM Policy Manager must be deployed to only one cluster in a domain. However SOA Suite, OSB, BAM and MFT templates target OWSM PM by default to their own clusters.
    1.  In a domain with such different clusters, put OWSM PM in its own cluster like the EDG suggests. You can target the JRF and the two OWSM PM related user extensible server groups to this cluster.
    2. OWSM PM is automatically targeted to the SOA cluster when you target the user extensible server group SOA-MGD-SVRS which is the default. However if OWSM PM  is already targeted to a separate cluster then you should target SOA Suite to the SOA cluster by targeting the user extensible server group SOA-MGD-SVRS-ONLY.
    3. OWSM PM is automatically targeted to the BAM cluster when you target the user extensible server group BAM12-MGD-SVRS which is the default. However if OWSM PM  is already targeted to a separate cluster then you should target BAM to the BAM cluster by targeting the user extensible server group BAM12-MGD-SVRS-ONLY.
    4. OWSM PM is automatically targeted to the Service Bus cluster when you target the user extensible server group OSB-MGD-SVRS-COMBINED which is the default. However if OWSM PM  is already targeted to a separate cluster then you should target Service Bus to the Service Bus cluster by targeting the user extensible server group OSB-MGD-SVRS-ONLY.
    5. OWSM PM is automatically targeted to the MFT cluster when you target the user extensible server group MFT-MGD-SVRS which is the default. However if OWSM PM  is already targeted to a separate cluster then you should target MFT to the MFT cluster by targeting the user extensible server group MFT-MGD-SVRS-ONLY.
    6. ESS requires that OWSM PM be present somewhere in the domain but itself does not target OWSM PM.
  • Follow the following guidelines for ESS targeting.
    1. In a domain with Service Bus only ESS is typically targeted to the Service Bus cluster.
    2. In a domain with SOA Suite only, ESS is typically targeted to the SOA Suite cluster.
    3. However in a domain with both SOA Suite and Service Bus in different clusters, the best practice is to target ESS to its own cluster.
    4. MFT always has a private copy of ESS deployed to its cluster independent of any additional deployment of ESS for use by SOA Suite and Service Bus.
    5. ESS currently is positioned not as a standalone scheduler, but a scheduler for SOA Suite and Service Bus and should be in the same domain.
  • MFT is typically in a separate domain from SOA Suite or Service Bus, but could be in the same domain but in a separate cluster.
  • The best practice is to use separate domains for Healthcare and B2B and separate domains for SOA Suite and B2B. This is documented in the B2B and Healthcare documentation.

JDeveloper Tips & Tricks

iAdvise blog

In the different projects I’ve worked on the past few years, I’ve always worked in an Oracle-Java environment. This means I’ve always used an Oracle Database, mostly JDeveloper as my IDE environment and deploying to an OC4J instance or an Oracle IAS instance.

During these projects different issues arose regarding business requirements we needed to implement using JSF/ADF or deployment-issues when porting a 9i application to 10g environment, …

I’ve tried to keep my own cookbook regarding these different issues we’ve faced and how we resolved them.

In this post you will find different challenges we’ve addressed regarding working in an Oracle-Java environment. Please feel free to comment and add challenges/issues to the list !


You want to open up documents in a new screen, such as pdf-documents or word-documents
Use ‘targetFrame=_blank’ for a goLink to open the link in a new window

Refresh a table-component when a dropdown-component is…

View original post 1,169 more words

Weblogic JMX – Creating Instances of MBeans in Java

I am working on something similar, and the solution that @Rich gave worked for me. However, I have ended up with a slightly different approach that doesn’t require using the weblogic.management.jmx.MBeanServerInvocationHandler (directly at least).

Here is some code that should do what you are looking for:

package scratch;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Hashtable;

import javax.management.JMX;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;

import weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean;

import com.bea.wli.sb.management.configuration.ALSBConfigurationMBean;
import com.bea.wli.sb.management.configuration.SessionManagementMBean;

public class TestOSB_JMX {

    public static void main(String[] args) throws Throwable {

        // Provide connection information for OSB WebLogic AdminServer on command line
        String host = args[0];
        int    port = Integer.parseInt(args[1]);
        String user = args[2];
        String password = args[3];

        JMXConnector conn = initJmxConnection(host, port, user, password);
        try {
            System.out.println("Opened JMX connection to " + host + ":" + port + " as " + user);

            // get mbean connection
            MBeanServerConnection mbconn = conn.getMBeanServerConnection();

            // Get SessionmanagementMBean
            SessionManagementMBean sm = 
                JMX.newMBeanProxy(mbconn, ObjectName.getInstance(SessionManagementMBean.OBJECT_NAME), SessionManagementMBean.class);

            // Create a session
            String sessionName = "MySession";           
            sm.createSession(sessionName);

            // Get the configuration MBean for the session, do stuff, and then discard the session.
            try
            {
                System.out.println("Session exists? : " + sm.sessionExists(sessionName));

                ALSBConfigurationMBean configMBean = 
                    JMX.newMBeanProxy(
                        mbconn, 
                        ObjectName.getInstance("com.bea:Name=" +ALSBConfigurationMBean.NAME + "." + sessionName +",Type=" + ALSBConfigurationMBean.TYPE), 
                        ALSBConfigurationMBean.class
                    );

                System.out.println("Got the config MBean for session: " + configMBean.getSession());

                // Do stuff in the session here....
            }
            finally
            {
                // use activateSession to commit session changes instead
                sm.discardSession(sessionName);
            }
        } finally {
            conn.close();
            System.out.println("Closed JMX connection");
        }
    }

    public static JMXConnector initJmxConnection(String hostname, int port,String username, String password) 
    throws IOException, MalformedURLException 
    {
        JMXServiceURL serviceURL = new JMXServiceURL("t3", hostname, port, "/jndi/" + DomainRuntimeServiceMBean.MBEANSERVER_JNDI_NAME);

        Hashtable<String, String> h = new Hashtable<String, String>();
        h.put(Context.SECURITY_PRINCIPAL, username);
        h.put(Context.SECURITY_CREDENTIALS, password);
        h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");

        return JMXConnectorFactory.connect(serviceURL, h);
    }
}

Here are some things to note about my solution:

  1. My classpath directly references the following WebLogic and OSB JAR files: alsb.jar, osb-server-modules-ref.jar, wlfullclient.jar
  2. These JARs will reference (many) other JARs through the Class-Path entries in the Manifest files.
  3. You may need to generate the wlfullclient.jar file as described here: http://docs.oracle.com/cd/E17904_01/web.1111/e13717/jarbuilder.htm
  4. It is better to use wlfullclient.jar instead of weblogic.jar for this type of client application. I was using weblogic.jar first and it caused many class loading headaches for me.
  5. I am using Oracle Service Bus Version: 11.1.1.4 WebLogic version: 10.3.4, and Java 1.6.0_29.