Monday, June 28, 2010

32-bit bitwise XOR negation value. Chinese vendor MML generate checksum in Java

Crack my head trying to make the Java equivalent of the MML checksum computation. Specification says 32-bit bitwise XOR negation value. Here's to guessing somebody might find this useful. You can just easily put this inside a method. The meat of the checksum processing is here.

int[] checksumInt = new int[4];
byte[] checksumByte = new byte[4];

StringBuffer sbuf = null;
byte[] bytesToHash = {'H','B','H','B'}; //Can be a string, just call getBytes()

//process bytesToHash in chunks of 4 bytes

for(int offset=0;offset<
bytesToHash.length;offset+=4){
checksumInt[0]^=bytesToHash[offset+0];
checksumInt[1]^=bytesToHash[offset+1];
checksumInt[2]^=bytesToHash[offset+2];
checksumInt[3]^=bytesToHash[offset+3];
}

checksumInt[0]=~checksumInt[0];
checksumInt[1]=~checksumInt[1];
checksumInt[2]=~checksumInt[2];
checksumInt[3]=~checksumInt[3];


checksumByte[0]=(byte)(checksumInt[0]&0xFF);
checksumByte[1]=(byte)(checksumInt[1]&0xFF);
checksumByte[2]=(byte)(checksumInt[2]&0xFF);
checksumByte[3]=(byte)(checksumInt[3]&0xFF);

sbuf=new StringBuffer();
for(int i=0;i<checksumByte.length;i++
sbuf.append(String.format("%X",checksumByte[i]));
}

System.out.println("The checksum: "+sbuf.toString());


An alternative way is also posted in http://forums.sun.com/thread.jspa?threadID=5354842 . Both the above and this link gave the same checksum value when given the same inputs to process.

Yet another way in .NET http://www.pcreview.co.uk/forums/thread-3652613.php

Monday, June 7, 2010

Exception in thread "main" java.lang.NoClassDefFoundError: org/jaxen/JaxenException

Faced trouble with this exception while trying to do org.dom4j.Document.selectNodes() on a XML. Turns out you just need to include jaxen.jar in the referenced libraries of your Java app because dom4j.jar has a dependency on it. It's a Runtime exception so it's a little bit frustrating to trace.

Thursday, December 17, 2009

BAD_SCAN_ENUM perl string to flist function

The following input flist results in an error when using the pcmif::pin_perl_str_to_flist() function. The error was BAD_SCAN_ENUM:

my $in_flist = qq{
0 PIN_FLD_POID POID [0] 0.0.0.1 /search -1 0
0 PIN_FLD_FLAGS INT [0] 256
0 PIN_FLD_TEMPLATE STR [0] "select X from /purchased_product where F1 = V1 "
0 PIN_FLD_ARGS ARRAY [1] allocated 20, used 1
1 PIN_FLD_ACCOUNT_OBJ POID [0] ${account_poid}
0 PIN_FLD_RESULTS ARRAY [*]
1 PIN_FLD_POID POID [0] NULL
1 PIN_FLD_PRODUCT_OBJ POID [0] NULL
1 PIN_FLD_SERVICE_OBJ POID [0] NULL
1 PIN_FLD_QUANTITY DECIMAL [0] NULL
1 PIN_FLD_STATUS ENUM [0] NULL
1 PIN_FLD_STATUS_FLAGS INT [0] NULL
};


This gave me headaches until I realized the error. The correct flist is given below:

my $in_flist = qq{
0 PIN_FLD_POID POID [0] 0.0.0.1 /search -1 0
0 PIN_FLD_FLAGS INT [0] 256
0 PIN_FLD_TEMPLATE STR [0] "select X from /purchased_product where F1 = V1 "
0 PIN_FLD_ARGS ARRAY [1] allocated 20, used 1
1 PIN_FLD_ACCOUNT_OBJ POID [0] ${account_poid}
0 PIN_FLD_RESULTS ARRAY [*]
1 PIN_FLD_POID POID [0] NULL
1 PIN_FLD_PRODUCT_OBJ POID [0] NULL
1 PIN_FLD_SERVICE_OBJ POID [0] NULL
1 PIN_FLD_QUANTITY DECIMAL [0] 0
1 PIN_FLD_STATUS ENUM [0] 0
1 PIN_FLD_STATUS_FLAGS INT [0] 0
};

Sunday, November 22, 2009

Convert string to all caps in C

/*Sample code to convert to ALL CAPS a given string. */

#include
<stdio.h>
#include<string.h>

main()
{

int len =0;
int i =0;

char *str="quick BroWn Fox juMP ovEr the HeAd";
char *up_str;

len=strlen(str);
/*strlen does not include '\0' in the count so we allocate space for it*/
up_str=malloc((len+1)*sizeof(char));

printf("\nThis is the sample string: %s\n", str);
printf("\nThe length: %d",len);

for(i=0;i<=len;i++){ *(up_str+i)= toupper(*(str+i));
/* In C, *(array+1) == array[1] */
if(i==len){
*(up_str+i)='\0';
}
}

printf("\nThe upper string: %s\n", up_str);
free(up_str);
system("PAUSE");
}

Search between two tables

With an account POID, search for the product name of its products.

The sql template to use here would be:

"select X from /product 1, /purchased_product 2 where ( 2.F1 = V1 and 1.F2 = 2.F3 ) "

where F1 = PIN_FLD_ACCOUNT_OBJ
F2 = PIN_FLD_POID
F3 = PIN_FLD_PRODUCT_OBJ
V1 = account POID

The search flist looks like this:

0 PIN_FLD_POID POID [0] 0.0.0.1 /search 0 0
0 PIN_FLD_TEMPLATE STR [0] "select X from /product 1, /purchased_product 2 where ( 2.F1 = V1 and 1.F2 = 2.F3 ) "
0 PIN_FLD_FLAGS INT [0] 256
0 PIN_FLD_ARGS ARRAY [1] allocated 20, used 1
1 PIN_FLD_ACCOUNT_OBJ POID [0] 0.0.0.1 /account 20454
0 PIN_FLD_ARGS ARRAY [2] allocated 20, used 1
1 PIN_FLD_POID POID [0] NULL poid pointer
0 PIN_FLD_ARGS ARRAY [3] allocated 20, used 1
1 PIN_FLD_PRODUCT_OBJ POID [0] NULL poid pointer
0 PIN_FLD_RESULTS ARRAY [0] allocated 20, used 1
1 PIN_FLD_NAME STR [0] ""

Thursday, January 8, 2009

Check BRM patch version

To check the latest patch installed on Oracle BRM:

Infranet: Type 'pinrev' or check pinrev.dat
Pipeline: Check 'version.info.txt' in $IFW_HOME

To be sure that these files are current, the patches must be installed using the installer. These files might not get properly updated if, for example, instead of running the installer, you extract the new files from the tar file and then just plunk them in their respective directories.

Migrating IPL files


The following are common causes of IPL files throwing errors when committing them in production after taking them from a test/integration environment:
  • The resources and GL/IDs used by products and discount rules in the IPL file does not exist in production.
  • The discounts mentioned in the deals are not included in the IPL file to be committed.
  • The service used by the products in the IPL does not exist in production.