damienbeaufils / soap-client-with-cxf-using-play

Implementing a SOAP client with CXF using Play Framework 2.x
Other
11 stars 6 forks source link

HTTP response '405: Method Not Allowed' #3

Closed inuru closed 8 years ago

inuru commented 8 years ago

I ran into problem when calling http request. turn out HTTP response '405: Method Not Allowed' image

do I need to specify the http request method?, ho do i do it?

here is my WSDL <?xml version="1.0" encoding="UTF-8"?><wsdl:definitions name="GetPayRollList_OB_SI" targetNamespace="urn:gmf-aeroasia.co.id:GetPayRollSlip" xmlns:rfc="urn:sap-com:document:sap:rfc:functions" xmlns:p1="urn:gmf-aeroasia.co.id:GetPayRollSlip" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><wsdl:documentation/><wsp:UsingPolicy wsdl:required="true"/><wsp:Policy wsu:Id="OP_GetPayRollList_OB_SI"/><wsdl:types><xsd:schema targetNamespace="urn:sap-com:document:sap:rfc:functions" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:sap-com:document:sap:rfc:functions"><xsd:element name="BAPI_GET_PAYROLL_RESULT_LIST"><xsd:complexType><xsd:all><xsd:element name="EMPLOYEENUMBER"><xsd:annotation><xsd:documentation>Personnel number</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="8"/><xsd:pattern value="\d+"/></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name="FROMDATE" type="date" minOccurs="0"><xsd:annotation><xsd:documentation>Start of selection period</xsd:documentation></xsd:annotation></xsd:element><xsd:element name="TODATE" type="date" minOccurs="0"><xsd:annotation><xsd:documentation>End of selection period</xsd:documentation></xsd:annotation></xsd:element><xsd:element name="RESULTS"><xsd:annotation><xsd:documentation>Directory of payroll results</xsd:documentation></xsd:annotation><xsd:complexType><xsd:sequence><xsd:element name="item" type="BAPI7004_RL" minOccurs="0" maxOccurs="unbounded"/></xsd:sequence></xsd:complexType></xsd:element></xsd:all></xsd:complexType></xsd:element><xsd:element name="BAPI_GET_PAYROLL_RESULT_LIST.Response"><xsd:complexType><xsd:all><xsd:element name="RETURN" type="BAPIRETURN1" minOccurs="0"><xsd:annotation><xsd:documentation>Messages</xsd:documentation></xsd:annotation></xsd:element><xsd:element name="RESULTS"><xsd:annotation><xsd:documentation>Directory of payroll results</xsd:documentation></xsd:annotation><xsd:complexType><xsd:sequence><xsd:element name="item" type="BAPI7004_RL" minOccurs="0" maxOccurs="unbounded"/></xsd:sequence></xsd:complexType></xsd:element></xsd:all></xsd:complexType></xsd:element><xsd:simpleType name="genericDate"><xsd:restriction base="xsd:string"><xsd:pattern value="....-..-.."/></xsd:restriction></xsd:simpleType><xsd:simpleType name="date"><xsd:union memberTypes="xsd:date genericDate" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:sap-com:document:sap:rfc:functions"/></xsd:simpleType><xsd:complexType name="BAPI7004_RL"><xsd:annotation><xsd:documentation>Directory of payroll results in database</xsd:documentation></xsd:annotation><xsd:sequence><xsd:element name="SEQUENCENUMBER" minOccurs="0"><xsd:annotation><xsd:documentation>Sequence Number</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="5"/><xsd:pattern value="\d+"/></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name="FPPERIOD" minOccurs="0"><xsd:annotation><xsd:documentation>For-period for payroll</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="6"/></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name="FPBEGIN" type="date" minOccurs="0"><xsd:annotation><xsd:documentation>Start date of payroll period (FOR period)</xsd:documentation></xsd:annotation></xsd:element><xsd:element name="FPEND" type="date" minOccurs="0"><xsd:annotation><xsd:documentation>End of payroll period (for-period)</xsd:documentation></xsd:annotation></xsd:element><xsd:element name="BONUSDATE" type="date" minOccurs="0"><xsd:annotation><xsd:documentation>Off-cycle payroll payment date</xsd:documentation></xsd:annotation></xsd:element><xsd:element name="PAYDATE" type="date" minOccurs="0"><xsd:annotation><xsd:documentation>Pay date for payroll result</xsd:documentation></xsd:annotation></xsd:element><xsd:element name="PAYTYPE" minOccurs="0"><xsd:annotation><xsd:documentation>Payroll type</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="1"/></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name="PAYID" minOccurs="0"><xsd:annotation><xsd:documentation>Payroll Identifier</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="1"/></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name="OCREASON" minOccurs="0"><xsd:annotation><xsd:documentation>Reason for Off-Cycle Payroll</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="4"/></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name="PAYTYPE_TEXT" minOccurs="0"><xsd:annotation><xsd:documentation>Short Text for Fixed Values</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="60"/></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name="OCREASON_TEXT" minOccurs="0"><xsd:annotation><xsd:documentation>Text, 40 Characters Long</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="40"/></xsd:restriction></xsd:simpleType></xsd:element></xsd:sequence></xsd:complexType><xsd:complexType name="BAPIRETURN1"><xsd:annotation><xsd:documentation>Return Parameter</xsd:documentation></xsd:annotation><xsd:sequence><xsd:element name="TYPE" minOccurs="0"><xsd:annotation><xsd:documentation>Message type: S Success, E Error, W Warning, I Info, A Abort</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="1"/></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name="ID" minOccurs="0"><xsd:annotation><xsd:documentation>Message Class</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="20"/></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name="NUMBER" minOccurs="0"><xsd:annotation><xsd:documentation>Message Number</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="3"/><xsd:pattern value="\d+"/></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name="MESSAGE" minOccurs="0"><xsd:annotation><xsd:documentation>Message Text</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="220"/></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name="LOG_NO" minOccurs="0"><xsd:annotation><xsd:documentation>Application log: log number</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="20"/></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name="LOG_MSG_NO" minOccurs="0"><xsd:annotation><xsd:documentation>Application log: Internal message serial number</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="6"/><xsd:pattern value="\d+"/></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name="MESSAGE_V1" minOccurs="0"><xsd:annotation><xsd:documentation>Message Variable</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="50"/></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name="MESSAGE_V2" minOccurs="0"><xsd:annotation><xsd:documentation>Message Variable</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="50"/></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name="MESSAGE_V3" minOccurs="0"><xsd:annotation><xsd:documentation>Message Variable</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="50"/></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name="MESSAGE_V4" minOccurs="0"><xsd:annotation><xsd:documentation>Message Variable</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="50"/></xsd:restriction></xsd:simpleType></xsd:element></xsd:sequence></xsd:complexType></xsd:schema></wsdl:types><wsdl:message name="rfc.BAPI_GET_PAYROLL_RESULT_LIST.Input"><wsdl:documentation/><wsdl:part name="parameters" element="rfc:BAPI_GET_PAYROLL_RESULT_LIST"/></wsdl:message><wsdl:message name="rfc.BAPI_GET_PAYROLL_RESULT_LIST.Output"><wsdl:documentation/><wsdl:part name="parameters" element="rfc:BAPI_GET_PAYROLL_RESULT_LIST.Response"/></wsdl:message><wsdl:portType name="GetPayRollList_OB_SI"><wsdl:documentation/><wsdl:operation name="GetPayRollList_OB_SI"><wsdl:documentation/><wsp:Policy><wsp:PolicyReference URI="#OP_GetPayRollList_OB_SI"/></wsp:Policy><wsdl:input message="p1:rfc.BAPI_GET_PAYROLL_RESULT_LIST.Input"/><wsdl:output message="p1:rfc.BAPI_GET_PAYROLL_RESULT_LIST.Output"/></wsdl:operation></wsdl:portType><wsdl:binding name="GetPayRollList_OB_SIBinding" type="p1:GetPayRollList_OB_SI"><soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/><wsdl:operation name="GetPayRollList_OB_SI"><soap:operation soapAction="http://sap.com/xi/WebService/soap1.1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/><wsdl:input><soap:body use="literal" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/></wsdl:input><wsdl:output><soap:body use="literal" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="GetPayRollList_OB_SIService"><wsdl:port name="HTTP_Port" binding="p1:GetPayRollList_OB_SIBinding"><soap:address location="http://sapgmfdpi.gmf-aeroasia.co.id:52500/XISOAPAdapter/MessageServlet?senderParty=&amp;senderService=BC_GetPayRollSlip&amp;receiverParty=&amp;receiverService=&amp;interface=GetPayRollList_OB_SI&amp;interfaceNamespace=urn%3Agmf-aeroasia.co.id%3AGetPayRollSlip" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/></wsdl:port><wsdl:port name="HTTPS_Port" binding="p1:GetPayRollList_OB_SIBinding"><soap:address location="https://sapgmfdpi.gmf-aeroasia.co.id:52501/XISOAPAdapter/MessageServlet?senderParty=&amp;senderService=BC_GetPayRollSlip&amp;receiverParty=&amp;receiverService=&amp;interface=GetPayRollList_OB_SI&amp;interfaceNamespace=urn%3Agmf-aeroasia.co.id%3AGetPayRollSlip" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/></wsdl:port></wsdl:service></wsdl:definitions>

