Monday, 24 May 2010

ADF and WLS JNDI configuration errors

Another blog under the theme "let's document it so we don't get caught out again", which can also be tagged as "let's document it so others don't get caught out too".

In our Oracle JDeveloper 11g ADF applications at runtime, on occasion we encountered one of the following errors when running our applications under Oracle's WebLogic Server 10.3.2. I've included the beginning stack trace to assist Google searches into this page:

<Utils><buildFacesMessage> ADF: Adding the following JSF error message: JNDI failure. Unable to lookup Data Source at context jdbc/SomeJndi
oracle.jbo.DMLException: JBO-27200: JNDI failure. Unable to lookup Data Source at context jdbc/SomeJndi
at oracle.jbo.server.DBTransactionImpl.lookupDataSource(DBTransactionImpl.java:1414)
at oracle.jbo.server.DBTransactionImpl2.connectToDataSource(DBTransactionImpl2.java:309)
at oracle.jbo.common.ampool.DefaultConnectionStrategy.connect(DefaultConnectionStrategy.java:203)
at oracle.jbo.server.ApplicationPoolMessageHandler.doPoolConnect(ApplicationPoolMessageHandler.java:553)
at oracle.jbo.server.ApplicationPoolMessageHandler.doPoolMessage(ApplicationPoolMessageHandler.java:409)
at oracle.jbo.server.ApplicationModuleImpl.doPoolMessage(ApplicationModuleImpl.java:8534)
at oracle.jbo.common.ampool.ApplicationPoolImpl.sendPoolMessage(ApplicationPoolImpl.java:4392)
at oracle.jbo.common.ampool.ApplicationPoolImpl.prepareApplicationModule(ApplicationPoolImpl.java:2388)
at oracle.jbo.common.ampool.ApplicationPoolImpl.doCheckout(ApplicationPoolImpl.java:2204)
at oracle.jbo.common.ampool.ApplicationPoolImpl.useApplicationModule(ApplicationPoolImpl.java:3088)
at oracle.jbo.common.ampool.SessionCookieImpl.useApplicationModule(SessionCookieImpl.java:460)
at oracle.jbo.http.HttpSessionCookieImpl.useApplicationModule(HttpSessionCookieImpl.java:234)
at oracle.jbo.common.ampool.SessionCookieImpl.useApplicationModule(SessionCookieImpl.java:431)
at oracle.jbo.common.ampool.SessionCookieImpl.useApplicationModule(SessionCookieImpl.java:426)
at oracle.adf.model.bc4j.DCJboDataControl.initializeApplicationModule(DCJboDataControl.java:513)
at oracle.adf.model.bc4j.DCJboDataControl.getApplicationModule(DCJboDataControl.java:856)
..or..
Caused by: javax.naming.NameNotFoundException: Unable to resolve 'jdbc.SomeJndi'. Resolved 'jdbc'; remaining name 'SomeJndi'
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1139)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:252)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:182)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:206)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:214)
at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:393)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
..or..
<Utils><buildFacesMessage> ADF: Adding the following JSF error message: Unable to resolve 'jdbc.SomeJndi'. Resolved 'jdbc'
javax.naming.NameNotFoundException: Unable to resolve 'jdbc.SomeJndi'. Resolved 'jdbc'; remaining name 'SomeJndi'
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1139)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:252)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:182)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:206)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:214)
at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:393)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
All of these errors occur because of a misconfiguration of a JNDI in one or more of the following locations:

1) the datasource within your WebLogic Server
2) an Application Module's JDBC Data Source within your main ADF application
3) an Application Module's JDBC Data Source within a Bounded Task Flow added to your application via an ADF Library
4) an Application Module's property jbo.server.internal_connection within your main application
5) an Application Module's property jbo.server.internal_connection within a Bounded Task Flow added to your application via an ADF Library

As readers know the JNDI typically takes the form "jdbc/SomeJndi".

Essentially the JNDI for the data source in #1 must be consistent with #2 and #3 otherwise the JNDI lookup fails. In addition if you make use of the jbo.server.internal_connection Application Module property, you'll require a second datasource for #1 that is consistent with that specified in #4 and #5.

This may seem simple, but during a recent development we suffered repeated mistakes where the JNDI was misconfigured causing us large amounts of grief when we thought we had it "sorted". Take the following error message, see if you can spot the issue:

Caused by: javax.naming.NameNotFoundException: Unable to resolve 'jdbc.SomeJndi '. Resolved 'jdbc'; remaining name 'SomeJndi '

