You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by David Nedrow <Da...@voxmobile.com> on 2013/05/23 19:27:29 UTC

CXF client expects namespace, server doesn't send one.

I have a problem in which CXF generated client code expects a namespace as part of the web-service response. However, the web-service does not include a namespace as part of the response. This causes an unexpected element error. How can I configure the client to ignore the missing namespace? Plain old java, no Spring.

Here's a snippet of the exception the client throws... Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Unexpected wrapper element getResponse found.   Expected {http://www.service-now.com/fooservice}getResponse.

RE: CXF client expects namespace, server doesn't send one.

Posted by David Nedrow <Da...@voxmobile.com>.
And here's the preamble for the wsdl..

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
    xmlns:tns="http://www.service-now.com/fooservice"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
    <wsdl:types>
        <xsd:schema
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            elementFormDefault="unqualified"
            targetNamespace="http://www.service-now.com/fooservice">
            <xsd:element
                name="getKeys">

-----Original Message-----
From: David Nedrow 
Sent: Thursday, May 23, 2013 14:37
To: users@cxf.apache.org
Subject: RE: CXF client expects namespace, server doesn't send one.

Doing this WSDL first. I pulled the WSDL directly from the server. I had actually found the thread you linked to, but it isn't much help. A lot of people talk about modifying the @WebParam annotation, but the CXF wsdl2java doesn't generate any @WebParams.


Here's a sample of the generated client code...


package com.service_now.fooservice;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;


