You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by kbabushkin <kb...@hotmail.com> on 2012/08/23 04:26:23 UTC

Apache CXF (2.6.1): Client gets “Content is not allowed in prolog”

Hello,

I'm using Apache CXF (2.6.1) in my java application to consume 3rd party Web
Service. But I have a problem with it, in particular if I use JAXB for
databinding while stubs generation my client will always send requests with
"header" like "--uuid:e47f145b-38f7-4402-8eec-657d71bc8ad4..." (see client
request below), i.e. besides XML part there is some special info...

It looks like this special info causes error reply from server "Content is
not allowed in prolog" (see server response below), i.e. server is not
expecting such body. What is interesting here is that if I generate stubs
using XMLBEANS for databinding everything starts to work just fine (and
there is no such "special" info in request body, only XML). After some
googling I suspect that my client for some reason tries to use MTOM (with
JAXB) and I don't know how to turn it off. I've already tried the following
to turn MTOM off (with no luck):

((BindingProvider)port).getRequestContext().put("mtom-enabled",
Boolean.FALSE);
((BindingProvider)port).getRequestContext().put("write.attachments",
Boolean.FALSE);
((BindingProvider)port).setMTOMEnabled(false);

Please help I would really want to move to JAXB since it's much more compact
in comparison with XMLBEANS...

*Client code:*

AdminServiceV2 ws = new AdminServiceV2();
AdminV2 port = ws.getAdminPortV2();

Client client = ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit) client.getConduit();

AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
authorizationPolicy.setUserName("user1");
authorizationPolicy.setPassword("password1");
authorizationPolicy.setAuthorizationType("Basic");
http.setAuthorization(authorizationPolicy); 

try {
    port.getUsersInfo("user1");
} catch (Exception e) {
    e.printStackTrace();
}

*Client request:*

--uuid:e47f145b-38f7-4402-8eec-657d71bc8ad4
Content-Type: text/xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: <ro...@cxf.apache.org>

<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:getUsersInfo
xmlns:ns2="http://service.admin.ws.five9.com/v2/"><userNamePattern>user1</userNamePattern></ns2:getUsersInfo></soap:Body></soap:Envelope>
--uuid:e47f145b-38f7-4402-8eec-657d71bc8ad4--

*Server response:*

<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header></env:Header><env:Body><env:Fault
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><faultcode>env:Client</faultcode><faultstring>org.xml.sax.SAXParseException:
Content is not allowed in
prolog.</faultstring></env:Fault></env:Body></env:Envelope>

Thanks, 
Konstantin



--
View this message in context: http://cxf.547215.n5.nabble.com/Apache-CXF-2-6-1-Client-gets-Content-is-not-allowed-in-prolog-tp5713009.html
Sent from the cxf-dev mailing list archive at Nabble.com.

Re: Apache CXF (2.6.1): Client gets “Content is not allowed in prolog”

Posted by Benson Margulies <bi...@gmail.com>.
This is not MTOM:

Content-Type: text/xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: <ro...@cxf.apache.org>

That's not an MTOM message. See
http://en.wikipedia.org/wiki/XML-binary_Optimized_Packaging for what
one of those looks like. Rather, it appears that something has
discarded the HTTP headers that should proceed your XML.

Re: Apache CXF (2.6.1): Client gets “Content is not allowed in prolog”

Posted by kbabushkin <kb...@hotmail.com>.
Dan,