Somewhat oddly this error message converts the JNDI such that the forward slashes are replaced with a fullstop. However that's a red herring. Can you see the real error?

If you've looked closely you'll note the JNDI name has an additional space character at the end, something very difficult to visually detect. This resulted in the error above.

For us this particular misconfiguration happened in the worst of places too. Rather than a JNDI used by our main ADF application which would have fallen over straight away, it was used by a secondary ADF Library Bounded Task Flow Application Module's jbo.server.internal_connection setting. As such the application when running under no stress would work fine, but only when the specific Bounded Task Flow was called, and only when the specific Bounded Task Flow was under stress and needed to passivate to the ps_txn table did we see ADF throw the above errors. Before we realized what was going on, a large flapping red herring was that the application would occasionally throw:
JBO-28030: Could not insert row into table PS_TXN, collection id 24,026, persistent id 1" followed by "JBO-27200: JNDI failure. Unable to lookup Data Source at context jdbc/SomeJndi "
...followed by one of the JNDI connections above. But we could see that records were inserted into the ps_txn table regardless of the previous error, and via our own testing, logging into the associated database account specified for the jbo.server.internal_connection, the db user had all the correct database privileges for working with the ps_txn table. Eventually we tracked it back to the misconfigured JNDI, such that the main application with the correct JNDI was happily inserting into PS_TXN, but the secondary Bounded Task Flow JNDI was intermittently causing this issue.

Lesson learned. Don't get your JNDIs wrong.

Thursday, 6 May 2010

Configuring Apache JMeter for Apex

A couple weeks ago I blogged how to configure Apache JMeter for testing Oracle's ADF. This week to complete the set, I'll post my findings on stress testing Oracle's Application Express (Apex) with JMeter . Both posts are related to an earlier post on how to record sessions in JMeter that are essential reading to understand what I've specified here.

A Small Caveat

Please note this particular post is the result of my rather limited testing of JMeter with Apex. I'm not an Apex expert, and I haven't used it for over 2 years in any development project. The implication for this post is I might not have discovered absolutely everything that needs to be done to set up JMeter for stress testing Apex in every considerably use case.

If you discover a problem, and hopefully a fix, to assist other readers it would be great if you could post your comments to this blog to assist those next readers please.

Yet Another Small Caveat

For those who read my ADF post, you'll find much of the text in this post similar. I'm mindful I have readers leaping into this post from Google without having read anything earlier, so I'm guessing it's important I give them the same spool. Apologies for repeating myself.

Not a Caveat, But My Thanks

I need to express my thanks to both Penny Cookson and Patrick Wolf with their assistance in getting this post together. Both obviously have a huge amount of experience with Apex and their thoughts and guidance were appreciated.

Introduction

When considering using JMeter for Oracle Application Express applications there are additional JMeter configuration steps required beyond that detailed in the original post. Apex similar to most web applications uses Cookies, and you can use JMeter's HTTP Cookie Manager to correctly handle the cookie. However Apex also makes use of a number of parameters passed as HTTP POST parameters and URL parameters. On running an Apex application you'll often see URL parameters including the session ID, and embedded within the HTTP bodies variables such as p_instance, p_vt01, p_arg_names and more, used by Apex to coordinate state with the browser session. In order for JMeter to simulate multiple user sessions it needs to be correctly configured to handle these too, capturing and carrying the unique values for each session in the load test.

The following post lists the additional configurations required for JMeter beyond those described in the original post. As noted in the original post the easiest way to setup your JMeter Test Plan is to record an existing Apex session through JMeter's HTTP Proxy Server and I haven't bothered to reiterate those instructions here. In turn I've taken no effort to explain the JMeter features we're utilizing to do this; if you want to learn about the relevant JMeter features consult the JMeter User Manual.

These instructions were created against the Apex version 3.2.1.00.10 included with the latest 11gR2 Oracle database release on Windows. Presumably in the future, possibly Apex v4, it will change its HTTP mechanisms, resulting in you having to carefully check this post's instructions against the future Apex version.

JMeter Apex Required Configurations

The following lists the additional objects and their settings required within JMeter. You need only create one of each for each Thread Group but I'll agree there does seem to be a lot of them. The end result will look something like this:


a) HTTP Cookie Manager

Create via Test Plan -> Thread Group -> Right Click -> Add -> Config Element -> HTTP Cookie Manager