/**
 * <p>Java class for anonymous complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType>
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="sys_id" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *         &lt;element name="__use_view" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "sysId",
    "useView"
})
@XmlRootElement(name = "get")
public class Get {

    @XmlElement(name = "sys_id", required = true)
    protected String sysId;
    @XmlElement(name = "__use_view")
    protected String useView;

    /**
     * Gets the value of the sysId property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getSysId() {
        return sysId;
    }

    /**
     * Sets the value of the sysId property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setSysId(String value) {
        this.sysId = value;
    }

    /**
     * Gets the value of the useView property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getUseView() {
        return useView;
    }

    /**
     * Sets the value of the useView property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setUseView(String value) {
        this.useView = value;
    }

}

-----Original Message-----
From: Johan Edstrom [mailto:seijoed@gmail.com] 
Sent: Thursday, May 23, 2013 13:38
To: users@cxf.apache.org
Subject: Re: CXF client expects namespace, server doesn't send one.

Are you doing Java first or WSDL first?
An error like this usually indicates that the server or the client is generated against a faulty/changed interface.

http://cxf.547215.n5.nabble.com/Unmarshalling-Error-td4927304.html

On May 23, 2013, at 11:27 AM, David Nedrow <Da...@voxmobile.com> wrote:

> javax.xml.ws.soap.SOAPFaultException: Unexpected wrapper element


RE: CXF client expects namespace, server doesn't send one.

Posted by David Nedrow <Da...@voxmobile.com>.
What changes would need to be made here to get the client to fixed the "found response, expected {com.service_now.fooservice}response" to of error.

    @RequestWrapper(localName = "get", targetNamespace = "http://www.service-now.com/fooservice", className = "com.service_now.fooservice.Get")
    @WebMethod(action = "http://www.service-now.com/fooservice/get")
    @ResponseWrapper(localName = "getResponse", targetNamespace = "http://www.service-now.com/fooservice", className = "com.service_now.fooservice.GetResponse")
    public void get(
        @WebParam(mode = WebParam.Mode.INOUT, name = "sys_id", targetNamespace = "")
        javax.xml.ws.Holder<java.lang.String> sysId,
        @WebParam(name = "__use_view", targetNamespace = "")
        java.lang.String useView,
        @WebParam(mode = WebParam.Mode.OUT, name = "asset", targetNamespace = "")
        javax.xml.ws.Holder<java.lang.String> asset,
        @WebParam(mode = WebParam.Mode.OUT, name = "asset_tag", targetNamespace = "")

-----Original Message-----
From: David Nedrow 
Sent: Thursday, May 23, 2013 14:45
To: users@cxf.apache.org
Subject: RE: CXF client expects namespace, server doesn't send one.

Now there's a clue. There is a WebParam annotation, but it defines empty values. From the interface file...

@WebService(targetNamespace = "http://www.service-now.com/fooservice", name = "ServiceNowSoap")
@XmlSeeAlso({ObjectFactory.class})
public interface ServiceNowSoap {

    @WebResult(name = "getRecordsResult", targetNamespace = "")
    @RequestWrapper(localName = "getRecords", targetNamespace = "http://www.service-now.com/ fooservice ", className = "com.service_now. fooservice.GetRecords")
    @WebMethod(action = "http://www.service-now.com/ fooservice /getRecords")
    @ResponseWrapper(localName = "getRecordsResponse", targetNamespace = "http://www.service-now.com/ fooservice ", className = "com.service_now. fooservice.GetRecordsResponse")
    public java.util.List<com.service_now.cmdb_ci_comm.GetRecordsResponse.GetRecordsResult> getRecords(
        @WebParam(name = "asset", targetNamespace = "")

-----Original Message-----
From: Johan Edstrom [mailto:seijoed@gmail.com] 
Sent: Thursday, May 23, 2013 14:39
To: users@cxf.apache.org
Subject: Re: CXF client expects namespace, server doesn't send one.

Ouch, then it kinda sorta looks like the server might be wrong.
You'd find the WebParams in the generated interface class.


On May 23, 2013, at 12:37 PM, David Nedrow <Da...@voxmobile.com> wrote:

> Doing this WSDL first. I pulled the WSDL directly from the server. I had actually found the thread you linked to, but it isn't much help. A lot of people talk about modifying the @WebParam annotation, but the CXF wsdl2java doesn't generate any @WebParams.
> 
> Here's a sample of the generated client code...
> 
> 
> package com.service_now.fooservice;
> 
> import javax.xml.bind.annotation.XmlAccessType;
> import javax.xml.bind.annotation.XmlAccessorType;
> import javax.xml.bind.annotation.XmlElement;
> import javax.xml.bind.annotation.XmlRootElement;
> import javax.xml.bind.annotation.XmlType;
> 
> 
> /**
> * <p>Java class for anonymous complex type.
> * 
> * <p>The following schema fragment specifies the expected content contained within this class.
> * 
> * <pre>
> * &lt;complexType>
> *   &lt;complexContent>
> *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
> *       &lt;sequence>
> *         &lt;element name="sys_id" type="{http://www.w3.org/2001/XMLSchema}string"/>
> *         &lt;element name="__use_view" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
> *       &lt;/sequence>
> *     &lt;/restriction>
> *   &lt;/complexContent>
> * &lt;/complexType>
> * </pre>
> * 
> * 
> */
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "", propOrder = {
>    "sysId",
>    "useView"
> })
> @XmlRootElement(name = "get")
> public class Get {
> 
>    @XmlElement(name = "sys_id", required = true)
>    protected String sysId;
>    @XmlElement(name = "__use_view")
>    protected String useView;
> 
>    /**
>     * Gets the value of the sysId property.
>     * 
>     * @return
>     *     possible object is
>     *     {@link String }
>     *     
>     */
>    public String getSysId() {
>        return sysId;
>    }
> 
>    /**
>     * Sets the value of the sysId property.
>     * 
>     * @param value
>     *     allowed object is
>     *     {@link String }
>     *     
>     */
>    public void setSysId(String value) {
>        this.sysId = value;
>    }
> 
>    /**
>     * Gets the value of the useView property.
>     * 
>     * @return
>     *     possible object is
>     *     {@link String }
>     *     
>     */
>    public String getUseView() {
>        return useView;
>    }
> 
>    /**
>     * Sets the value of the useView property.
>     * 
>     * @param value
>     *     allowed object is
>     *     {@link String }
>     *     
>     */
>    public void setUseView(String value) {
>        this.useView = value;
>    }
> 
> }
> 
> -----Original Message-----
> From: Johan Edstrom [mailto:seijoed@gmail.com] 
> Sent: Thursday, May 23, 2013 13:38
> To: users@cxf.apache.org
> Subject: Re: CXF client expects namespace, server doesn't send one.
> 
> Are you doing Java first or WSDL first?
> An error like this usually indicates that the server or the client is generated against a faulty/changed interface.
> 
> http://cxf.547215.n5.nabble.com/Unmarshalling-Error-td4927304.html
> 
> On May 23, 2013, at 11:27 AM, David Nedrow <Da...@voxmobile.com> wrote:
> 
>> javax.xml.ws.soap.SOAPFaultException: Unexpected wrapper element
> 


