I want to consume the following soap url:
http://89.221.253.174:8080/OpenClinica-ws/ws/data/v1/dataWsdl.wsdl
I am using google pass script and my code looks as below:
var xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:v1=\"http://openclinica.org/ws/studySubject/v1\" xmlns:bean=\"http://openclinica.org/ws/beans\">"
+"<soapenv:Header>"
+"<wsse:Security soapenv:mustUnderstand=\"1\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">"
+"<wsse:UsernameToken wsu:Id=\"UsernameToken-27777511\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">"
+"<wsse:Username>x</wsse:Username>"
+"<wsse:Password>y</wsse:Password>"
+"</wsse:UsernameToken>"
+"</wsse:Security>"
+"</soapenv:Header>"
+"<soapenv:Body>"
+"<v1:importRequest>"
+"<ODM>"
+"<ClinicalData StudyOID=\"S_PROSPER2\" MetaDataVersionOID=\"v1.0.0\">"
+"<SubjectData SubjectKey=\"SS_UU001\">"
+"<StudyEventData StudyEventOID=\"SE_QUESW4\" StudyEventRepeatKey=\"0\">"
+"<FormData FormOID=\"F_RANDANDQUEST_11\">"
+"<ItemGroupData ItemGroupOID=\"IG_RANDA_UNGROUPED\" ItemGroupRepeatKey=\"1\" TransactionType=\"Insert\">"
+"<ItemData ItemOID=\"I_RANDA_RAND01\" Value=\"1\"/>"
+"<ItemData ItemOID=\"I_RANDA_RAND02\" Value=\"1\"/>"
+"<ItemData ItemOID=\"I_RANDA_RAND03\" Value=\"1\"/>"
+"<ItemData ItemOID=\"I_RANDA_RAND04\" Value=\"1\"/>"
+"</ItemGroupData>"
+"</FormData>"
+"</StudyEventData>"
+"</SubjectData>"
+"</ClinicalData>"
+"</ODM>"
+"</v1:importRequest>"
+"</soapenv:Body>"
+"</soapenv:Envelope>";
var options =
{
"method" : "post",
"contentType" : "text/xml; charset=utf-8",
"payload" : xml
};
var result = UrlFetchApp.fetch("http://89.221.253.174:8080/OpenClinica-ws/ws/data/v1/dataWsdl.wsdl", options);
Logger.log(result);
I don't know actually what is the error on here, what does 404 means in this case? Seems like I am communicating with the server but something else is missing.
Any idea what would be wrong in here?
PS: The same code works just fine using soapUI.
solved it by puting all the xml in one line this way:
var xml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:v1=\"http://openclinica.org/ws/data/v1\"><soapenv:Header><wsse:Security soapenv:mustUnderstand=\"1\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"><wsse:UsernameToken wsu:Id=\"UsernameToken-27777511\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"><wsse:Username>x</wsse:Username><wsse:Password>y</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><v1:importRequest><ODM><ClinicalData StudyOID=\"S_PROSPER2\" MetaDataVersionOID=\"v1.3.0\"><SubjectData SubjectKey=\"SS_UU001\"><StudyEventData StudyEventOID=\"SE_QUESW4\" StudyEventRepeatKey=\"0\"><FormData FormOID=\"F_RANDANDQUEST_11\"><ItemGroupData ItemGroupOID=\"IG_RANDA_UNGROUPED\" ItemGroupRepeatKey=\"1\" TransactionType=\"Insert\"><ItemData ItemOID=\"I_RANDA_RAND01\" Value=\"1\"/></ItemGroupData></FormData></StudyEventData></SubjectData></ClinicalData></ODM></v1:importRequest></soapenv:Body></soapenv:Envelope>";
I have no idea why is this way it works, but it is working!
Related
I've spent tens of hours on it: calling a web service from my school platform with google script. It works in php but not in google script. I don't know how to implement the "getClassList" method in the script. Everything tried nothing works! Please help me before I go completely crazy!
I give you everything I think is necessary to write the script:
Webservices V3 (SOAP)
URL's:
https://tisj-bilzen.smartschool.be/Webservices/V3
https://tisj-bilzen.smartschool.be/Webservices/V3?wsdl
Details of the methode:
getClassList
This method requests a list of all classes. This method provides a serialized array with the class name, description, visibility, and unique class code.
string $accesscode: Password webservices
getClassListJson
This method requests a list of all classes. This method provides a JSON array with the class name, description, visibility and unique class code.
string $accesscode: Password webservices
Password webservices : 408cb6c31db39698b176
Many thanks in advance !!
Patrick Crijns
one of my attempts :
function probeer5(){
var $code = '408cb6c31db39698b176';
var options = {"headers" : {"Authorization" : "accesscode:408cb6c31db39698b176>"} };
var url = "https://tisj-bilzen.smartschool.be/Webservices/V3?wsdl#getClassList";
var response = UrlFetchApp.fetch(url,options);
var result= response.getContentText();
Logger.log(result);
}
I'm trying to do the same thin on my school's smartschool.be-platform. Did you ever get this to work?
I've tried setting up a soap client like in this example!, but didn't get it to work for smartschool...
Update: I got it to work! Check out the demo code bolow, for the saveUserParameter method. I'm sure you'll be able to alter it to get the getClassList method to work as well. Don't forget to change my school prefix (msvoskenslaan) to yours (tisj-bilzen)!
function SS() {
var SSpass = "MySecretPassWord" //webservices PW
var sam = "fake.student" //user identifier (login or uniek ID)
var parameter = "extraInfo" //as this script calls the saveUserParameter webservice, this is the name of the parameter field which will be altered
var data = "Door script ingevoerde waarde met spaties \nen \nline \nbreaks." //the data entered in the field mentioned above
var xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="https://msvoskenslaan.smartschool.be:443/Webservices/V3" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ><SOAP-ENV:Body><mns:saveUserParameter xmlns:mns="https://msvoskenslaan.smartschool.be:443/Webservices/V3" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><accesscode xsi:type="xsd:string">' + SSpass + '</accesscode><userIdentifier xsi:type="xsd:string">' + sam + '</userIdentifier><paramName xsi:type="xsd:string">' + parameter + '</paramName><paramValue xsi:type="xsd:string">' + data + '</paramValue></mns:saveUserParameter></SOAP-ENV:Body></SOAP-ENV:Envelope>'
var options =
{
"method" : "post",
"contentType" : "text/xml; charset=utf-8",
"payload" : xml,
"muteHttpExceptions" : true
};
var soapCall= UrlFetchApp.fetch("https://msvoskenslaan.smartschool.be/Webservices/V3", options);
Logger.log(soapCall);
}
I am trying to do this on client side using JavaScript.
Question: How to access JSON stored within https://www.instagram.com/xsolvesoftware/media/ with JavaScript and turn it into Object?
I tried xmlHttpRequest
function httpGet(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
xmlHttp.send( null );
return xmlHttp.responseText;
}
var data = httpGet("https://www.instagram.com/xsolvesoftware/media/");
console.log(data);
I have tried loading it with src but it obviously doesn't work as it works only on content inside of tags:
var jsonData = JSON.parse(document.getElementById('data').textContent)
<script id="data" type="application/json" src="https://www.instagram.com/xsolvesoftware/media/">
</script>
I have tried editing this example but it uses JSONP not JSON as a reply and i think i would get JSONP only if i would use registered with access to users content:
var token = '1362124742.3ad74ca.6df307b8ac184c2d830f6bd7c2ac5644',
num_photos = 10,
container = document.getElementById( 'rudr_instafeed' ),
scrElement = document.createElement( 'script' );
window.mishaProcessResult = function( data ) {
for( x in data.data ){
container.innerHTML += '<li><img src="' + data.data[x].images.low_resolution.url + '"></li>';
}
}
scrElement.setAttribute( 'src', 'https://api.instagram.com/v1/users/self/media/recent?access_token=' + token + '&count=' + num_photos + '&callback=mishaProcessResult' );
document.body.appendChild( scrElement );
<ul id="rudr_instafeed"></ul>
have you already tried it?
What is you concrete problem?
If you have already tried, you could provide some code snippets and explain what you are struggeling with? (edit: you edited the question and added some code snippets, I'll have a look at them now)
From the distance it sounds like you are running into the CORS trap.
You need a backend service that fetches the json for you running on the same origin as you page is served from. This answer is a good starting point :)
Hope this helps.
edit: Had a look at your snippets and it is like I assumed: you have a problem with CORS. Your javascript is not allowed to load data from any arbitrary URL.
I have an Ajax form that I need to hit a JavaScript function on failure, like so:
using (Ajax.BeginForm("UpdateStages", new AjaxOptions
{
HttpMethod = "POST",
OnSuccess = "refreshSearchResults('" + #Model.First().ItemCode + "')",
OnFailure = "showError"
}))
With the showError function taking the Ajax context response and appending it to a div, like so:
function showError(ajaxContext)
{
var response = ajaxContext.responseText;
response = $($.trim(response));
var itemVersion = response.filter("div")[0].innerHTML.trim().toString();
var error = response.filter("p")[0].outerHTML.toString();
$("#" + itemVersion.replace(".", "") + "-UpdateStagesResults").empty();
$(error).appendTo("#" + itemVersion.replace(".", "") + "-UpdateStagesResults");
}
In order for the OnFailure to be called I have in my MVC controller ActionResult, when an error occurs:
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return PartialView();
which returns a PartialView with the error message in the ViewBag. This works fine when running locally, the error message is sent to the showError function and then the error is appended to the page.
The problem is that when I put the application onto a live server (IIS7), the Ajax context is just
Bad Request
and for example is not:
<p>You have not entered a valid date.</p>
<div style="display:none;">V7.0 </div>
Any help would be great!
I've had this,
in IIS7 the default error settings are to show detailed error messages locally only., your view is replaced with the default for the status code.
If you want to see your custom errors, add this into your web.config
<system.webServer>
<httpErrors errorMode="Detailed" />
</system.webServer>
that should sort it
I am using IE9 and jquery-1.8.0.js. I am getting extra junk character in responseXML. The actual XML sent by server is as below,
<?xml version="1.0" encoding="UTF-8" ?><ResponseStatus><version>0.0.1</version><requestURL>myurl.com</requestURL><statusCode>-1</statusCode><statusString>success</statusString></ResponseStatus>
But when I check responseText it shows as below which is giving error with loadXML. Notice the spaces and \r\n- characters added unneeded,
" <?xml version=\"1.0\" encoding=\"UTF-8\" ?> \r\n- <ResponseStatus>\r\n <version>0.0.1</version> \r\n <requestURL>myurl.com</requestURL> \r\n <statusCode>-1</statusCode> \r\n <statusString>success</statusString> \r\n </ResponseStatus>"
below is the code snippet,
var options =
{
beforeSend:...
error:...
success: function (responseXML, statusText, xhr, $form)
{
var xmlobj = responseXML.documentElement.innerText;
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.loadXML(xmlobj);
//xmlDoc.parseError.errorCode = -1072896682
//xmldoc.reason = "Invalid at the top level of the document.\r\n"
}
};
I am wondering who is changing the XML automatically. I appreciate your guidance resolving this.
Thanks,
Jdp
I don't know the exact reason about who is tampering the XML in between but I used below function to sanitize the XML and resolved my problem.
function sanitizeXML(xmlobj)
{
"use strict";
return xmlobj.replace("\r\n-","");
}
Appreciate if there is any good solution.
I would like to start a simple file download through the browser, however an access token must be passed with a custom HTTP header:
GET https://my.site.com/some/file
Authorization: access_token
How can I inject the Authorization: header following the site URL?
I know it's possible to do that using query string, but I want to do it using headers.
I'm familiar with XMLHttpRequest, but as far as I understand it does not trigger download, it only reads content and the file I want to download is few hundred MBs at least.
xhr.setRequestHeader('Authorization', 'access_token');
This looks like a simple task, but I'm inexperienced coder so any help would be nice. Thanks.
I think this solves your problem:
function toBinaryString(data) {
var ret = [];
var len = data.length;
var byte;
for (var i = 0; i < len; i++) {
byte=( data.charCodeAt(i) & 0xFF )>>> 0;
ret.push( String.fromCharCode(byte) );
}
return ret.join('');
}
var xhr = new XMLHttpRequest;
xhr.open( "GET", "https://my.site.com/some/file" );
xhr.addEventListener( "load", function(){
var data = toBinaryString(this.responseText);
data = "data:application/text;base64,"+btoa(data);
document.location = data;
}, false);
xhr.setRequestHeader("Authorization", "access_token" );
xhr.overrideMimeType( "application/octet-stream; charset=x-user-defined;" );
xhr.send(null);
Modified answer https://stackoverflow.com/a/10518190/2767026 to fit your needs.
https://stackoverflow.com/a/12372670/1961561 could be a solution for your problem.
$.ajax({
url: "/test",
headers: {"X-Test-Header": "test-value"}
});
It is not possible to add custom http header when you download a file by clicking on a link.
However, in your use case, you might store the token in a cookie, which will be automatically added to all browser requests.