You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by dave derry <dd...@acm.org> on 2009/10/07 20:46:31 UTC

How to specify content-type?

I'm trying to create a SOAP client for an existing web service. I used the
wsdl2java utility to generate a client from the project's wsdl. I am able to
populate a request, but when I submit it (running in Eclipse) I am getting a
415 response code. When I check the application log it indicates
"Unsupported Content-Type: application/x-www-form-urlencoded Supported ones
are: [text/xml]".

I have searched for how to set the content-type, but haven't been able to
find anything useful. I'm using CXF 2.2. Is there an easy way to accomplish
this?

Thanks,
Dave Derry
-- 
View this message in context: http://www.nabble.com/How-to-specify-content-type--tp25791924p25791924.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to specify content-type?

Posted by Daniel Kulp <dk...@apache.org>.

This is a GET request.   Thus, it kind of looks to me like this is asking for 
the WSDL or similar, not actually a request.

Check the value of:
NCPlusOnlineInquiryService.WSDL_LOCATION
to make sure it's either a location that is local (like file://....) or would 
have ?wsdl appended or similar to actually point at the wsdl.

Dan





On Thu October 8 2009 9:30:26 am dave derry wrote:
> I get scared when I read "There really isn't any way that ..."  ;-}
> But in this case you are correct. The data captured (edited for readability
> is:
> 
> GET /NCPlusOnlineInquiryService/NCPlusOnlineInquiryServicePort/1.0.0.0
> HTTP/1.1..
> User-Agent: Java/1.5.0_09
> Host:  devhost.ec.equifax.com:7965
> Accept: text/html, image/gif, image/jpeg, *;
> q= .2, */*; q=.2..
> Connection: keep- alive.
> Content-type: application/x-www-form-urlencoded..
> 
> 
> So it is *not* being sent as a SOAP message. After posting my original
> message I found the doc on creating a CXF configuration file, but that
> didn't make any difference. I then realized that although CXF was used to
> generate the skeleton for this app, the project has no dependencies on CXF.
> Here is the output of 'mvn dependency:tree' :
> 
> [INFO] [dependency:tree]
> [INFO] com.efx.ncplus:NCPlusClient:jar:1.0-SNAPSHOT
> [INFO] +- stax:stax:jar:1.2.0:runtime
> [INFO] |  \- stax:stax-api:jar:1.0.1:runtime
> [INFO] +- javax.xml.bind:jaxb-api:jar:2.2:compile
> [INFO] |  +- javax.xml.stream:stax-api:jar:1.0-2:compile
> [INFO] |  \- javax.activation:activation:jar:1.1:compile
> [INFO] +- javax.xml.ws:jaxws-api:jar:2.1-1:compile
> [INFO] |  +- javax.xml.soap:saaj-api:jar:1.3:compile
> [INFO] |  +- javax.annotation:jsr250-api:jar:1.0:compile
> [INFO] |  \- javax.jws:jsr181-api:jar:1.0-MR1:compile
> [INFO] +- com.sun.xml.bind:jaxb-impl:jar:2.1.12:runtime
> [INFO] +- com.sun.xml.stream.buffer:streambuffer:jar:0.8:runtime
> [INFO] |  \- org.jvnet.staxex:stax-ex:jar:1.2:runtime
> [INFO] |     \- junit:junit:jar:3.8:runtime
> [INFO] +- com.sun.xml.bind:jaxb-xjc:jar:2.1.12:runtime
> [INFO] +- com.sun.xml.ws:jaxws-rt:jar:2.1EA1:runtime
> [INFO] \- com.sun.xml.messaging.saaj:saaj-impl:jar:1.3:runtime
> 
> 
> And here is a portion of the client code:
> 
> public final class
> NCPlusOnlineInquiryServicePortType_NCPlusOnlineInquiryServicePort_Client
> {
> 
>     private static final QName SERVICE_NAME = new
> QName("http://services.equifax.com/gds/ncplus/servicedefs",
> 
> "NCPlusOnlineInquiryService");
> 
>     private
> NCPlusOnlineInquiryServicePortType_NCPlusOnlineInquiryServicePort_Client()
>     {
>     }
> 
>     public static void main(String args[]) throws Exception
>     {
>         URL wsdlURL = NCPlusOnlineInquiryService.WSDL_LOCATION;
>         // setting wsdlURL from args cut
> 
>         NCPlusOnlineInquiryService ss = new
> NCPlusOnlineInquiryService(wsdlURL, SERVICE_NAME);
>         NCPlusOnlineInquiryServicePortType port =
> ss.getNCPlusOnlineInquiryServicePort();
> 
>         {
>             System.out.println("Invoking getAccountsInformation at " +
> wsdlURL + "...");
>             InquiryRequestType request = new InquiryRequestType();
>             InquiryRequestHeaderType header = new
> InquiryRequestHeaderType();
>             header.setCustRefField("1234");
>             header.setSecCode("901");
>             header.setMemberNbr("999EP00001");
>             request.setInquiryRequestHeader(header);
>             InquiryResponseType response =
> port.getAccountsInformation(request);
>             System.out.println("getAccountsInformation.result=" +
>  response);
> 
>         }
> 
>         System.exit(0);
>     }
> 
> }
> 
> 
> OK, clearly I've done something wrong, but being a newbie to CXF, I have no
> clue what it is.
> 
> Dave
> 
> dkulp wrote:
> > Any chance you could wireshark this to see what really is being sent on
> > the
> > wire.   There really isn't any way that CXF should be sending that
> > content-
> > type for a soap message.
> >
> > Note: also update to 2.2.3 if possible. (and 2.2.4 will be out early next
> > week)
> >
> > Dan
> 

-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog

Re: How to specify content-type?

Posted by dave derry <dd...@acm.org>.
I get scared when I read "There really isn't any way that ..."  ;-}
But in this case you are correct. The data captured (edited for readability
is:

GET /NCPlusOnlineInquiryService/NCPlusOnlineInquiryServicePort/1.0.0.0 
HTTP/1.1..
User-Agent: Java/1.5.0_09
Host:  devhost.ec.equifax.com:7965
Accept: text/html, image/gif, image/jpeg, *; 
q= .2, */*; q=.2..
Connection: keep- alive.
Content-type: application/x-www-form-urlencoded..


So it is *not* being sent as a SOAP message. After posting my original
message I found the doc on creating a CXF configuration file, but that
didn't make any difference. I then realized that although CXF was used to
generate the skeleton for this app, the project has no dependencies on CXF.
Here is the output of 'mvn dependency:tree' :

[INFO] [dependency:tree]
[INFO] com.efx.ncplus:NCPlusClient:jar:1.0-SNAPSHOT
[INFO] +- stax:stax:jar:1.2.0:runtime
[INFO] |  \- stax:stax-api:jar:1.0.1:runtime
[INFO] +- javax.xml.bind:jaxb-api:jar:2.2:compile
[INFO] |  +- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] |  \- javax.activation:activation:jar:1.1:compile
[INFO] +- javax.xml.ws:jaxws-api:jar:2.1-1:compile
[INFO] |  +- javax.xml.soap:saaj-api:jar:1.3:compile
[INFO] |  +- javax.annotation:jsr250-api:jar:1.0:compile
[INFO] |  \- javax.jws:jsr181-api:jar:1.0-MR1:compile
[INFO] +- com.sun.xml.bind:jaxb-impl:jar:2.1.12:runtime
[INFO] +- com.sun.xml.stream.buffer:streambuffer:jar:0.8:runtime
[INFO] |  \- org.jvnet.staxex:stax-ex:jar:1.2:runtime
[INFO] |     \- junit:junit:jar:3.8:runtime
[INFO] +- com.sun.xml.bind:jaxb-xjc:jar:2.1.12:runtime
[INFO] +- com.sun.xml.ws:jaxws-rt:jar:2.1EA1:runtime
[INFO] \- com.sun.xml.messaging.saaj:saaj-impl:jar:1.3:runtime