Many thanks! You saved a lot of my time...
(likely I won't need these methods with swaRefs)

Konstantin



--
View this message in context: http://cxf.547215.n5.nabble.com/Apache-CXF-2-6-1-Client-gets-Content-is-not-allowed-in-prolog-tp5713009p5713055.html
Sent from the cxf-dev mailing list archive at Nabble.com.

Re: Apache CXF (2.6.1): Client gets “Content is not allowed in prolog”

Posted by Daniel Kulp <dk...@apache.org>.
On Aug 23, 2012, at 3:29 PM, kbabushkin <kb...@hotmail.com> wrote:

> Hi Daniel,
> 
> Send sample to your email…


It's definitely the WSDL.   The wsdl uses various types from the soap/w attachment schemas and spec:

http://ws-i.org/profiles/basic/1.1/swaref.xsd
….
<xs:element minOccurs='0' name='wavFile' type='swaRef:swaRef'/>
etc…

With that, we have to setup the attachment stuff "just in case" as we won't know ahead of time whether the types will be hitting the attachment stuff or not.   

The only workaround I have right now is to remove the SwaOutInterceptor:
        Client client = ClientProxy.getClient(port);
        for (Interceptor<?> i : client.getEndpoint().getOutInterceptors()) {
            if (i instanceof SwAOutInterceptor) {
                client.getEndpoint().getOutInterceptors().remove(i);
            }
        }

which is where we check the JAXBContext to see if swa is used or not.   However, if you then invoke one of the operations for which it's required, you'll likely have other failures as the attachments won't be able to be written.


Dan



> 
> Many thanks,
> Konstantin
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Apache-CXF-2-6-1-Client-gets-Content-is-not-allowed-in-prolog-tp5713009p5713049.html
> Sent from the cxf-dev mailing list archive at Nabble.com.

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Re: Apache CXF (2.6.1): Client gets “Content is not allowed in prolog”

Posted by kbabushkin <kb...@hotmail.com>.
Hi Daniel,

Send sample to your email...

Many thanks,
Konstantin



--
View this message in context: http://cxf.547215.n5.nabble.com/Apache-CXF-2-6-1-Client-gets-Content-is-not-allowed-in-prolog-tp5713009p5713049.html
Sent from the cxf-dev mailing list archive at Nabble.com.

Re: Apache CXF (2.6.1): Client gets “Content is not allowed in prolog”

Posted by Daniel Kulp <dk...@apache.org>.
Any chance you can create a small sample that shows the problem with the generated messages?  Without a sample, I'm really not sure what I can suggest.

Dan



On Aug 22, 2012, at 10:26 PM, kbabushkin <kb...@hotmail.com> wrote:

> Hello,
> 
> I'm using Apache CXF (2.6.1) in my java application to consume 3rd party Web
> Service. But I have a problem with it, in particular if I use JAXB for
> databinding while stubs generation my client will always send requests with
> "header" like "--uuid:e47f145b-38f7-4402-8eec-657d71bc8ad4..." (see client
> request below), i.e. besides XML part there is some special info...
> 
> It looks like this special info causes error reply from server "Content is
> not allowed in prolog" (see server response below), i.e. server is not
> expecting such body. What is interesting here is that if I generate stubs
> using XMLBEANS for databinding everything starts to work just fine (and
> there is no such "special" info in request body, only XML). After some
> googling I suspect that my client for some reason tries to use MTOM (with
> JAXB) and I don't know how to turn it off. I've already tried the following
> to turn MTOM off (with no luck):
> 
> ((BindingProvider)port).getRequestContext().put("mtom-enabled",
> Boolean.FALSE);
> ((BindingProvider)port).getRequestContext().put("write.attachments",
> Boolean.FALSE);
> ((BindingProvider)port).setMTOMEnabled(false);
> 
> Please help I would really want to move to JAXB since it's much more compact
> in comparison with XMLBEANS...
> 
> *Client code:*
> 
> AdminServiceV2 ws = new AdminServiceV2();
> AdminV2 port = ws.getAdminPortV2();
> 
> Client client = ClientProxy.getClient(port);
> HTTPConduit http = (HTTPConduit) client.getConduit();
> 
> AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
> authorizationPolicy.setUserName("user1");
> authorizationPolicy.setPassword("password1");
> authorizationPolicy.setAuthorizationType("Basic");
> http.setAuthorization(authorizationPolicy); 
> 
> try {
>    port.getUsersInfo("user1");
> } catch (Exception e) {
>    e.printStackTrace();
> }
> 
> *Client request:*
> 
> --uuid:e47f145b-38f7-4402-8eec-657d71bc8ad4
> Content-Type: text/xml; charset=UTF-8; type="text/xml";
> Content-Transfer-Encoding: binary
> Content-ID: <ro...@cxf.apache.org>
> 
> <soap:Envelope
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:getUsersInfo
> xmlns:ns2="http://service.admin.ws.five9.com/v2/"><userNamePattern>user1</userNamePattern></ns2:getUsersInfo></soap:Body></soap:Envelope>
> --uuid:e47f145b-38f7-4402-8eec-657d71bc8ad4--
> 
> *Server response:*
> 
> <env:Envelope
> xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header></env:Header><env:Body><env:Fault
> xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><faultcode>env:Client</faultcode><faultstring>org.xml.sax.SAXParseException:
> Content is not allowed in
> prolog.</faultstring></env:Fault></env:Body></env:Envelope>
> 
> Thanks, 
> Konstantin
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Apache-CXF-2-6-1-Client-gets-Content-is-not-allowed-in-prolog-tp5713009.html
> Sent from the cxf-dev mailing list archive at Nabble.com.

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com