Name:HTTP Cookie Manager
Clear cookies each iteration:Selected

In my original JMeter post, you'll see in the comments from Manolis Nikiforakis, he suggests the Cookie policy should be set to "compatible". In my own testing that didn't seem to work, so I used rfc2965 instead. See what works for you.

b) User Defined Variables

Create via Test Plan -> Thread Group -> Right Click -> Add -> Config Element -> User Defined Variables


Name:User Defined Variables Variables
Variable Name:sessionId
Variable Name:p_flow_id
Variable Name:p_flow_step_id
Variable Name:p_instance
Variable Name:p_page_submission_id
Variable Name:p_request
Variable Name:p_md5_checksum
Variable Name:p_arg_values
Variable Name:p_arg_names01...XXX
Variable Name:p_arg_names01name...XXX
Variable Name:p_arg_names01value
Variable Name:success_msg

Above where you see p_arg_names01...XXX and p_arg_names01name...XXX, what I'm implying here is you need to define as many as these as there are submittable fields on your Apex web pages. In the picture you can see I've defined a set of 10. How many do you need to create, well, you need to carefully look at the session requests you've recorded in JDev and identify the maximum number of fields like p_v01, p_t02 etc. If you're not familiar with what I'm describing here, read on and hopefully it'll become more apparent.

c) sessionId Regular Expression Extractor

Create via Test Plan -> Thread Group -> Right Click -> Add -> Post Processors -> Regular Expression Extractor


Name:sessionId Regular Expression Extractor
Response Field to Check:Body
Reference Name:sessionId
Regular Expression:f?p=([0-9]{1,3}):([0-9]{1,3}):([0-9]{16}):
Template:$3$
Match No.:1
Default Value:n/a

d) p_flow_id Regular Expression Extractor

Create via Test Plan -> Thread Group -> Right Click -> Add -> Post Processors -> Regular Expression Extractor


Name:p_flow_id Regular Expression Extractor
Response Field to Check:Body
Reference Name:p_flow_id
Regular Expression:<input type="hidden" name="p_flow_id" value="(.+?)" id="pFlowId" />
Template:$1$
Match No.:1
Default Value:n/a

e) p_flow_step_id Regular Expression Extractor

Create via Test Plan -> Thread Group -> Right Click -> Add -> Post Processors -> Regular Expression Extractor


Name:p_flow_step_id Regular Expression Extractor
Response Field to Check:Body
Reference Name:p_flow_step_id
Regular Expression:<input type="hidden" name="p_flow_step_id" value="(.+?)" id="pFlowStepId" />
Template:$1$
Match No.:1
Default Value:n/a

f) p_instance Regular Expression Extractor

Create via Test Plan -> Thread Group -> Right Click -> Add -> Post Processors -> Regular Expression Extractor


Name:p_instance Regular Expression Extractor
Response Field to Check:Body
Reference Name:p_instance
Regular Expression:<input type="hidden" name="p_instance" value="(.+?)" id="pInstance" />
Template:$1$
Match No.:1
Default Value:n/a

g) p_page_submission_id Regular Expression Extractor

Create via Test Plan -> Thread Group -> Right Click -> Add -> Post Processors -> Regular Expression Extractor


Name:p_page_submission_id Regular Expression Extractor
Response Field to Check:Body
Reference Name:p_page_submission_id
Regular Expression:<input type="hidden" name="p_page_submission_id" value="(.+?)" id="pPageSubmissionId" />
Template:$1$
Match No.:1
Default Value:n/a

h) p_request Regular Expression Extractor

Create via Test Plan -> Thread Group -> Right Click -> Add -> Post Processors -> Regular Expression Extractor


Name:p_request Regular Expression Extractor
Response Field to Check:Body
Reference Name:p_request
Regular Expression:<input type="hidden" name="p_request" value="(.+?)" id="pRequest" />
Template:$1$
Match No.:1
Default Value:n/a

It's possible this extractor isn't needed, see why in the following descriptions. However I've included it for completeness.

i) p_md5_checksum Regular Expression Extractor

Create via Test Plan -> Thread Group -> Right Click -> Add -> Post Processors -> Regular Expression Extractor


Name: p_md5_checksum Regular Expression Extractor
Response Field to Check:Body
Reference Name: p_md5_checksum
Regular Expression:<input type="hidden" name="p_md5_checksum" value="(.+?)" />
Template:$1$
Match No.:1
Default Value:n/a