And here is a portion of the client code:

public final class
NCPlusOnlineInquiryServicePortType_NCPlusOnlineInquiryServicePort_Client
{

    private static final QName SERVICE_NAME = new
QName("http://services.equifax.com/gds/ncplus/servicedefs",
                                                       
"NCPlusOnlineInquiryService");

    private
NCPlusOnlineInquiryServicePortType_NCPlusOnlineInquiryServicePort_Client()
    {
    }

    public static void main(String args[]) throws Exception
    {
        URL wsdlURL = NCPlusOnlineInquiryService.WSDL_LOCATION;
        // setting wsdlURL from args cut

        NCPlusOnlineInquiryService ss = new
NCPlusOnlineInquiryService(wsdlURL, SERVICE_NAME);
        NCPlusOnlineInquiryServicePortType port =
ss.getNCPlusOnlineInquiryServicePort();

        {
            System.out.println("Invoking getAccountsInformation at " +
wsdlURL + "...");
            InquiryRequestType request = new InquiryRequestType();
            InquiryRequestHeaderType header = new
InquiryRequestHeaderType();
            header.setCustRefField("1234");
            header.setSecCode("901");
            header.setMemberNbr("999EP00001");
            request.setInquiryRequestHeader(header);
            InquiryResponseType response =
port.getAccountsInformation(request);
            System.out.println("getAccountsInformation.result=" + response);

        }

        System.exit(0);
    }

}


