This discussion is archived
11 Replies Latest reply: Jul 2, 2012 2:58 AM by 946415 RSS

How to add exactly 2 NON XML caracters at the end of a SOAP body

946415 Newbie
Currently Being Moderated
Hello all I am trying to add two (and only two) extra non xml caracters "AA" at the END of a SOAP body using the JAXWS handlers as so:

HTTP/1.1 200 OK
Content-Type: text/xml;charset=UTF-8
Content-Length: 131
Content-Length: 131
Server: Jetty(7.x.y-SNAPSHOT)

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body></SOAP-ENV:Body></SOAP-ENV:Envelope>
AA

The problem is that if you try to add them to the SOAP body (see code below) you get a XML Unmarshalling exception. If I add "AA" as a soap attachment I get MORE than 2 caracters after the SOAP body (which I don't want)




Here is the my SOAPHandler code :

@Override
public boolean handleMessage(SOAPMessageContext mc) {
if (Boolean.TRUE.equals(mc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY))) {

try {
SOAPMessage message = context.getMessage()
String stringSoapMessage= getMsgAsString(message);
stringSoapMessage += "ss";
message.getSOAPPart().setContent((Source) new StreamSource(new ByteArrayInputStream(msg.getBytes())));
message.saveChanges();
context.setMessage(message);

} catch (Exception e1) {

}

}
return true;
}

public String getMsgAsString(SOAPMessage message) throws SOAPException {
String msg = null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
message.writeTo(baos);
msg = baos.toString();
} catch (Exception e) {
e.printStackTrace();
}

return msg;
}


so my question is this: is there any way to add exactly 2 non xml caracters at the end of the soap body using jaxws handlers ? I have spent several weeks on this so it is not an easy question...

Thanks,