RE: CXF client expects namespace, server doesn't send one.

Posted by David Nedrow <Da...@voxmobile.com>.
Now there's a clue. There is a WebParam annotation, but it defines empty values. From the interface file...

@WebService(targetNamespace = "http://www.service-now.com/fooservice", name = "ServiceNowSoap")
@XmlSeeAlso({ObjectFactory.class})
public interface ServiceNowSoap {

    @WebResult(name = "getRecordsResult", targetNamespace = "")
    @RequestWrapper(localName = "getRecords", targetNamespace = "http://www.service-now.com/ fooservice ", className = "com.service_now. fooservice.GetRecords")
    @WebMethod(action = "http://www.service-now.com/ fooservice /getRecords")
    @ResponseWrapper(localName = "getRecordsResponse", targetNamespace = "http://www.service-now.com/ fooservice ", className = "com.service_now. fooservice.GetRecordsResponse")
    public java.util.List<com.service_now.cmdb_ci_comm.GetRecordsResponse.GetRecordsResult> getRecords(
        @WebParam(name = "asset", targetNamespace = "")

-----Original Message-----
From: Johan Edstrom [mailto:seijoed@gmail.com] 
Sent: Thursday, May 23, 2013 14:39
To: users@cxf.apache.org
Subject: Re: CXF client expects namespace, server doesn't send one.

Ouch, then it kinda sorta looks like the server might be wrong.
You'd find the WebParams in the generated interface class.


On May 23, 2013, at 12:37 PM, David Nedrow <Da...@voxmobile.com> wrote:

> Doing this WSDL first. I pulled the WSDL directly from the server. I had actually found the thread you linked to, but it isn't much help. A lot of people talk about modifying the @WebParam annotation, but the CXF wsdl2java doesn't generate any @WebParams.
> 
> Here's a sample of the generated client code...
> 
> 
> package com.service_now.fooservice;
> 
> import javax.xml.bind.annotation.XmlAccessType;
> import javax.xml.bind.annotation.XmlAccessorType;
> import javax.xml.bind.annotation.XmlElement;
> import javax.xml.bind.annotation.XmlRootElement;
> import javax.xml.bind.annotation.XmlType;
> 
> 
> /**
> * <p>Java class for anonymous complex type.
> * 
> * <p>The following schema fragment specifies the expected content contained within this class.
> * 
> * <pre>
> * &lt;complexType>
> *   &lt;complexContent>
> *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
> *       &lt;sequence>
> *         &lt;element name="sys_id" type="{http://www.w3.org/2001/XMLSchema}string"/>
> *         &lt;element name="__use_view" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
> *       &lt;/sequence>
> *     &lt;/restriction>
> *   &lt;/complexContent>
> * &lt;/complexType>
> * </pre>
> * 
> * 
> */
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "", propOrder = {
>    "sysId",
>    "useView"
> })
> @XmlRootElement(name = "get")
> public class Get {
> 
>    @XmlElement(name = "sys_id", required = true)
>    protected String sysId;
>    @XmlElement(name = "__use_view")
>    protected String useView;
> 
>    /**
>     * Gets the value of the sysId property.
>     * 
>     * @return
>     *     possible object is
>     *     {@link String }
>     *     
>     */
>    public String getSysId() {
>        return sysId;
>    }
> 
>    /**
>     * Sets the value of the sysId property.
>     * 
>     * @param value
>     *     allowed object is
>     *     {@link String }
>     *     
>     */
>    public void setSysId(String value) {
>        this.sysId = value;
>    }
> 
>    /**
>     * Gets the value of the useView property.
>     * 
>     * @return
>     *     possible object is
>     *     {@link String }
>     *     
>     */
>    public String getUseView() {
>        return useView;
>    }
> 
>    /**
>     * Sets the value of the useView property.
>     * 
>     * @param value
>     *     allowed object is
>     *     {@link String }
>     *     
>     */
>    public void setUseView(String value) {
>        this.useView = value;
>    }
> 
> }
> 
> -----Original Message-----
> From: Johan Edstrom [mailto:seijoed@gmail.com] 
> Sent: Thursday, May 23, 2013 13:38
> To: users@cxf.apache.org
> Subject: Re: CXF client expects namespace, server doesn't send one.
> 
> Are you doing Java first or WSDL first?
> An error like this usually indicates that the server or the client is generated against a faulty/changed interface.
> 
> http://cxf.547215.n5.nabble.com/Unmarshalling-Error-td4927304.html
> 
> On May 23, 2013, at 11:27 AM, David Nedrow <Da...@voxmobile.com> wrote:
> 
>> javax.xml.ws.soap.SOAPFaultException: Unexpected wrapper element
> 


Re: CXF client expects namespace, server doesn't send one.

Posted by Johan Edstrom <se...@gmail.com>.
Ouch, then it kinda sorta looks like the server might be wrong.
You'd find the WebParams in the generated interface class.


On May 23, 2013, at 12:37 PM, David Nedrow <Da...@voxmobile.com> wrote:

> Doing this WSDL first. I pulled the WSDL directly from the server. I had actually found the thread you linked to, but it isn't much help. A lot of people talk about modifying the @WebParam annotation, but the CXF wsdl2java doesn't generate any @WebParams.
> 
> Here's a sample of the generated client code...
> 
> 
> package com.service_now.fooservice;
> 
> import javax.xml.bind.annotation.XmlAccessType;
> import javax.xml.bind.annotation.XmlAccessorType;
> import javax.xml.bind.annotation.XmlElement;
> import javax.xml.bind.annotation.XmlRootElement;
> import javax.xml.bind.annotation.XmlType;
> 
> 
> /**
> * <p>Java class for anonymous complex type.
> * 
> * <p>The following schema fragment specifies the expected content contained within this class.
> * 
> * <pre>
> * &lt;complexType>
> *   &lt;complexContent>
> *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
> *       &lt;sequence>
> *         &lt;element name="sys_id" type="{http://www.w3.org/2001/XMLSchema}string"/>
> *         &lt;element name="__use_view" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
> *       &lt;/sequence>
> *     &lt;/restriction>
> *   &lt;/complexContent>
> * &lt;/complexType>
> * </pre>
> * 
> * 
> */
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "", propOrder = {
>    "sysId",
>    "useView"
> })
> @XmlRootElement(name = "get")
> public class Get {
> 
>    @XmlElement(name = "sys_id", required = true)
>    protected String sysId;
>    @XmlElement(name = "__use_view")
>    protected String useView;
> 
>    /**
>     * Gets the value of the sysId property.
>     * 
>     * @return
>     *     possible object is
>     *     {@link String }
>     *     
>     */
>    public String getSysId() {
>        return sysId;
>    }
> 
>    /**
>     * Sets the value of the sysId property.
>     * 
>     * @param value
>     *     allowed object is
>     *     {@link String }
>     *     
>     */
>    public void setSysId(String value) {
>        this.sysId = value;
>    }
> 
>    /**
>     * Gets the value of the useView property.
>     * 
>     * @return
>     *     possible object is
>     *     {@link String }
>     *     
>     */
>    public String getUseView() {
>        return useView;
>    }
> 
>    /**
>     * Sets the value of the useView property.
>     * 
>     * @param value
>     *     allowed object is
>     *     {@link String }
>     *     
>     */
>    public void setUseView(String value) {
>        this.useView = value;
>    }
> 
> }
> 
> -----Original Message-----
> From: Johan Edstrom [mailto:seijoed@gmail.com] 
> Sent: Thursday, May 23, 2013 13:38
> To: users@cxf.apache.org
> Subject: Re: CXF client expects namespace, server doesn't send one.
> 
> Are you doing Java first or WSDL first?
> An error like this usually indicates that the server or the client is generated against a faulty/changed interface.
> 
> http://cxf.547215.n5.nabble.com/Unmarshalling-Error-td4927304.html
> 
> On May 23, 2013, at 11:27 AM, David Nedrow <Da...@voxmobile.com> wrote:
> 
>> javax.xml.ws.soap.SOAPFaultException: Unexpected wrapper element
> 