OK, clearly I've done something wrong, but being a newbie to CXF, I have no
clue what it is.

Dave




dkulp wrote:
> 
> 
> Any chance you could wireshark this to see what really is being sent on
> the 
> wire.   There really isn't any way that CXF should be sending that
> content-
> type for a soap message.   
> 
> Note: also update to 2.2.3 if possible. (and 2.2.4 will be out early next 
> week)
> 
> Dan
> 
> 
> -- 
> Daniel Kulp
> dkulp@apache.org
> http://www.dankulp.com/blog
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-specify-content-type--tp25791924p25802987.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to specify content-type?

Posted by dave derry <dd...@acm.org>.
Oh, and here's the wsdl:

<definitions name="WSDNCPlusOnlineInquiryService"
targetNamespace="http://services.equifax.com/gds/ncplus/servicedefs"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:tns="http://services.equifax.com/gds/ncplus/servicedefs" 
    xmlns:ns="http://services.equifax.com/gds/ncplus/online/schemas" 
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
    <types>
        <xsd:schema
targetNamespace="http://services.equifax.com/gds/ncplus/servicedefs">
            <xsd:import
namespace="http://services.equifax.com/gds/ncplus/online/schemas" 
            schemaLocation="NCPlusOnlineInquiry-1.0.0.0.xsd"/>
        </xsd:schema>
    </types>
    <message name="ConsumerInquiryRequest">
        <part name="Input" element="ns:InquiryRequest"/>
    </message>
    <message name="ConsumerInquiryResponse">
        <part name="Output" element="ns:InquiryResponse"/>
    </message>
    <portType name="NCPlusOnlineInquiryServicePortType">
        <operation name="GetAccountsInformation">
            <input name="request" message="tns:ConsumerInquiryRequest"/>
            <output name="response" message="tns:ConsumerInquiryResponse"/>
        </operation>
    </portType>
    <binding name="NCPlusOnlineInquiryServiceBinding"
type="tns:NCPlusOnlineInquiryServicePortType">
        <soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="GetAccountsInformation">
            <soap:operation/>
            <input name="request">
                <soap:body use="literal"/>
            </input>
            <output name="response">
                <soap:body use="literal"/>
            </output>
        </operation>
    </binding>
    <service name="NCPlusOnlineInquiryService">
        <port name="NCPlusOnlineInquiryServicePort"
binding="tns:NCPlusOnlineInquiryServiceBinding">
            <soap:address
location="http://devhost.ec.equifax.com:7965/NCPlusOnlineInquiryService/NCPlusOnlineInquiryServicePort/1.0.0.0"/>
        </port>
    </service>
</definitions>




dkulp wrote:
> 
> 
> Any chance you could wireshark this to see what really is being sent on
> the 
> wire.   There really isn't any way that CXF should be sending that
> content-
> type for a soap message.   
> 
> Note: also update to 2.2.3 if possible. (and 2.2.4 will be out early next 
> week)
> 
> Dan
> 
> 
> 
> -- 
> Daniel Kulp
> dkulp@apache.org
> http://www.dankulp.com/blog
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-specify-content-type--tp25791924p25802990.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to specify content-type?

Posted by dave derry <dd...@acm.org>.
I should have realized after reading that article and learning that the GET
was to retrieve the wsdl that the '?wsdl' query string was required. That
almost works, except that the endpoint URL in that wsdl specifies
'http://sdlc109:.....' instead of a complete
'http://sdlc109.atl.ec...:....'. 

Specifying the ENDPOINT_ADDRESS on the BindingProvider provides the magic
that I needed though.


Thanks,
Dave D



