Author Topic: remote dataModel with Soap URL?  (Read 4904 times)

jpantona

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 11
    • View Profile
remote dataModel with Soap URL?
« on: December 05, 2013, 03:01:48 am »
When I review the examples of remote dataModel, the URL parameters given always seems to suggest a REST web services approach. I don't see how to have a remote dataModel connection using SOAP web services... Is this possible? In particular, I want to pass JSON data in the SOAP envelope and receive JSON data back from the web service. I understand the server side of this operation but I don't see how to configure this in the paramquery grid dataModel parameters. Am I missing something?

So I tried to implement the getURL() method on the dataModel to send a soap request. Below is the code. See below for the error I receive when I execute this code.

Code: [Select]
var reportObj = {};
    reportObj.width = 1200;
    reportObj.height = 1000;
reportObj.title = "Report";
    reportObj.colModel = <%= attributeComp.getReportColumnModel() %>;
    reportObj.dataModel = {
location: "remote",
        sorting: "local",
        dataType: "JSON",
        method: "POST",
getData: function (dataJSON) {
alert(dataJSON);
            var data = dataJSON.data;
            //expand the first row
            //data[0]['pq_detail'] = { 'show': true };               
            return { data: data };
        },
getUrl: function() {
var rObjectId = jQuery('#contractObjId').val();
var rjson = "{ r_object_id : '" + rObjectId + "',  encryptedUsername : 'IL9llvk', encryptedPassword : 'apx6TrB+Gc', encryptedRepository : 'QlRDcYjMxVX2k' }";
var soapMessage = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.prodagio.com"><soapenv:Header/><soapenv:Body><ser:refreshReport><json>' + rjson + '</json></ser:refreshReport></soapenv:Body></soapenv:Envelope>';
var webServiceURL = 'http://x.com/services/prodagioDFS/AboveTheLineContractService';
alert(soapMessage);
return { url : webServiceURL, data: escapeHTML(soapMessage) };
}
};
reportObj.hoverMode = 'cell';
reportObj.selectionModel = { type: 'cell' };
reportObj.editModel = {
            saveKey: $.ui.keyCode.ENTER,
            select: false,
            keyUpDown: false,
            cellBorderWidth: 0               
        };
//reportObj.editor = { type: "textbox" };
    var reportGrid = jQuery("#grid_contractReport").pqGrid( reportObj );

Quote
SEVERE: Unsupported Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Supported ones are: [text/xml]
com.sun.xml.ws.server.UnsupportedMediaException: Unsupported Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Supported ones are: [text/xml]
   at com.sun.xml.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:295)
« Last Edit: December 05, 2013, 05:14:31 am by jpantona »

jpantona

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: remote dataModel with Soap URL?
« Reply #1 on: December 05, 2013, 05:39:41 am »
OK. I was able to successfully send the SOAP request and receive a response by forcing the contentType of all $.ajax() calls to 'text/xml' as shown below:

Code: [Select]
getUrl: function() {
$.ajaxSetup({
contentType : "text/xml"
});
var rObjectId = jQuery('#contractObjId').val();
var rjson = "{ r_object_id : '" + rObjectId + "',  encryptedUsername : 'IL9llv', encryptedPassword : 'apx6TrB+G', encryptedRepository : 'QlRDcYjMxVX' }";
var soapMessage = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.prodagio.com"><soapenv:Header/><soapenv:Body><ser:refreshReport><json>' + rjson + '</json></ser:refreshReport></soapenv:Body></soapenv:Envelope>';
var webServiceURL = 'http://x.com/services/prodagioDFS/AboveTheLineContractService?wsdl';
//alert(soapMessage);
return { url : webServiceURL, data: soapMessage };
}

In particular, this was the key to success:

Code: [Select]
$.ajaxSetup({
contentType : "text/xml"
});

jpantona

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: remote dataModel with Soap URL?
« Reply #2 on: December 05, 2013, 07:04:49 am »
The final code, working successfully:

Code: [Select]

var reportObj = {};
    reportObj.width = 1200;
    reportObj.height = 1000;
reportObj.title = "Report";
    reportObj.colModel = <%= attributeComp.getReportColumnModel() %>;
    reportObj.dataModel = {
location: "remote",
        sorting: "local",
        dataType: "XML",
        method: "POST",
error: function(jqXHR, textStatus, errorThrown) {
xmlDoc = $.parseXML( jqXHR.responseText ),
$xml = $( xmlDoc ),
$rr = $xml.find( "return" );
if ($rr.text().toLowerCase().indexOf("error") > -1 ) {
  alert("Report unsuccuessful. An error occured: " + textStatus + " " + $rr.text());
    }
},
getData: function(response, textStatus, jqXHR) {
//alert(jqXHR.responseText);
xmlDoc = $.parseXML( jqXHR.responseText );
$xml = $( xmlDoc );
$rr = $xml.find( "return" );
if ($rr.text().toLowerCase().indexOf("error") > -1 ) {
  alert("Report unsuccuessful. An error occured: " + $rr.text());
    } else {
alert($rr.text());
try {
var rdata = $.parseJSON($rr.text());
} catch ( eeee ) {
alert("Report unsuccuessful. An error occured: " + eeee);
}
alert('5');
}
            return { data: rdata.data };
        },
getUrl: function() {
$.ajaxSetup({
contentType : "text/xml"
});
var rObjectId = jQuery('#contractObjId').val();
var rjson = "{ r_object_id : '" + rObjectId + "',  encryptedUsername : 'IL9ll', encryptedPassword : 'apx6TrB+', encryptedRepository : 'QlRDcYjMxVX2k' }";
var soapMessage = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.prodagio.com"><soapenv:Header/><soapenv:Body><ser:refreshReport><json>' + rjson + '</json></ser:refreshReport></soapenv:Body></soapenv:Envelope>';
var webServiceURL = 'http://x.com/services/xDFS/AboveTheLineContractService?wsdl';
//alert(soapMessage);
return { url : webServiceURL, data: soapMessage };
}
};
reportObj.hoverMode = 'cell';
reportObj.selectionModel = { type: 'cell' };
reportObj.editModel = {
            saveKey: $.ui.keyCode.ENTER,
            select: false,
            keyUpDown: false,
            cellBorderWidth: 0               
        };
//reportObj.editor = { type: "textbox" };
    var reportGrid = jQuery("#grid_contractReport").pqGrid( reportObj );


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: remote dataModel with Soap URL?
« Reply #3 on: December 05, 2013, 05:56:08 pm »
This is a nice example of using SOAP request.

Just want to add that

$.ajaxSetup({
   contentType : "text/xml"
});

affects all the jQuery Ajax requests on the page which may not be desirable in some cases.

Another way to add content type to a specific remote dataModel request is
Code: [Select]
dataModel.beforeSend = function (jqXHR, settings) {           
  //settings.contentType = "text/xml";
  jqXHR.setRequestHeader("Content-Type", "text/xml"); 
};
« Last Edit: December 29, 2013, 04:40:56 pm by paramquery »