Wednesday, April 23, 2014

Dependent Application 'isv' does not exist : Resolution

Normally we encounter a error which says "Dependent Application 'isv' does not exist" while installing the isvp. A screenshot is shown below


Reason : As far as I have understood whenever your project has any UDDI services this dependency will be added by default (may be a product bug) but this can be solved by following below steps

Resolution :

Step 1 : Locate the isvp which will be in "isvcontent" folder of <<InstanceOfCordys>>


Step 2 : Right click and open the archive (I am using 7z you can also use winrar to follow this step)


Step 3 : Once you open the archive, you would be seeing isv.xml file (this is where your concentration should be) drag and drop somewhere in your hard drive (I have copied the isv.xml file in the same location where isvps are present. This is shown below)


Step 4 : Open the isv.xml file using some textpad or notepad++ (I am fortunate that its only 1MB, You have to struggle if your application is huge editing this isv.xml would be a challenge)
A view to show the text which causes this problem is shown below
You could see the highlighted portion which must be removed in order to overcome this error.
Once you remove you have to replace this isv.xml file to the same archive.

Step 5 : Over write the isv.xml into archive content (isv)


Step 6 : You can go ahead and install the isvp (You might have to close and open the Application registry not to run into problem while installing again)



Note : Write to me if anything to be added here.


Usage of variable in xslt (Data Transformation)

We use XSLT in data transformation and in one particular situation we might want to use same value for different fields. A variable in such case is a best approach one could think of. Below is the code snippet which is used in xslt in order to create and use a variable.

Below is a part of xslt which can be referred as an example,

<sch:ReceivedReturnCenter>
<xsl:value-of xmlns:sch="http://schemas.cordys.com/" select="concat(substring(/sch:ROConDTInput/sch:request/sch:GRDATE,7,2),substring(/sch:ROConDTInput/sch:request/sch:GRDATE,5,2),substring(/sch:ROConDTInput/sch:request/sch:GRDATE,1,4))" />
</sch:ReceivedReturnCenter>
<sch:SendBackToCustomer>
<xsl:value-of xmlns:sch="http://schemas.cordys.com/" select="concat(substring(/sch:ROConDTInput/sch:request/sch:GRDATE,7,2),substring(/sch:ROConDTInput/sch:request/sch:GRDATE,5,2),substring(/sch:ROConDTInput/sch:request/sch:GRDATE,1,4))" />
</sch:SendBackToCustomer>

Here both the target values "ReceivedReturnCenter" and "SendBackToCustomer" are mapped to a single value which is concatenation/substring of another field "GRDATE".

No doubt with this approach we would achieve the solution but its unnecessary to perform the same logic multiple times. Hence ideally we would be having the logic stored in a variable and use that variable to assign to both the target fields. Here is how we can do it,

<xsl:variable name="grDate">
<xsl:value-of xmlns:sch="http://schemas.cordys.com/" select="concat(substring(/sch:ROConDTInput/sch:request/sch:GRDATE,7,2),substring(/sch:ROConDTInput/sch:request/sch:GRDATE,5,2),substring(/sch:ROConDTInput/sch:request/sch:GRDATE,1,4))" />
</xsl:variable>
<sch:ReceivedReturnCenter>
<xsl:value-of select="$grDate" />
</sch:ReceivedReturnCenter>
<sch:SendBackToCustomer>
<xsl:value-of select="$grDate" />
</sch:SendBackToCustomer>

Usage of variable : $grDate

Note : There is a drawback of using variable in xslt as the same variable cannot be edited later (or I am not aware of :P). Variables in xslt are supposed to be initialized/assigned a value only once. 

Tuesday, April 8, 2014

Write a file from Java with Encoding "UTF-8 Without BOM"

The ultimate goal is to write the file with different encoding types (ANSI/UTF-8/UTF-8 without BOM):

The Code which I will be referring through out this post would be below
public static void main(String[] args) throws IOException {
OutputStreamWriter osw = null;
try{
//Example to write a file into file system
//Charset windows1252 = Charset.forName("windows-1252");
String filePath="D:\\temp\\";
filePath = filePath.concat(String.valueOf(new Date().getTime())).concat(".txt");
FileOutputStream fos = new FileOutputStream(filePath,false);
osw = new OutputStreamWriter(fos,"UTF-8");
osw.write("Sample");
osw.write("\uFEFF");
osw.write("File");
//osw.write(Charset.forName("UTF-8").encode("Sample"));
osw.close();
System.out.println("Success");
fos.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
osw.close();
}
}
Scenario 1: (You want to write a file with "ANSI" encoding) Below url helps


Writing straight forwardly(Simple plain text) would save the file in ANSI format even though your output stream reader has a character set "UTF-8". It is because there are no UTF-8 characters that you are writing. Unless you write UTF-8 characters the file will not change from ANSI. 


But if your requirement is not this, You have simple plain text but you have to write a file in UTF-8 Encoding you have to go through below,

Scenario 2: UTF-8 Encoding is divided into two types 1. With BOM and 2. Without BOM

Following piece of code helps to write a file with BOM,
Here adding \uFEFF character at initial block would make this file as UTF-8 with BOM,

The result of above code is shown below
Now your requirement is still not this, You have a simple plain text but you want to write the file with encoding as "Encoding in UTF-8 without BOM". Please refer scenario 3.

Scenario 3: (Write file using UTF-8 without BOM).

You just have to make sure you write "\uFEFF" character to make the file as "UTF-8" and write it after some simple text to make the encoding as "UTF-8 without BOM".

The result would be as shown below
Note : The encoding what this post is talking about all are taken from Notepad++





Code snippet to write a file from Java

public static void main(String[] args) throws IOException {
OutputStreamWriter osw = null;
try{
//Example to write a file into file system
//Charset windows1252 = Charset.forName("windows-1252");
String filePath="D:\\temp\\";

filePath = filePath.concat(String.valueOf(new Date().getTime())).concat(".txt");
FileOutputStream fos = new FileOutputStream(filePath,false);
osw = new OutputStreamWriter(fos,"UTF-8");
osw.write("Sample");
osw.write("\uFEFF");
osw.write("File");
//osw.write(Charset.forName("UTF-8").encode("Sample"));
osw.close();
System.out.println("Success");
fos.close();

}
catch(Exception e)
{
System.out.println(e.getMessage());
osw.close();
}
}