Rajvinder Singh

Greenhorn
+ Follow
since Oct 13, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rajvinder Singh

Hi guys.

iam facing one problem, and cant work it out why exactly it happening.
Iam putting an inputstream request in to Map and than using SAXBuilder parser to parse the same. but when iam using build() method of SAXBuilde its saying me Character conversion error: "Malformed UTF-8 char -- is an XML encoding declaration missing? i dond know why???

here is my code.
<%
response.setContentType("text/xml");


InputStream ins = (InputStream)request.getInputStream();
OutputStream fileOut = null;
// Get the lenth of the bytes.
int insLength = request.getContentLength();
System.out.println("inslength ="+ insLength);
String APP_ID = null;
String SERVICE_ID = null;
String ACTION_ID = null;
String DAO_ID = null;

try{
// Set the byte type array length to total length of bytes receive.
byte[] fileDataByte = new byte[insLength];
byte[] fileNamebyte = new byte[insLength];
ins.read(fileNamebyte,0,300);
int len = 0;
char ch;


String fileName;
StringBuffer sbFileName = new StringBuffer();
StringBuffer filePath = new StringBuffer();
// Raed the fist 30 bytes to get the file name.
while(len <=300 )
{
ch=(char)fileNamebyte[len] ;
len++;
sbFileName.append(ch);
}
System.out.print("File Name is ="+sbFileName.toString());
fileName = sbFileName.toString().trim();

System.out.println("Before Hashmap"+ins);
HashMap map = new HashMap();
map.put("REQUESTTYPE","XML");
map.put("TESTCODE","TRUE");
map.put("XMLSOURCE",ins);
System.out.println("After Hashmap");

String x = (String)map.get("TESTCODE");
System.out.println("TESTCODE"+x);

/*String xsource = (String)map.get("XMLSOURCE");
System.out.println("XMLSOURCE"+xsource); */
// Build the document with SAX and Xerces, no validation
SAXBuilder builder = new SAXBuilder();
// Create the document
Document doc = null;
System.out.println("before DOC");
if(map.containsKey("TESTCODE")){
System.out.println("check 4 test code");
doc = builder.build((InputStream)map.get("XMLSOURCE"));
}
System.out.println("after DOC");
//doc = builder.build((String)map.get("XMLSOURCE"));


Element RootElement = doc.getRootElement();
System.out.println("after doc"+RootElement.getText().equalsIgnoreCase("REQ"));
// Scans the Request
if ( (RootElement.getName().equals("REQ"))){
System.out.println("after Req");
//Get the APPLICATION TAG
Element app = RootElement.getChild("APP");
//Get the APPLICATION ID
APP_ID = app.getAttributeValue("ID").trim();
System.out.println("APP_ID ="+ APP_ID);
// Get the SERVICE TAG
Element service = app.getChild("SRV");
// Get the Service ID
SERVICE_ID = service.getAttributeValue("ID").trim();
System.out.println("SERVICE_ID ="+ SERVICE_ID);
//Get the ACTION Tag
Element action = service.getChild("ACT");
//Get the action Action ID
ACTION_ID = action.getText().trim();
System.out.println("ACTION_ID ="+ ACTION_ID);
//Get the DAO Tag
Element dao = service.getChild("DAO");
//Get the action Action ID
DAO_ID = dao.getText().trim();
}

// Set the path to uplaod the file.
System.out.println("before file path");
filePath = filePath.append("/var/opt/SUNWappserver7/domains/domain1/server1/applications/j2ee-modules/KotakAssist_1/external/" +APP_ID);
System.out.println("File Path ="+filePath.toString());

// write the stream to the file.
fileOut = new BufferedOutputStream(new FileOutputStream(filePath.toString()));
// Now ins.read(fileDataByte) will read the 31st byte to end of line
ins.read(fileDataByte);
fileOut.write(fileDataByte);
fileOut.flush();
fileOut.close();
System.out.println("file uplaoded sucessfully"+fileName);
}
%>
and my inputstream is an xml file + xsl file
my xml file format is

<?xml version="1.0" encoding="utf-8"?>
<REQ>
<APP ID="KA">
<SRV ID="KA">
<ACT>GET</ACT>
<DAO>SQL</DAO>
</SRV>
<DATA>
<IN KEY="GET_ACC">
<IN KEY="ROW1">
<IN KEY="ACCOPENID">1</IN>
<IN KEY="UID">1</IN>
</IN>
</IN>
</DATA>
</APP>
</REQ>

Tahnks in advance.
Rajvinder Singh
Hi,

I am facing some problem while running my tom cat. it saying access denied i don't know why.even i had set all my classpath, java_home path, Catalina_home path but still its saying access denied. even i increase memmory though command line but still not happening.

Here is how i set my autoexec.bat file

SET PATH=d:\jdk1.4\j2sdk1.4.2\bin;%PATH%
SET JAVA_HOME=d:\jdk1.4\j2sdk1.4.2
SET CATALINA_HOME=C:\Program Files\Apache Software Foundation\Tomcat 5.0
SET CLASSPATH=%CATALINA_HOME%\common\lib\servlet.jar;d:\jdk1.4\j2sdk1.4.2\lib;%PATH%
set classpath=.;C:\Program Files\Apache Software Foundation\Tomcat 5.0\server\lib\catalina.jar;
set classpath=.;C:\Program Files\Apache Software Foundation\Tomcat 5.0\lib\jasper-runtime.jar;
set classpath=.;C:\Program Files\Apache Software Foundation\Tomcat 5.0\lib\jasper-compiler.jar;

error out put -:

Using CATALINA_BASE: C:\Program Files\Apache Software Foundation\Tomcat 5.0
Using CATALINA_HOME: C:\Program Files\Apache Software Foundation\Tomcat 5.0
Using CATALINA_TMPDIR: C:\Program Files\Apache Software Foundation\Tomcat 5.0\te
mp
Using JAVA_HOME: d:\jdk1.4\j2sdk1.4.2
Access is denied.

please help me out

Regards
Rajvinder
19 years ago