[Axis2] Call service with UTF-8 Stream

2008-02-11 Thread Oliver Hirschi

Hi

I try to call a soap-service on an axis2 1.3 server with only one 
string argument. The value of the string argument I get from a file 
which is utf-8 encoded and contains special characters like "äöü".


I read the file as followed:

Reader in = new InputStreamReader(new FileInputStream(m_sUploadFile), 
"UTF-8");

char[] chr = new char[(int)new File(m_sUploadFile).length()];
in.read(chr);
in.close();
String sArgument = new String(chr);


If I now call the service with sArgument as argument, I get ever the 
error:


org.apache.axis2.AxisFault: Invalid null character in text to output
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:417)
at 
org.apache.axis2.transport.http.SOAPMessageFormatter.writeTo(SOAPMessageFormatter.java:72)
at 
org.apache.axis2.transport.http.AxisRequestEntity.writeRequest(AxisRequestEntity.java:84)
at 
org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:495)
at 
org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:1973)



This is my soap-client-code:

try {
RPCServiceClient sender = new RPCServiceClient();
Options options = sender.getOptions();
// Set the Server-Reference
EndpointReference targetEPR = new 
EndpointReference(m_sCPSServerURL+"/CPSServerRedSys");

options.setTo(targetEPR);
// Set the operation to be called
QName op_xmlexport = new QName(CPSSERVER_NAMESPACE, 
"redsysImportStructure");

// Set the parameters
Object[] opArgs = new Object[] { new String(sStructureXMLStream),
new Integer(iRedSysUserID)
};
Class[] returnTypes = new Class[] { String.class };
// Call WebService
Object[] response = sender.invokeBlocking(op_xmlexport, opArgs, 
returnTypes);

// Read Return data
if(response[0] != null) {
String sResponse = response[0].toString();
if(sResponse.startsWith("CPS-Error: ")) {
oSB_ImportReport.append(sResponse.substring(sResponse.indexOf("CPS-Error: 
")+11));

bOK = false;
} else {
oSB_ImportReport.append(response[0].toString());
}
}
} catch(AxisFault e) {
oSB_ImportReport.append("Error calling CPSServer: " +e.toString());
bOK = false;
}


Can anyone help?

Great thanks,
--
Oliver Hirschi
http://www.FamilyHirschi.ch 




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [Axis2] Call service with UTF-8 Stream

2008-02-11 Thread Andreas Veithen

Hi Oliver!

The code you use to read the content of the file is incorrect. The  
size of the char array you are allocating equals the file size, which  
is calculated in number of bytes. For UTF-8, if special characters  
appear in the file, the number of characters is less than the number  
of bytes. Therefore you will indeed have null characters at the end of  
your array. I suggest to use one of the IOUtils.toString methods from  
Commons IO to read the file content as a string.


Andreas

On 11 Feb 2008, at 16:01, Oliver Hirschi wrote:


Hi

I try to call a soap-service on an axis2 1.3 server with only one  
string argument. The value of the string argument I get from a file  
which is utf-8 encoded and contains special characters like "äöü".


I read the file as followed:

Reader in = new InputStreamReader(new  
FileInputStream(m_sUploadFile), "UTF-8");

char[] chr = new char[(int)new File(m_sUploadFile).length()];
in.read(chr);
in.close();
String sArgument = new String(chr);


If I now call the service with sArgument as argument, I get ever the  
error:


org.apache.axis2.AxisFault: Invalid null character in text to output
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:417)
at  
org 
.apache 
.axis2 
.transport 
.http.SOAPMessageFormatter.writeTo(SOAPMessageFormatter.java:72)
at  
org 
.apache 
.axis2 
.transport 
.http.AxisRequestEntity.writeRequest(AxisRequestEntity.java:84)
at  
org 
.apache 
.commons 
.httpclient 
.methods 
.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java: 
495)
at  
org 
.apache 
.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java: 
1973)



This is my soap-client-code:

try {
RPCServiceClient sender = new RPCServiceClient();
Options options = sender.getOptions();
// Set the Server-Reference
EndpointReference targetEPR = new EndpointReference(m_sCPSServerURL 
+"/CPSServerRedSys");

options.setTo(targetEPR);
// Set the operation to be called
QName op_xmlexport = new QName(CPSSERVER_NAMESPACE,  
"redsysImportStructure");

// Set the parameters
Object[] opArgs = new Object[] { new String(sStructureXMLStream),
new Integer(iRedSysUserID)
};
Class[] returnTypes = new Class[] { String.class };
// Call WebService
Object[] response = sender.invokeBlocking(op_xmlexport, opArgs,  
returnTypes);

// Read Return data
if(response[0] != null) {
String sResponse = response[0].toString();
if(sResponse.startsWith("CPS-Error: ")) {
oSB_ImportReport.append(sResponse.substring(sResponse.indexOf("CPS- 
Error: ")+11));

bOK = false;
} else {
oSB_ImportReport.append(response[0].toString());
}
}
} catch(AxisFault e) {
oSB_ImportReport.append("Error calling CPSServer: " +e.toString());
bOK = false;
}


Can anyone help?

Great thanks,
--
Oliver Hirschi
http://www.FamilyHirschi.ch


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [Axis2] Call service with UTF-8 Stream

2008-02-11 Thread Oliver Hirschi

Hi Andreas

That's it! Many thanks for your efforts!

Oliver Hirschi


"Andreas Veithen" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]

Hi Oliver!

The code you use to read the content of the file is incorrect. The 
size of the char array you are allocating equals the file size, which 
is calculated in number of bytes. For UTF-8, if special characters 
appear in the file, the number of characters is less than the number 
of bytes. Therefore you will indeed have null characters at the end 
of  your array. I suggest to use one of the IOUtils.toString methods 
from  Commons IO to read the file content as a string.


Andreas

On 11 Feb 2008, at 16:01, Oliver Hirschi wrote:

> Hi
>
> I try to call a soap-service on an axis2 1.3 server with only one 
> string argument. The value of the string argument I get from a file 
> which is utf-8 encoded and contains special characters like "äöü".

>
> I read the file as followed:
> 
> Reader in = new InputStreamReader(new 
> FileInputStream(m_sUploadFile), "UTF-8");

> char[] chr = new char[(int)new File(m_sUploadFile).length()];
> in.read(chr);
> in.close();
> String sArgument = new String(chr);
> 
>
> ... 




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [Axis2] Call service with UTF-8 Stream

2008-02-13 Thread Amila Suriarachchi
set the character encoding to
serviceClient.getOptions().setProperty(
Constants.Configuration.CHARACTER_SET_ENCODING,"ISO-8859-1");

Amila.

On Feb 12, 2008 1:10 PM, Oliver Hirschi <[EMAIL PROTECTED]> wrote:

> Hi Andreas
>
> That's it! Many thanks for your efforts!
>
> Oliver Hirschi
>
>
> "Andreas Veithen" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
> news:[EMAIL PROTECTED]
> > Hi Oliver!
> >
> > The code you use to read the content of the file is incorrect. The
> > size of the char array you are allocating equals the file size, which
> > is calculated in number of bytes. For UTF-8, if special characters
> > appear in the file, the number of characters is less than the number
> > of bytes. Therefore you will indeed have null characters at the end
> > of  your array. I suggest to use one of the IOUtils.toString methods
> > from  Commons IO to read the file content as a string.
> >
> > Andreas
> >
> > On 11 Feb 2008, at 16:01, Oliver Hirschi wrote:
> >
> > > Hi
> > >
> > > I try to call a soap-service on an axis2 1.3 server with only one
> > > string argument. The value of the string argument I get from a file
> > > which is utf-8 encoded and contains special characters like "äöü".
> > >
> > > I read the file as followed:
> > > 
> > > Reader in = new InputStreamReader(new
> > > FileInputStream(m_sUploadFile), "UTF-8");
> > > char[] chr = new char[(int)new File(m_sUploadFile).length()];
> > > in.read(chr);
> > > in.close();
> > > String sArgument = new String(chr);
> > > 
> > >
> > > ...
>
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


-- 
Amila Suriarachchi,
WSO2 Inc.