It's possible this isn't required. In my mini Apex application I never saw the checksum populated. Potentially it may be in yours so I've included it for completeness here.

j) p_arg_values Regular Expression Extractor

Create via Test Plan -> Thread Group -> Right Click -> Add -> Post Processors -> Regular Expression Extractor


Name: p_arg_values Regular Expression Extractor
Response Field to Check:Body
Reference Name: p_arg_values
Regular Expression:<input type="hidden" name="p_arg_values" value="(.+?)" />
Template:$1$
Match No.:1
Default Value:n/a

h) p_arg_names01..XX Regular Expression Extractor

Create via Test Plan -> Thread Group -> Right Click -> Add -> Post Processors -> Regular Expression Extractor


Name:p_arg_names01...XX Regular Expression Extractor
Response Field to Check:Body
Reference Name:p_arg_names01..XX
Regular Expression:<input type="hidden" name="p_arg_names" value="(.+?)" /><input type="(hidden|text)" name="(p_[tv]01)"
Template:$1$
Match No.:1
Default Value:n/a

As described in the User Variables section, you'll need as many as these as the maximum amount of fields you have in any of your Apex pages. In the above table the Name and Reference Name should not include ..XX, that's just a notation to mean you need to create many of them. Look to the picture to see exactly what you define for the first.

k) p_arg_names01name..XX Regular Expression Extractor

Create via Test Plan -> Thread Group -> Right Click -> Add -> Post Processors -> Regular Expression Extractor


Name:p_arg_names01...XX Regular Expression Extractor
Response Field to Check:Body
Reference Name:p_arg_names01name..XX
Regular Expression:<input type="hidden" name="p_arg_names" value="(.+?)" /><input type="(hidden|text)" name="(p_[tv]01)"
Template:$3$
Match No.:1
Default Value:n/a

Again as per the last extractor, you'll need as many as these as the maximum amount of fields you have in any of your Apex pages. In the above table the Name and Reference Name should not include ..XX, that's just a notation to mean you need to create many of them. Look to the picture to see exactly what you define for the first.

l) p_arg_names01value Regular Expression Extractor

Create via Test Plan -> Thread Group -> Right Click -> Add -> Post Processors -> Regular Expression Extractor


Name:p_arg_names01value Regular Expression Extractor
Response Field to Check:Body
Reference Name:p_arg_names01value
Regular Expression:<input type="hidden" name="p_arg_names" value="(.+?)" /><input type="(hidden|text)" name="(p_[tv]01)" value="(.+?)" id="P2_BOOKING_NO" />
Template:$4$
Match No.:1
Default Value:n/a

In your application if you have sequence number fields that are prepopulated from a database sequence number and hidden from the user, you need to include an extractor for each. In this example we're grabbing a hidden P2_BOOKING_NO field.

l) success_msg Regular Expression Extractor

Create via Test Plan -> Thread Group -> Right Click -> Add -> Post Processors -> Regular Expression Extractor


Name: success_msg Regular Expression Extractor
Response Field to Check:Body
Reference Name:success_msg
Regular Expression:success_msg=(Action%20Processed.%2F[A-F0-9]{32,33}%2F)
Template:$1$
Match No.:1
Default Value:n/a

It's possible in this extractor the length of the hex regular expression of 32-33 chars could be to limited.

Recorded HTTP Request Changes

After recording an Apex session in JMeter, and setting up the variables above, you'll note in the recorded HTTP Requests numerous references to the same named variables as HTTP parameters. Yet the recorded HTTP Requests include the parameters' values for the recorded session, which simply won't work when we replay the session as the values will have changed.

It is therefore necessary to identify all locations where the parameters exist in the recorded session HTTP Requests and substitute references to your variables.

a) HTTP Request – Parameters – sessionId

For any HTTP Request that has the parameter "p", where the value looks something like:

102:1: 1438937389458569:::::

The third value must be replaced with

102:1: ${sessionId}:::::


If you see a "p" value that looks something like this:

102:1::::::

...don't modify it.

b) HTTP request – Parameters – for any of the following parameters we need to change their values to the following expressions:

p_flow_id -> ${p_flow_id}
p_flow_step_id -> ${p_flow_step_id}
p_instance -> ${p_instance}
p_page_submission_id -> ${p_page_submission_id}
p_arg_names -> ${p_arg_names}
p_v01...p_vXX -> ${p_arg_names01..XX}
p_t01...p_vXX --> ${p_arg_names01..XX}

