How to check null value from Java Method of Tibco ActiveMatrix - xpath

I am having a trouble on checking null value from a Java Method component in Tibco ActiveMatrix process.
Basically, I have a Java Method component invoking java to get a billing account, if the return is null, I would like to log the searching criteria - billing account id; otherwise, I will map the object to be XML content...
The problem is while using the following in 'XPath' to check the null object in a transition (Success with condition):
empty($Get-BA-Details/ns5:JavaMethodActivityOutput/MethodReturnValue
count($Get-BA-Details/ns5:JavaMethodActivityOutput/MethodReturnValue)= 0
string-length($Get-BA-Details/ns5:JavaMethodActivityOutput/MethodReturnValue) = 0
'$Get-BA-Details' is the Java Method component.
they all return 'false', and then try to map the java object to be XML content, which results in error while billing account is not found.
Could anyone shed some lights?
Thanks a lot!

Try this:
$Get-BA-Details/ns5:JavaMethodActivityOutput/MethodReturnValue=""

From what I can tell you cannot check if the return from a Java Method activity is null using XPath. Instead you can create a Java Code activity that takes an ObjectReference as an input parameters and provides a boolean as an output parameter. You can then use code like to following to check if the object is null (object is the input parameter and isnull is the output parameter):
isnull = object == null;
I have created BWUnit tests in the for this in the latest snapshot of BWUnit, which you can download from http://windyroad.org/software/bwunit/download/BWUnit-11.2.zip
The tests are located at StackOverflow/UnitTestSuite/JavaMethodNullTestCase in the simple example, which is found in Examples/Simple within the download.

Related

JMeter If Controller

not too sure if this is a user error but I can't seem to get this working. I have a test that returns 200 and this always hits the If controller, but the following fails.
I get a productID, if this is nested then i get the first one.
Regex is
prodID
"ProductId":(.*?),
$1$
0
Then as I want to use this in another thread group I cjhange to a property:
${__setProperty(prodID-${__threadNum},${prodID},)}
Then i use If Controller as
${__P(prodID-${__threadNum})} == "18"
Then it runs the same regex, but this time with $2$
Problem is that the If Controller isn't getting run on any, is there a way I can see this, or even is the above correct?
Thanks
The If Controller run its children if the expression evaluates to true
You're giving 18 == "18", it is not equal to true therefore the children are not getting executed.
I would suggest using __groovy() function instead like:
${__groovy(props.get('prodID-' + ctx.getThreadNum()).equals('18'),)}
where
props is a shorthand for Properties class instance holding JMeter Properties
ctx is a shorthand for JMeterContext class instance
See Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information on this and other JMeter API shorthands

How to unit test asp.net api if using Application

In my globals.asax.cs, I am creating a dictionary object that I want to use in my APIs to add and get data from in the life of the application.
I do the following:
Application["MyDictionary"] = myDictionary;
In my ApiController I get a handle of it, in this way:
MyDictionary myDictionary= (MyDictionary)HttpContext.Current.Application["MyDictionary"];
So far so good, the issue is that I need to do the same in the unit test, I need to add this dictionary into my Application as well, so when I call my controller, I will be able to retrieve it, how do I do that ?
doing this:
HttpContext.Current.Application.Add("MyDictionary", myDictionary);
enter code here
doesn't work, I get an exception:
An exception of type 'System.NullReferenceException' occurred in RESTServices.Tests.dll but was not handled in user code
My HttpContext.Current is null.
Any ideas how to work around this ?
The HttpContext.Current is created when a request is received, so you need to set the Current property, before using it.
See the example below:
var myDictionary = new Dictionary<string, string>();
HttpContext.Current = new HttpContext(new HttpRequest("default.aspx", "http://localhost", string.Empty), new HttpResponse(new StringWriter(CultureInfo.InvariantCulture)));
HttpContext.Current.Application.Add("MyDictionary", myDictionary);

ConstraintViolationException - extract field name which caused exception

I'm using hibernate-validator with a JAX-RS service to validate query parameters using #NotNull:
#GET
public Response doSomething(#NotNull #QueryParam("myParam") String myParam) {...}
This works as expected and throws a ConstraintViolationException if myParam is null. I'd like to extract the param name which is associated to the violation (e.g. myParam), and return that in the response message to the client but there does not appear to be an obvious way of extracting this from the exception. Can someone provide some insight?
As of BeanValidation 1.1 there is a ParameterNameProvider contract which makes parameter name extraction configurable. As mentioned in the other answer, with Java 8 you can get the parameter names in the byte code provided you compile with the -parameters flag. Use the ReflectionParameterNameProvider in this case. However, even with Java 7 you can get parameter names, for example by using the ParanamerParameterNameProvider. This parameter name provider is based on Paranamer and there are several ways to set it up.
This only works if you're using Java 8, as prior to Java 8 the actual parameter name was lost at compile time. Its now retained, assuming you compile and run at Java 8. See also http://docs.jboss.org/hibernate/validator/5.2/reference/en-US/html_single/#_java_8_support

BIRT Reporting: how to access LinkedHashMap in script

While creating BIRT Report, I'm trying to access a LinkedHashMap in report beforeFactory event thro' rhino scripting..Able to print the map. But, when i use any method like size(), the following error is thrown
size not found
var test1 = reportVO.getTest(); // "test" is a LinkedHashMap
log(test1) // --> In the logs, im able to see the LinkedHashMap contents printed
(log test1.size()) // --> this fails.
I have imported the util package.
I read about org.eclipse.birt.core.script.NativeJavaLinkedHashMap. I tried accessing the LinkedHashMap thro' methods of this class also, like
test1.getIds() // Method from NativeJavaLinkedHashMap --> this fails too
getIds not found
Is there a specific way to access LinkedhashMap in script.
Thanks,
Vishnupriya
Did you used test1.length ? you are now accessing javascript variable instead of java variable
For More Click Here

Cast IPrincipal to IClaimsPrincipal returning null

I have inherited come code (an MVC web app) and am having trouble getting it to start.
These two lines exist:
var claimsPrincipal = principal as IClaimsPrincipal;
if (claimsPrincipal == null)
throw new ArgumentException("Cannot convert principal to IClaimsPrincipal.", "principal");
principal is an IPrincipal (in this case a System.Security.Principal.WindowsPrincipal), and is not null.
The first line sets claimsPrincipal to null, so the exception is thrown. I'm assuming it must have worked for someone at some point, and this is a fresh copy from source control. Why would this cast return null for me?
I see that this post is a long time ago. But I encountered the same problem today, and finally I get the way to resolve it.
In framework 4.5 or 4.6, you can directly cast System.Security.Principal.WindowsPrincipal into IClaimsPrincipal, because the first one implements the second one. But in framework 3.5 or 4.0, you cannot do this, becasue the first one doesn't implement the second one.It just implements IPrinciple, not IClaimsPrincipal. You can see it from MSDN link here.
Here it a way to resovle this and get the IClaimsPrincipal object.
var t = HttpContext.Current.User.Identity as WindowsIdentity;
WindowsClaimsPrincipal wcp = new WindowsClaimsPrincipal(t);
IClaimsPrincipal p = wcp as IClaimsPrincipal;
HttpContext.Current.User is a WindowsPrincipal, and finally you can get IClaimPrincipal.
principal might in fact be null. Did you debug that?
Check to see if the type of principal implements the IClaimsPrincipal interface.

Resources