Controller

@Inject GetPayRollListOBSI payrollSoapClient;
    public Result payroll(){
        BAPIGETPAYROLLRESULTLIST payrolllist = new BAPIGETPAYROLLRESULTLIST();
        payrolllist.setEMPLOYEENUMBER("00580671");
        payrolllist.setFROMDATE("2016-01-01");
        payrolllist.setTODATE("2016-12-31");

        BAPIGETPAYROLLRESULTLISTResponse payrollresponse = payrollSoapClient.getPayRollListOBSI(payrolllist);
        BAPIRETURN1 br1 = payrollresponse.getRETURN();
        return ok(br1.toString());
    }
damienbeaufils commented 8 years ago

Hello,

It's strange because if you have the WSDL, all is specified inside. CXF will parse the WSDL and send the request to target.

Did you update the host configuration? In application.conf file, the global.weather.host configuration key and in applicationContext.xml file, the jaxws:client address property. If the endpoint is OK, I think this is a configuration issue on your server.

You can also use SoapUI or Wireshark to help you debugging the request.

inuru commented 8 years ago

Here is my configuration

<jaxws:client id="payrollSoapClient"
              serviceClass="com.global.payroll.GetPayRollListOBSI"
              address="${global.sap.host}/dir/wsdl?p=sa/a94554b41add3d06ac9ebe8bc82f20e4"/>