...as demonstrated in the following picture:


Then in addition for each p_v01..XX and p_t01..XX fields you'll need to replace the actual parameter names, such that:

p_v01..XX -> ${p_arg_names01name..XX}
p_t01..XX -> ${p_arg_names01name..XX}

...ditto for every parameter name, as demonstrated in the following picture:


You'll note we haven't bothered to do anything with the p_request and p_md5_checksum fields. I'm still not overly convinced we need to, so I've included them in the User Variables and Regular Expression Extractors, but haven't done any more with them at this stage.

c) HTTP request – Parameter – success_msg

For the success_msg parameter, replace its value with ${success_msg}, and ensure Encoding is turned off:


Assertions

Once you've completed the above setup and want to run your load test via JMeter, it is important to see that the test is working correctly. One way to do this is to create a View Results Tree (Test Plan -> Thread Group -> Right Click -> Add -> Listener -> View Results Tree) that allows you to inspect the response of each HTTP Request. If you then see HTTP Request responses in red this indicates a HTTP error code response (!= 200). However it's also necessary to inspect each response even if they are green to see if there's a valid response returned carrying an error message. There is definitely a small knack to differentiating between the different type of failures in an Apex application, which you'll become familiar with on some experience.

In order to save you having to look for the same problems for each test-run, you can create a Response Assertion (Test Plan -> Thread Group -> Add -> Assertions -> Response Assertion) to look for specific errors in the responses. To set this up:

Which Samples to Test:Main Sample Only
Response Field to Test:Text Response
Pattern Matching Rules:Contains
Not:Selected
Patterns to Test #1:The error string you're looking for

Sample JMeter file

Readers can download a sample JMeter JMX file for Apex here with the configurations already setup.

Finishing Comment

As I mentioned much earlier in this post, this post really constitutes my research to date in stress testing Apex with JMeter, and doesn't necessarily cover everything you need to do. Ultimately my goal, like other posts on this blog is to share the spark of inspiration such that you can take the ideas and run with them to form a complete solution yourself. Without a doubt because of the length of this post I'll have a typo or have missed something, so again follow up comments would be appreciated to help the next reader please.

Good luck.

Thursday, 22 April 2010

Configuring Apache JMeter specifically for Oracle's ADF 11g

Sometime back I blogged about Stress & load testing web applications (even ADF & Apex) using Apache JMeter. That post dealt with the generic setup of recording a web session and then replaying under load via JMeter.

When considering using JMeter for JDeveloper 11g ADF applications there are additional JMeter configuration steps required beyond that detailed in the original post. As per the original post ADF passes around cookies to store the JSESSIONID, and you can use JMeter's HTTP Cookie Manager to correctly handle the cookie. However ADF also makes use of a number of parameters passed as HTTP POST parameters and URL parameters. On running an ADF application you'll often see URL parameters like _adf.ctrl-state, _afrLoop, and embedded within the HTTP bodies variables such as javax.faces.ViewState, used by ADF to coordinate state with the browser session. In order for JMeter to simulate multiple user sessions it needs to be correctly configured to handle these too, capturing and carrying the unique values for each session in the load test.

The following post lists the additional configurations required for JMeter beyond those described in the original post. As noted in the original post the easiest way to setup your JMeter Test Plan is to record an existing ADF session through JMeter's HTTP Proxy Server and I haven't bothered to reiterate those instructions here. In turn I've taken no effort to explain the JMeter features we're utilizing to do this; if you want to learn about the relevant JMeter features consult the JMeter User Manual.

Caveat for ADF 10g users: You'll note above I specifically stated JDeveloper 11g ADF, not 10g. I haven't tested any of the following settings for JDev 10g and I don't believe they'll work, as if memory serves me correctly the POST and URL parameters mechanisms changed between versions. However the following notes may give you enough information to dig around in a running 10g ADF application, looking at the HTTP Requests to work out what parameters to work with.

JMeter ADF Required Configurations

The following lists 5 additional objects and their settings. You need only create one of each for each Thread Group. The end result will look something like this:


a) HTTP Cookie Manager

Create via Test Plan -> Thread Group -> Right Click -> Add -> Config Element -> HTTP Cookie Manager

Name:HTTP Cookie Manager
Clear cookies each iteration:Selected

b) User Defined Variables

Create via Test Plan -> Thread Group -> Right Click -> Add -> Config Element -> User Defined Variables

