You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Oliver Hirschi <o....@bluewin.ch> on 2008/02/11 16:01:56 UTC
[Axis2] Call service with UTF-8 Stream
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: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
Re: [Axis2] Call service with UTF-8 Stream
Posted by Amila Suriarachchi <am...@gmail.com>.
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 <o....@bluewin.ch> wrote:
> Hi Andreas
>
> That's it! Many thanks for your efforts!
>
> Oliver Hirschi
>
>
> "Andreas Veithen" <an...@skynet.be> schrieb im Newsbeitrag
> news:2233B6DD-2222-4FA7-868E-F106603D1584@skynet.be...
> > 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: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>
--
Amila Suriarachchi,
WSO2 Inc.
Re: [Axis2] Call service with UTF-8 Stream
Posted by Oliver Hirschi <o....@bluewin.ch>.
Hi Andreas
That's it! Many thanks for your efforts!
Oliver Hirschi
"Andreas Veithen" <an...@skynet.be> schrieb im Newsbeitrag
news:2233B6DD-2222-4FA7-868E-F106603D1584@skynet.be...
> 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: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
Re: [Axis2] Call service with UTF-8 Stream
Posted by Andreas Veithen <an...@skynet.be>.
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: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org