RE: CXF client expects namespace, server doesn't send one.

Posted by David Nedrow <Da...@voxmobile.com>.
Doing this WSDL first. I pulled the WSDL directly from the server. I had actually found the thread you linked to, but it isn't much help. A lot of people talk about modifying the @WebParam annotation, but the CXF wsdl2java doesn't generate any @WebParams.

Here's a sample of the generated client code...


package com.service_now.fooservice;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;


/**
 * <p>Java class for anonymous complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType>
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="sys_id" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *         &lt;element name="__use_view" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "sysId",
    "useView"
})
@XmlRootElement(name = "get")
public class Get {

    @XmlElement(name = "sys_id", required = true)
    protected String sysId;
    @XmlElement(name = "__use_view")
    protected String useView;

    /**
     * Gets the value of the sysId property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getSysId() {
        return sysId;
    }

    /**
     * Sets the value of the sysId property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setSysId(String value) {
        this.sysId = value;
    }

    /**
     * Gets the value of the useView property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getUseView() {
        return useView;
    }

    /**
     * Sets the value of the useView property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setUseView(String value) {
        this.useView = value;
    }

}

-----Original Message-----
From: Johan Edstrom [mailto:seijoed@gmail.com] 
Sent: Thursday, May 23, 2013 13:38
To: users@cxf.apache.org
Subject: Re: CXF client expects namespace, server doesn't send one.

Are you doing Java first or WSDL first?
An error like this usually indicates that the server or the client is generated against a faulty/changed interface.

http://cxf.547215.n5.nabble.com/Unmarshalling-Error-td4927304.html

On May 23, 2013, at 11:27 AM, David Nedrow <Da...@voxmobile.com> wrote:

> javax.xml.ws.soap.SOAPFaultException: Unexpected wrapper element


Re: CXF client expects namespace, server doesn't send one.

Posted by Johan Edstrom <se...@gmail.com>.
Are you doing Java first or WSDL first?
An error like this usually indicates that the server or the client is generated against
a faulty/changed interface.

http://cxf.547215.n5.nabble.com/Unmarshalling-Error-td4927304.html

On May 23, 2013, at 11:27 AM, David Nedrow <Da...@voxmobile.com> wrote:

> javax.xml.ws.soap.SOAPFaultException: Unexpected wrapper element


Re: CXF client expects namespace, server doesn't send one.

Posted by Bill Nash <bi...@billn.net>.
> On May 23, 2013, at 1:27 PM, David Nedrow <Da...@...> wrote:
> However, the web-service does not include a namespace as part of the response.

Relevant:
http://wiki.servicenow.com/index.php?title=Direct_Web_Services#elementFormDefault

This affects compatibility with WSDL-generated interfaces.

- billn


Re: CXF client expects namespace, server doesn't send one.

Posted by Daniel Kulp <dk...@apache.org>.
On May 23, 2013, at 1:27 PM, David Nedrow <Da...@voxmobile.com> wrote:

> I have a problem in which CXF generated client code expects a namespace as part of the web-service response. However, the web-service does not include a namespace as part of the response. This causes an unexpected element error. How can I configure the client to ignore the missing namespace? Plain old java, no Spring.
> 
> Here's a snippet of the exception the client throws... Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Unexpected wrapper element getResponse found.   Expected {http://www.service-now.com/fooservice}getResponse.

This LOOKS like the server is generating an invalid soap message.   Any chance of seeing the soap message?  At least the body and immediate children?

Per SOAP spec, the immediate children of the SOAP:Body element must be qualified.  However, it looks like your server is sending back a plain "<getReponse>" element that isn't qualified.  If that's the case, there isn't an easy way to get CXF to use it as CXF would set itself up to generate and accept valid messages.  You MAY be able to use the cxf transform feature (http://cxf.apache.org/docs/transformationfeature.html) to add namespaces to the elements as they come in.   That may work.


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