Name:ADF Variables
Variable Name:afrLoop
Variable Name:afrWindowId
Variable Name:jsessionId
Variable Name:adf.ctrl-state
Variable Name:javax.faces.ViewState

No initial values.
c) Regular Expression Extractor #1

Create via Test Plan -> Thread Group -> Right Click -> Add -> Post Processors -> Regular Expression Extractor

Name:adf.ctrl-state Extractor
Response Field to Check:Body
Reference Name:adf.ctrl-state
Regular Expression:_adf.ctrl-state=([-_0-9A-Za-z!]{10,13})
Template:$1$
Match No.:1
Default Value:n/a

Take notice that the variable name does not include an underscore in it's name unlike the actual parameter _adf.ctrl-state.

d) Regular Expression Extractor #2

Create via Test Plan -> Thread Group -> Right Click -> Add -> Post Processors -> Regular Expression Extractor

Name:afrLoop Extractor
Response Field to Check:Body
Reference Name:afrLoop
Regular Expression:_afrLoop=([-_0-9A-Za-z]{13,16})
Template:$1$
Match No.:1
Default Value:n/a

Take notice that the variable name does not include an underscore in it's name unlike the actual parameter _afrLoop.

d) Regular Expression Extractor #3

Create via Test Plan -> Thread Group -> Right Click -> Add -> Post Processors -> Regular Expression Extractor

Name:afrWindowId Extractor
Response Field to Check:Body
Reference Name:afrWindowId
Regular Expression:window.name='([-_0-9A-Za-z!]{10,13})'
Template:$1$
Match No.:1
Default Value:n/a

e) Regular Expression Extractor #4

Create via Test Plan -> Thread Group -> Right Click -> Add -> Post Processors -> Regular Expression Extractor

Name:javax.faces.ViewState Extractor
Response Field to Check:Body
Reference Name:javax.faces.ViewState
Regular Expression:<input type="hidden" name="javax\.faces\.ViewState" value="!(.+?)">
Template:$1$
Match No.:1
Default Value:n/a

f) Regular Expression Extractor #5

Create via Test Plan -> Thread Group -> Right Click -> Add -> Post Processors -> Regular Expression Extractor

Name:jsesssionId Extractor
Response Field to Check:Body
Reference Name:jsessionId
Regular Expression:;jsessionid=([-_0-9A-Za-z!]{63})
Template:$1$
Match No.:1
Default Value:n/a

Recorded HTTP Request Changes

After recording an ADF session in JMeter, and setting up the variables above, you'll note in the recorded HTTP Requests numerous references to the same named variables as HTTP parameters. Yet the recorded HTTP Requests include the parameters' values for the recorded session, which simply won't work when we replay the session as the values will have changed.

It is therefore necessary to identify all locations where the parameters exist in the recorded session HTTP Requests and substitute references to your variables.

a) HTTP Request – Path – any path that makes reference to jsessionId must be changed.

ie: /SageApp/faces/ViewEvents;jsessionId=${jsessionId}


b) HTTP Request – Path – ditto any path that makes reference to _adf.ctrl-state must be changed.

ie. /SageApp/faces/ViewEvents?_adf.ctrl-state=${adf.ctrl-state}


You can also change this in the name if you want but it wont make a different to the overall result, the name is for show only.

c) HTTP Request – Parameters – for any of the following parameters:

_adf.ctrl-state
_afrLoop
_afrWindowId (* see exception at the end of this step)

...for their values substitute the relevant variable. The following example shows the values for the afrLoop and adf.ctrl-state replaced:


However there is one exception with _afrWindowId. In one of the initial requests its value will be the literal string "null" (see the picture in step (a) for an example). Do not replace this, leave it as null.

d) HTTP Request – Parameters – for the "javax.faces.ViewState" parameter, ditto replace its values. Note it is necessary to put a not (negate) symbol in front of it:

ie. !${javax.faces.ViewState}

In addition by default the "Encode?" parameter will be on for each javax.faces.ViewState. Instead turn it off for each:


e) HTTP Request – Parameters – for the "unique" parameter, occurring in the Path and request parameters replace it with the following notation:

${__javaScript(new Date().getTime(),DUMMY)}

Note there is no JMeter user variable for this, we just write it straight into the unique value.

f) HTTP Header Manager Referer – if the HTTP session has been recorded via JMeter's HTTP Proxy, each HTTP Request will include a sub-element HTTP Header Manager that includes an element called Referer. You'll note it will have hardcoded many of the parameters discussed above. However I don't think ADF requires the Referer element and you can just ignore it or delete it from every HTTP Header Manager.

Assertions

Once you've completed the above setup and want to run your load test via JMeter, it is important to see that the test is working correctly. One way to do this is to create a View Results Tree (Test Plan -> Thread Group -> Right Click -> Add -> Listener -> View Results Tree) that allows you to inspect the response of each HTTP Request. If you then see HTTP Request responses in red this indicates a HTTP error code response (!= 200). However it's also necessary to inspect each response even if they are green to see if there's a valid response returned carrying an error message. There is definitely a small knack to differentiating between the different type of failures in an ADF application, which you'll become familiar with on some experience.

In order to save you having to look for the same problems for each test-run, you can create a Response Assertion (Test Plan -> Thread Group -> Add -> Assertions -> Response Assertion) to look for specific errors in the responses. From my own ADF experience you want to setup a Response Assertion with the following values:

Which Samples to Test:Main Sample Only
Response Field to Test:Text Response
Pattern Matching Rules:Contains
Not:Selected
Patterns to Test #1:The following exception occurred
Patterns to Test #2:Server Exception during PPR
Patterns to Test #3:ADFC-12000
Patterns to Test #4:java.net.SocketException
Patterns to Test #5:java.io.IOException

This isn't a definitive list, and in turn there may be specific errors that you may want to pick up for your application.

Sample JMeter file

Readers can download a sample JMeter JMX file for ADF here with the configurations already setup.

Finishing Comment

I haven't had the chance to test this in every ADF scenario or application. It's possible in your application, dependent on the components you're using or some other trick of ADF, that I've missed one of the state values it wants the browser to carry. With the post above hopefully you'll get an idea of the majority and be able to identify more. I'd appreciate it if anybody finds more that we need to cater for please post a comment with your findings to assist other readers.

Wednesday, 7 April 2010

ADF BC 11g Groovy expressions implicit type conversions

Under JDeveloper 11g ADF Business Components introduced the support for Groovy expressions. Among other benefits this allows JDeveloper programmers to skip many trivial Java programming tasks with a shorthand Groovy expression. Grant Ronald's Introduction to Groovy Support in JDeveloper and Oracle ADF 11g provides a good compliment to the Fusion Guide on Groovy expressions.

The Groovy support includes the ability to reference attributes of Entity Objects and View Objects. For instance you may create a transient attribute TotalCost in an InvoiceLines Entity Object based on the Groovy expression "Cost * Quantity" referencing the same named Entity Object attributes:


As you become more familiar with the use of Groovy expressions you'll realize you can also call the functions of the underlying attribute type. For instance a String attribute FullName would support the Groovy expression "FullName.toLowerCase()".

However there is a catch. When calling functions of a specific attribute, say calling the oracle.jbo.domain.Number add() function on the Quantity Number attribute, at runtime you might discover a runtime error such as:

(oracle.jbo.JboException) JBO-29000: Unexpected exception caught: groovy.lang.MissingMethodException, msg=No signature of method: java.lang.Long.add() is applicable for argument types: (java.lang.Integer) values: [1]

This comes as a surprise as the Fusion Guide tells us the Number attribute type is backed by the oracle.jbo.domain.Number class supplied by Oracle.

What's happening is that the Groovy expression evaluator is undertaking some implicit datatype conversions/casts on our behalf with the underlying attributes. In order to make this easier to understand I've documented the type conversions for you. The following table gives you the Type Name as selected in the EO/VO attribute editor, the Java Type you'll see in the resulting EntityImpl and ViewRowImpl classes, and then the Groovy Type they'll be cast to during a Groovy expression evaluation.

You'll note with the Groovy Types sometimes they are in fact the oracle.jbo.domain class, but in others they're the parent class. And for some types there is no oracle.jbo.domain equivalent, just a java.lang type. It's all a bit inconsistent but hopefully the table gives you the appropriate type for your attribute:

Type NameJava TypeGroovy Type
Arrayoracle.jbo.domain.Array-
BFileDomainoracle.jbo.domain.BFileDomain-
BigDecimaljava.math.BigDecimaljava.math.BigDecimal
BlobDomainoracle.jbo.domain.BlobDomainoracle.jbo.domain.BlobDomain
Booleanjava.lang.Booleanjava.lang.Boolean
Bytejava.lang.Bytejava.lang.Byte
Charoracle.jbo.domain.Charjava.lang.String
Characterjava.lang.Characterjava.lang.Character
ClobDomainoracle.jbo.domain.ClobDomainoracle.jbo.domain.ClobDomain
DBSequenceoracle.jbo.domain.DBSequencejava.lang.Long
Dateoracle.jbo.domain.Datejava.sql.Date
Doublejava.lang.Doublejava.lang.Double
Floatjava.lang.Floatjava.lang.Float
Integerjava.lang.Integerjava.lang.Integer
Longjava.lang.Longjava.lang.Long
NClobDomainoracle.jbo.domain.NClobDomainoracle.jbo.domain.NClobDomain
Numberoracle.jbo.domain.Numberjava.lang.Long
Objectjava.lang.Objectjava.lang.Object
OrdAudioDomainoracle.ord.im.OrdAudioDomainoracle.ord.im.OrdAudioDomain
OrdDocDomainoracle.ord.im.OrdDomainoracle.ord.im.OrdDomain
OrdImageDomainoracle.ord.im.OrdImageDomainoracle.ord.im.OrdImageDomain
OrdImageSignatureDomainoracle.ord.im.OrdImageSignatureDomainoracle.ord.im.OrdImageSignatureDomain
OrdVideoDomainoracle.ord.im.OrdVideoDomainoracle.ord.im.OrdVideoDomain
REForacle.sql.REF-
Raworacle.jbo.domain.Raw-
RowIDoracle.jbo.domain.RowIDjava.lang.String
Shortjava.lang.Shortjava.lang.Short
Stringjava.lang.Stringjava.lang.String
Timestamporacle.jbo.domain.Timestampjava.sql.Timestamp
TimestampLTZoracle.jbo.domain.TimestampLTZjava.sql.Timestamp
TimestampTZoracle.jbo.domain.TimestampTZjava.sql.Timestamp

You'll note I've missed a few Groovy Types, I simply couldn't determine the equivalent type.

This post was specifically written against JDeveloper 11g 11.1.1.2.0 build 5536. It's quite possibly in the future Oracle will tweak the data types to make it more consistent so be careful to check my facts.

Saturday, 27 March 2010

ADF BC 11g – Creating business rules for unique keys on actual database unique keys (rather than primary keys)

Phew, that's the best title I could think of for this post. Not the most inspiring I'd agree. Anyway, let's continue.

Users of JDeveloper 11g ADF Business Components will be familiar with the ability to create Declarative Validation Rules on an EO's underlying table's primary key, somewhat confusingly (as we will see) referred to as a "UniqueKey" validator, though it's based on a primary key. The main reason to create such a rule is to avoid the particularly unfriendly database constraint error that is thrown, to replace it with a more friendly error message defined in ADF BC.

This "UniqueKey" rule can easily be extended to actual schema unique keys through a little trick (as separate to a primary key) as we'll see in this post.

When an EO is created in your Model project based, the IDE takes the opportunity to capture all the constraints of the underlying table (or you can resync these at a later date by right clicking the EO in the App Navigator and choosing the Synchronize with Database option). To create a "UniqueKey" validator based on the primary key of the table you:

a) Open the EO editor
b) Select the Business Rules node
c) Then Entity Validators followed by the plus button

In the resulting Add Validation Rule dialog, selecting the Rule Type of "UniqueKey" gives you the option to pick the relating EO's primary key based on the same constraint from the database:


However you'll notice what it doesn't display is any actual unique keys (such as say a database constraint employees_uk that enforces the first_name and last_name must be unique within the employees table).

One solution to this is to define Alternate Keys in the EO via the EO editor's General page's same named option:


Once created the Alternate Key will then appear as a "UniqueKey" option in the Add Validation Rule dialog.

However there is an easier way.

If you select an EO in the Application Navigator, then open the Structure Window option, you get a list of parts of the EO including Constraints, which will include all the database constraints for the particular EO. As can be seen in the following picture, this includes not only the primary key, but also unique keys:

If you select the unique key constraint and then open the Property Inspector you'll see:


...including an option to create the unique key constraint as an Alternate Key (the default being false). Setting this to true means that when you create the validation rule for a "UniqueKey", you'll see the unique key constraint listed as well as the primary key:


This little trick saves us having to manually create Alternate Keys based on the columns in our unique keys, but rather reuse the unique key constraint definition to define the Alternate Keys for us.