<http-conf:conduit name="${global.sap.host}/.*">
    <http-conf:client ConnectionTimeout="${global.sap.connection.timeout}"
                      ReceiveTimeout="${global.sap.response.timeout}"
                      AllowChunking="false"/>
    <http-conf:authorization>
        <sec:UserName>N564G4</sec:UserName>
        <sec:Password>loginpassword4u53</sec:Password>
        <sec:AuthorizationType>Basic</sec:AuthorizationType>
    </http-conf:authorization>
</http-conf:conduit>

I already test the wsdl address using SOAP UI and it was running well

damienbeaufils commented 8 years ago

I just pushed a new commit to enable SOAP messages logging: ee41830e4443e8a356f9b22d0584dbe7764266fc. Update your logback.xml and applicationContext.xml, and you will able to see the HTTP Method used in the request sent by CXF.

For example, using the GlobalWeather web service, it looks like this (we can see that it is a POST request):

[info] - org.apache.cxf.services.GlobalWeatherSoapService.GlobalWeatherSoapPort.GlobalWeatherSoap - Outbound Message
---------------------------
ID: 1
Address: http://www.webservicex.net/globalweather.asmx
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml
Headers: {Accept=[*/*], SOAPAction=["http://www.webserviceX.NET/GetCitiesByCountry"]}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetCitiesByCountry xmlns="http://www.webserviceX.NET"><CountryName>France</CountryName></GetCitiesByCountry></soap:Body></soap:Envelope>
--------------------------------------
[info] - org.apache.cxf.services.GlobalWeatherSoapService.GlobalWeatherSoapPort.GlobalWeatherSoap - Inbound Message
----------------------------
ID: 1
Response-Code: 200
Encoding: UTF-8
Content-Type: text/xml; charset=utf-8
Headers: {Cache-Control=[private, max-age=0], connection=[keep-alive], Content-Length=[15613], content-type=[text/xml; charset=utf-8], Date=[Thu, 08 Sep 2016 14:04:10 GMT], Proxy-Connection=[keep-alive], Server=[Microsoft-IIS/7.0], Via=[1.0 localhost (squid/3.1.19)], X-AspNet-Version=[4.0.30319], X-Cache=[MISS from localhost], X-Cache-Lookup=[MISS from localhost:3127], X-Powered-By=[ASP.NET]}
Payload: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetCitiesByCountryResponse xmlns="http://www.webserviceX.NET"><GetCitiesByCountryResult>&lt;NewDataSet&gt;
  &lt;Table&gt;
    &lt;Country&gt;France&lt;/Country&gt;
    &lt;City&gt;Le Touquet&lt;/City&gt;
  &lt;/Table&gt;

etc.
inuru commented 8 years ago

thanks @damienbeaufils i got the detailed information. so, the request is using POST method. i think i need to use GET method. image how do implement GET method?

damienbeaufils commented 8 years ago

It is strange that you need to use a GET method, because you have to send a payload inside the request. You can't do this with a GET. Only with a POST.

Check this post on Stackoverflow, explaining that using GET method with SOAP is just theorical: https://stackoverflow.com/questions/4646146/http-soap-get-post

Maybe you should not use CXF to call your webservice. You can use it to generate Java classes from WSDL, but that's all. You will have to make an explicit GET request by yourself using the Play WSClient for example.

I think I can't help you more on this sorry. I hope this helps.