Fred.
  • 1. Re: How to add exactly 2 NON XML caracters at the end of a SOAP body
    jtahlborn Expert
    Currently Being Moderated
    sorry, i can't resist asking... why?
  • 2. Re: How to add exactly 2 NON XML caracters at the end of a SOAP body
    gimbal2 Guru
    Currently Being Moderated
    jtahlborn wrote:
    sorry, i can't resist asking... why?
    You... what have you DONE!?
  • 3. Re: How to add exactly 2 NON XML caracters at the end of a SOAP body
    946415 Newbie
    Currently Being Moderated
    hehe ! Well lets just say that sometimes I do things that don't make a whole lot of sense ! But really I am developing a webservice that is taking to a complex system which I cannot touch (by complex I mean weird). This system seems to want two extra caracters at the end of each SOAP messages (and exactly two) else it will discard these messages (don't ask). It was particularly hard to see in GUI network monitoring tools (SOAP UI and tcp mon) as the two caracters were /r/n ...

    But the thing that is frustrating to me is that I am sure there is a way to do something as simple as this in JAXWS ... I mean it doesn't violate any network protocols or nothing (it would be like adding a small attachment). I did manage to do it using CFX interceptors but the dependencies are just to heavy for me to warrant its use for such a small feature ...

    Any ideas on how to proceed/hack is most appreciated ! ( I am going to start looking if using reflection would help but I don't know how stable this would be ...)

    Thanks,

    Fred.
  • 4. Re: How to add exactly 2 NON XML caracters at the end of a SOAP body
    Kayaman Guru
    Currently Being Moderated
    943412 wrote:
    as the two caracters were /r/n ...
    You mean \r\n. That's the CRLF combination, so it makes (a little) more sense than just some random "AA" characters there.

    I imagine adding the CRLF isn't gonna be a bother, unlike adding "AA" which is completely out of place.

    Edited by: Kayaman on Jul 2, 2012 11:09 AM
  • 5. Re: How to add exactly 2 NON XML caracters at the end of a SOAP body
    946415 Newbie
    Currently Being Moderated
    Actually \r\n will be trimmed if you try to add it to your soap body ...
  • 6. Re: How to add exactly 2 NON XML caracters at the end of a SOAP body
    gimbal2 Guru
    Currently Being Moderated
    JAX-WS is only an API, it doesn't do anything. CXF is one of packages that delivers a JAX-WS implementation. So if you can do it through CXF that is in fact the answer to your question. But you may also want to investigate the documentation of the Metro webservices stack (which is the reference implementation backed by Oracle).

    http://metro.java.net/

    I believe the JAX-WS implementation that is part of the JDK is based on Metro; the version bundled with JDK 6 is very old though.
  • 7. Re: How to add exactly 2 NON XML caracters at the end of a SOAP body
    946415 Newbie
    Currently Being Moderated
    Yes I have done it using CFX interceptors. But the runtime dependencies needed were too big for this particular use. I mean having to use these:


    apache/cxf/cxf-bundle/2.6.0/cxf-bundle-2.6.0.jar
    org/apache/neethi/neethi/3.0.2/neethi-3.0.2.jar                    
    wsdl4j/wsdl4j/1.6.2/wsdl4j-1.6.2.jar
    /org/codehaus/woodstox/wstx-asl/3.2.4/wstx-asl-3.2.4.jar
    org/apache/ws/xmlschema/xmlschema-core/2.0.2/xmlschema-core-2.0.2.jar
    org/mortbay/jetty/jetty-util/6.0.2/jetty-util-6.0.2.jar
    org/eclipse/jetty/jetty-util/7.5.4.v20111024/jetty-util-7.5.4.v20111024.jar
    org/apache/geronimo/specs/geronimo-servlet_2.5_spec/1.1.2/geronimo-servlet_2.5_spec-1.1.2.jar
    org/apache/geronimo/specs/geronimo-javamail_1.4_spec/1.7.1/geronimo-javamail_1.4_spec-1.7.1.jar
    org/apache/geronimo/specs/geronimo-servlet_3.0_spec/1.0/geronimo-servlet_3.0_spec-1.0.jar
    org/eclipse/jetty/jetty-http/7.5.4.v20111024/jetty-http-7.5.4.v20111024.jar
    org/eclipse/jetty/jetty-server/7.5.4.v20111024/jetty-server-7.5.4.v20111024.jar
    org/eclipse/jetty/jetty-io/7.5.4.v20111024/jetty-io-7.5.4.v20111024.jar
    org/eclipse/jetty/jetty-continuation/7.5.4.v20111024/jetty-continuation-7.5.4.v20111024.jar

    to add two caracters at the end of a soap message seems like over kill. If this is the only way to do this then i'll do it this way but it just seems like the implementation of the JAXWS API in JDK 6 seems inches away from being able to do this no ?

    Thanks for the replies,

    Fred
  • 8. Re: How to add exactly 2 NON XML caracters at the end of a SOAP body
    gimbal2 Guru
    Currently Being Moderated
    Like I said, check the metro web services if you want to learn more about the JAX-WS implementation built into the JDK.

    http://metro.java.net/guide/

    Having to include a trunk load of dependencies is not uncommon when working with enterprisey Java stuff by the way...
  • 9. Re: How to add exactly 2 NON XML caracters at the end of a SOAP body
    946415 Newbie
    Currently Being Moderated
    Hmmm, the metro implementation of JAX-WS is not part of JDK 6 no ?:

    <dependency>
    <groupId>org.glassfish.metro</groupId>
    <artifactId>webservices-rt</artifactId>
    <version>2.1</version>
    </dependency>

    I get the feeling this will also introduce a lot of dependencies. The main reason why I want to avoid doing something like this unless it is necessary is that most of the libraries needed by metro and the apache cfx bundle are not supported by our production chain. This means that I will have to check all of them out before making sure that I can add them and convince people that we cannot do it without them (which I am trying to make sure). I already know that this can be done by throwing libraries into the build. I am trying to avoid this by using JDK 6 libraries and it doesn't seem like a stretch to make it work no ? I mean all the framework is already in java 6 to do this ... It's definitely not trivial to make it work: it is not directly offered by the API and i've been at it for 2 weeks and going... I am going to use the cfx interceptors if it comes to that but I wanted to check out the community first !

    Thanks again for the replies,

    John.
  • 10. Re: How to add exactly 2 NON XML caracters at the end of a SOAP body
    gimbal2 Guru
    Currently Being Moderated
    943412 wrote:
    Hmmm, the metro implementation of JAX-WS is not part of JDK 6 no ?:
    Yes it is. Only JDK 6 has version 1.1 of it. I don't know if later Java 6 updates received a newer version.

    Note that all that is basically for compilation purposes. If you are running this stuff on an application server then there is already an implementation of JAX-WS in there.
  • 11. Re: How to add exactly 2 NON XML caracters at the end of a SOAP body
    946415 Newbie
    Currently Being Moderated
    Thanks for the fast replies ! I not running it on an application server, I am doing a good old endpoint.publish on a standard JVM with java 6. I will check out metro version 1.1 and see what gives. If you have other JDK 6 stuff don't hesitate ;)


    Thanks again,

    Fred.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points