Envelope generated adds \r\n

140 views
Skip to first unread message

Ernesto Torres

unread,
Apr 25, 2012, 6:52:03 PM4/25/12
to ksoap2-android
Hello,

I am making a connection to a web service. I have previously tested
with a different webservice and it works correcty, then I changed the
SOAP data to the new Web Service and it didn't work.

The problem is that the envelope generated appends at the end a \r\n
and that for some weird reason breaks the Web Service.

Is there a way to edit the content of the XML generated envelope
before sending it with the HttpTransportSE call?

Thank you,

Ernesto Torres

Rustam K.

unread,
Apr 25, 2012, 7:15:28 PM4/25/12
to ksoap2-...@googlegroups.com
Hello,
Not sure how you can edit soap packet before sending it out, or by
setting special flags to envelope, but the library itself is not very big.
The most important classes are SoapEnvelope.java
SoapSerializationEnvelope.java KvmSerializable.java
Running debugger and checking writer's buffer should guide you through
the creation of soap packet, and you should be able to find the code
that appends \r\n sequence

Manfred Moser

unread,
Apr 25, 2012, 7:29:13 PM4/25/12
to ksoap2-...@googlegroups.com
And once you found it you can send a pull request with the fix to remove it ;-)

Ernesto Torres

unread,
Apr 26, 2012, 10:55:48 AM4/26/12
to ksoap2-...@googlegroups.com
Downloaded the sources, installed maven and did a

mvn clean install on the sources

I get this error:

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3:16.815s
[INFO] Finished at: Thu Apr 26 09:40:30 CDT 2012
[INFO] Final Memory: 8M/19M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:
2.9.1:check (default) on project ksoap2-base: You have 37 Checkstyle violations.
 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
eption
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command

[ERROR]   mvn <goals> -rf :ksoap2-base


Any idea why?

Manfred Moser

unread,
Apr 26, 2012, 12:29:12 PM4/26/12
to ksoap2-...@googlegroups.com

I am fixing that now.

Manfred Moser

unread,
Apr 26, 2012, 12:43:38 PM4/26/12
to ksoap2-...@googlegroups.com
This is fixed now. The build should succeed just fine.

When you are changing code yourself please keep in mind that the build includes running the checkstyle plugin and enforces things like line length or no tabs and a few other things.

If that happens you can just look at the error message in the checkstyle-results.xml file in target of the failing project.

This is documented here btw.


manfred

Ernesto Torres

unread,
Apr 26, 2012, 4:40:31 PM4/26/12
to ksoap2-...@googlegroups.com
The clean snapshot 

[INFO] Building ksoap2-base 2.6.4-SNAPSHOT

Is still giving me trouble in the build. Should I download it from git?

Manfred Moser

unread,
Apr 26, 2012, 5:30:28 PM4/26/12
to ksoap2-...@googlegroups.com
If you are working with the source you should get it from github

git clone git://github.com/mosabua/ksoap2-android.git
cd ksoap2-android
mvn clean install

works. I just tried it.

To create a pull request it is best to create your own fork, create a
branch in there and then send a pull request off the branch in github.
More details on the github site..

manfred

sdn

unread,
Jun 20, 2012, 7:15:19 AM6/20/12
to ksoap2-...@googlegroups.com
The \r\n generated at the end of the Envelope is also giving me problems in order to access a Web Service. Are there any plans to remove this characters in future versions of the library? is there any quick fix to this? 

Thanks in advance

Ernesto Torres

unread,
Jun 20, 2012, 10:16:37 AM6/20/12
to ksoap2-...@googlegroups.com
At first I thought that too, but the \r\n only appeared when running the debugger and analyzing the raw content.

To see the real content you can do this:

HttpTransportSE httpTransport = new HttpTransportSE(URL);  
httpTransport.debug = true;
httpTransport.call(ACTION, ENVELOPE); //send request

Log.d(TAG, "----------------- " + httpTransport.requestDump +"\r\n\r\n" + httpTransport.responseDump);

The problem may be the incorrect call of ksoap, it took me a while since I didn't knew how it worked.


This is the structure I use for retrieving a SOAP object for a WS operation with out any fields but the operation:

SoapObject request = new SoapObject(NAMESPACE, METHOD); //set up request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //put all required data into a soap envelope
envelope.setOutputSoapObject(request);  //prepare request
HttpTransportSE httpTransport = new HttpTransportSE(URL);  
httpTransport.debug = true;
httpTransport.call(ACTION, ENVELOPE); //send request
Log.d(TAG, "----------------- " + httpTransport.requestDump +"\r\n\r\n" + httpTransport.responseDump);
SoapObject result=(SoapObject)envelope.getResponse(); //get response
Log.d(TAG, "SoapObject: "+result.toString());


Hope it helps,

Ernesto

Robert Gustavsson

unread,
Jan 11, 2013, 1:33:14 PM1/11/13
to ksoap2-...@googlegroups.com
Hello!

It is because you downloaded the sources with Unix line endings (LF) and the file ...\ksoap2-android-master\build-tools\src\main\resources\simpligility\checkstyle.xml has this rule:

<module name="NewlineAtEndOfFile"/>

which creates errors likes this in ...\ksoap2-android-master\ksoap2-base\target\checkstyle-result.xml

<file name="C:\ksoap2-android-master\ksoap2-base\src\main\java\org\ksoap2\HeaderProperty.java">
  <error source="com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck" message="File does not end with a newline." severity="error" line="0"/>
</file>

which means maven on Windows doesn't think LF is a correct line ending. I replaced the last line ending with CR/LF just to verify this.

IMO this is quite braindead since most serious editors and tools on Windows nowadays has no problems with LF terminated files.

This also makes it dependant on you getting git to work (which I failed today at work, will try at home later) and it also depends on choosing the option that git converts from LF to CR/LF when retrieving code from a repo instead of the better option, leave it as it is.

Why <module name="NewlineAtEndOfFile"/> is required is a bit strange, if Java can't handle it there will be an error and it won't build and that code should make it to the repo anyway.

My reason for wanting to rebuild ksoap2 is that I want it more compliant with MS format for the request sent to the WS. I wan't to be able to specify the namespace aliases (xsi instead of i) which is hardcoded and impossible to set externally. I also want to get rid of the empty <Header /> tag. I don't think I am knowledgeable enough to contribute any changes back to the project though.

Cheers!

Rob

Robert Gustavsson

unread,
Jan 11, 2013, 1:34:53 PM1/11/13
to ksoap2-...@googlegroups.com
"that code should make it to the repo" should say shouldn't.

Manfred Moser

unread,
Jan 11, 2013, 2:03:54 PM1/11/13
to ksoap2-...@googlegroups.com
I will try to get that fixed but with the right git setup in terms of
CR/LF it should work. I am happy to delete that rule though.. send a
pullrequest ;-)

Robert Gustavsson

unread,
Jan 11, 2013, 2:25:50 PM1/11/13
to ksoap2-...@googlegroups.com
Naah. I don't dare to pull or push anything. I am a closed source guy. ;-)

/rob

Robert Gustavsson

unread,
Jan 11, 2013, 3:36:22 PM1/11/13
to ksoap2-...@googlegroups.com
Got git working at home without any problems, probably the firewall @ work.

The build was successful from the git got code after removing <module name="NewlineAtEndOfFile"/>) from the checkstyle.xml file.

/rob

Manfred Moser

unread,
Jan 12, 2013, 6:19:07 PM1/12/13
to ksoap2-...@googlegroups.com
so how many failures do you get if you leave it in? could you just add
a newline at the end of those files and it works?

Robert Gustavsson

unread,
Jan 12, 2013, 6:25:48 PM1/12/13
to ksoap2-...@googlegroups.com

37 errors. Maven expects cr/lf on windows. LF won't do it. A bit strange in fact that you can mess up line endings as long as the last one is ok.

Manfred Moser

unread,
Jan 13, 2013, 1:39:57 PM1/13/13
to ksoap2-...@googlegroups.com
Hm... are you sure you have configured your git config correctly for windows?

If it is really just the last line in 37 files... could you just add a
new line at the end of these and that would fix it?

Sorry that I cant debug this but I have no Windows around me at all..

manfred

Robert Gustavsson

unread,
Jan 14, 2013, 5:44:15 AM1/14/13
to ksoap2-...@googlegroups.com
Hi!
 
I got this sorted out now and it works if you configure git to convert to cr/lf when cloning the repo (or by patching the checkstyle.xml).
 
I've made 2 of 3 changes I planned and managed to rebuild ksoap2 with maven.
 
1) Removed the empty <Header /> in the SOAP request.
2) Added support for setting the namespace prefixes (xsd, xsi, and soap instead of x, d, and i).
3) The encoding namespace (c) that is unused in the request if adornments are turned off (c:root="1").
 
The encoding name space is referenced by other things (serializing arrays) which I currently don't know enough about.
 
Let me know if you think 1 and 2 are interesting enough to add to ksoap2 and I'll try to learn enough about git to be able to contribute.
 
/rob

Manfred Moser

unread,
Jan 14, 2013, 11:48:18 AM1/14/13
to ksoap2-...@googlegroups.com
I would totally love to get these improvements in. If you create a
separate branch and push them to github and then create a pull request
I can pull them in. Otherwise you can just create a patch file and I
can work with that as well.. that takes longer for me though and I am
currently very busy..

manfred

Robert Gustavsson

unread,
Jan 14, 2013, 5:10:56 PM1/14/13
to ksoap2-...@googlegroups.com
A clarification of the cr/lf issue I had. The rule

<module name="NewlineAtEndOfFile"/>

expects cr/lf on Windows. I pulled the files with git configured to leave line endings as they are. Then the rule won't accept the single <lf> as a line ending. But fixing the line-ending for the last line in the 37 files works (leaving all other lines with just <lf>):

row1<lf>
row2<lf>
row3<cr><lf>

which is a bit wacked IMO. A rule for checking the entire file's line ending would make more sense. And the rules accepts lines which contains only spaces. I tend to trim those away when editing other ppls source code. SoapFault12.java has a lot of empty lines with a lot of unnecessary spaces.

I have no problem with attention to detail, but attention to just one detail that probably doesn't matter (and messes up compilation) and not attending to other that matters more (IMO) is a bit strange :-)

/rob

Manfred Moser

unread,
Jan 16, 2013, 1:04:44 PM1/16/13
to ksoap2-...@googlegroups.com
I have removed the check in github now since I dont have time to fix
the files nor access to windows to find out which ones..
Reply all
Reply to author
Forward
0 new messages