dkulp wrote:
> 
> On Thu October 8 2009 11:46:06 am dave derry wrote:
>> Well I found the problem; thanks to this post
>> http://forums.java.net/jive/message.jspa?messageID=347997, which
>> explained
>> that if specifying a remote host for the wsdl a GET is sent to retrieve
>> the
>> wsdl. 
> 
> You should be able to append ?wsdl to get the wsdl if it's a normal cxf 
> service.
> 
> 
> 
>> Since the host doesn't accept GETs it is necessary for me to specify
>>  a local wsdl file. I was passing a remote host in as an argument because
>>  the local file had an incvalid URL (even though my other post indicated
>>  the valid URL). I modified the local wsdl, and it now seems to be
>> working.
>>  I say "seems" because I am getting a response, but I haven't yet
>> inspected
>>  it.
>> 
>> But that leaves me with a question regarding how would I specify a
>>  different host and/or port than what is specified in the local wsdl?
> 
> Similar to:
> ((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS, 
> "http://......")
> 
> 
> 
> Dan
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-specify-content-type--tp25791924p25821977.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to specify content-type?

Posted by Daniel Kulp <dk...@apache.org>.
On Thu October 8 2009 11:46:06 am dave derry wrote:
> Well I found the problem; thanks to this post
> http://forums.java.net/jive/message.jspa?messageID=347997, which explained
> that if specifying a remote host for the wsdl a GET is sent to retrieve the
> wsdl. 

You should be able to append ?wsdl to get the wsdl if it's a normal cxf 
service.

Dan


> Since the host doesn't accept GETs it is necessary for me to specify
>  a local wsdl file. I was passing a remote host in as an argument because
>  the local file had an incvalid URL (even though my other post indicated
>  the valid URL). I modified the local wsdl, and it now seems to be working.
>  I say "seems" because I am getting a response, but I haven't yet inspected
>  it.
> 
> But that leaves me with a question regarding how would I specify a
>  different host and/or port than what is specified in the local wsdl?

Similar to:
((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS, 
"http://......")



Dan

> 
> 
> Thanks,
> Dave
> 
> dkulp wrote:
> > Any chance you could wireshark this to see what really is being sent on
> > the
> > wire.   There really isn't any way that CXF should be sending that
> > content-
> > type for a soap message.
> >
> > Note: also update to 2.2.3 if possible. (and 2.2.4 will be out early next
> > week)
> >
> > Dan
> 

-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog

Re: How to specify content-type?

Posted by dave derry <dd...@acm.org>.
Well I found the problem; thanks to this post
http://forums.java.net/jive/message.jspa?messageID=347997, which explained
that if specifying a remote host for the wsdl a GET is sent to retrieve the
wsdl. Since the host doesn't accept GETs it is necessary for me to specify a
local wsdl file. I was passing a remote host in as an argument because the
local file had an incvalid URL (even though my other post indicated the
valid URL). I modified the local wsdl, and it now seems to be working. I say
"seems" because I am getting a response, but I haven't yet inspected it.

But that leaves me with a question regarding how would I specify a different
host and/or port than what is specified in the local wsdl?


Thanks,
Dave



dkulp wrote:
> 
> 
> Any chance you could wireshark this to see what really is being sent on
> the 
> wire.   There really isn't any way that CXF should be sending that
> content-
> type for a soap message.   
> 
> Note: also update to 2.2.3 if possible. (and 2.2.4 will be out early next 
> week)
> 
> Dan
> 
> 
> -- 
> Daniel Kulp
> dkulp@apache.org
> http://www.dankulp.com/blog
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-specify-content-type--tp25791924p25803263.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to specify content-type?

Posted by Daniel Kulp <dk...@apache.org>.
Any chance you could wireshark this to see what really is being sent on the 
wire.   There really isn't any way that CXF should be sending that content-
type for a soap message.   

Note: also update to 2.2.3 if possible. (and 2.2.4 will be out early next 
week)

Dan

On Wed October 7 2009 2:46:31 pm dave derry wrote:
> I'm trying to create a SOAP client for an existing web service. I used the
> wsdl2java utility to generate a client from the project's wsdl. I am able
>  to populate a request, but when I submit it (running in Eclipse) I am
>  getting a 415 response code. When I check the application log it indicates
> "Unsupported Content-Type: application/x-www-form-urlencoded Supported ones
> are: [text/xml]".
> 
> I have searched for how to set the content-type, but haven't been able to
> find anything useful. I'm using CXF 2.2. Is there an easy way to accomplish
> this?
> 
> Thanks,
> Dave Derry
> 

-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog