In IDE it is possible to set value of (connector) parameter through JavaScript.
Note: The IDE is IBM Security Directory Integrator (SDI). It is an eclipse based IDE that provides to write Java & JavaScript to perform ETL related activities. Since the questions is related to Java & JavaScript I believe if someone from Java/JavaScripts can help me understand the difference.
For eg: To set url parameter
// Get AL config object.
var gALCfg = task.getConfigClone(); //task is an in-built object provided in SDI
// Get AL settings object from AL config.
var gALSettings = gALCfg.getSettings();
// Get Parameters from TCB
var WSDLurl = gALSettings.getStringParameter("erPOSWSDLlocation"); ///we get the wsdl URL in this step.
var myURL = WSDL;
URL field on a connector can now be set with 'var myURL'
What difference would it make if I create a URL object and then set value of the (connector) parameter ? For eg:
var gALCfg = task.getConfigClone(); //task is an in-built object provided in SDI
var gALSettings = gALCfg.getSettings();
var WSDLurl = gALSettings.getStringParameter("erPOSWSDLlocation"); //we get the wsdl URL in this step.
var myURL = new Packages.java.net.URL(WSDL);
Related
I'm having a really hard time sending an automated email (with Google Apps Script) that includes a URL that contains query parameter.
Expected Behavior
Google Apps Script (specifically, the Gmail service) sends an email, and part of the email body contains a URL with a query parameter. The URL will look something like this:
http://my.app/products?id=Bz9n7PJLg8hufTj11gMF
Observed Behavior
The Gmail service seems to be stripping out the = from my URL. So, the body of the email ends up looking like this:
...
http://my.app/products?idBz9n7PJLg8hufTj11gMF
...
Obviously, that link won't work.
I've checked other questions here on SO, and I've tried working with the base encoding tools from the GAS Utilities service, as well as working with the encodeURI() JavaScript method. No luck so far.
Email-sending Code
//////// GENERATING MESSAGE FROM ID ////////////
// Gets message from ID
var id = Gmail.Users.Drafts.get('me', 'r-1006091711303067868').message.id
var message = GmailApp.getMessageById(id)
var template = message.getRawContent()
// Replaces template variables with custom ones for the user using RegExes
let listingUrl = 'http://my.app/products?id=xyz'
let creatorEmail = 'hello#gmail.com'
let creatorUsername = 'Sam'
template = template.replace(/templates#my.app/g, creatorEmail)
template = template.replace(/firstName/g, creatorUsername)
//** Below is the string that gets modified and broken **//
template = template.replace(/listingUrl/g, listingUrl)
// Creates the new message
var message = Gmail.newMessage()
var encodedMsg = Utilities.base64EncodeWebSafe(template)
message.raw = encodedMsg
// Sends it
Gmail.Users.Messages.send(message, "me", Utilities.newBlob(template, "message/rfc822"))
Regex-based Solution
With the help of Tanaike and Rafa Guillermo, the solution that ended up working for me was to replace = with = by using a little .replace() like this:
listingUrl = listingUrl.replace(/=/, '=')
I have an error in MVC, when I pass as parameter '&' fails to come the following. How will I show in this example?
public IActionResult Create(int? idTrabalhador, [FromQuery]string GridState{}
view
var lnk = "#Url.Action("Create" , new { idTrabalhador = "{#KeyTrabalhador}", GridState = "{#GRID_STATE}" })";
lnk = lnk.replace(encodeURIComponent("{#KeyTrabalhador}"), 0);
lnk = lnk.replace(encodeURIComponent("{#GRID_STATE}"), JSON.stringify(state));
http://localhost:58185/TrabalhadorPincodes/Create?idTrabalhador=0&GridState={"filter":{"NomeTrabalhador":"nuno","Estado":"0"},"sorter":[],"currentPage":0}
model =>
GridState = "{\"filter\":{\"NomeTrabalhador\":\"nuno\",\"Estado\":\"0\"},\"sorter\":[],\"currentPage\":0}"
Perfect!!!
BUT
http://localhost:58185/TrabalhadorPincodes/Create?idTrabalhador=0&GridState={"filter":{"NomeTrabalhador":"&","Estado":"0"},"sorter":[],"currentPage":0}
model =>
GridState = "{\"filter\":{\"NomeTrabalhador\":\""
need help!!!
The browser is interpreting the & as part of the url as you are sending the http request via the GET method.
One method to handle this is to urlEncode your parameters using Server.UrlEncode
This also means you will need to decode the parameters within your controller.
The other solution is to post the values so that they are not part of the url but you will need to decide whether this is appropriate.
because the 'encodeURIComponent' only works in plain text, what I'm doing is creating a compound object soon does not work. I have to use the 'encodeURIComponent' as soon as the object is constructed not after it is built
filter.NomeTrabalhador = encodeURIComponent($('#NomeTrabalhador').val());
Given this sample XML:
<patient>
<name>
<given>Bob</given>
<family>Dole</family>
</name>
</patient>
I would like to create an object, patient and be able to do something like alert(patient.name.given) and get a popup that says "Bob". My actual data is much more complex than this so I would also need to account for attributes and arrays.
How can this be achieved?
I'm currently using parseXML() but I'd rather not have to type alert($xml.find("patient").find("name").find("given").text)
Here's an example of how to use JSONIX to parse (unmarshal) XML into JavaScript:
Parse XML into JS
// Include or require PO.js so that PO variable is available
// For instance, in node.js:
var PO = require('./mappings/PO').PO;
// First we construct a Jsonix context - a factory for unmarshaller (parser)
// and marshaller (serializer)
var context = new Jsonix.Context([PO]);
// Then we create a unmarshaller
var unmarshaller = context.createUnmarshaller();
// Unmarshal an object from the XML retrieved from the URL
unmarshaller.unmarshalURL('po.xml',
// This callback function will be provided
// with the result of the unmarshalling
function (unmarshalled) {
// Alice Smith
console.log(unmarshalled.value.shipTo.name);
// Baby Monitor
console.log(unmarshalled.value.items.item[1].productName);
});
http://www.biletix.com/search/TURKIYE/en#!subcat_interval:12/12/15TO19/12/15
I want to get data from this website. When i use jsoup, it cant execute because of javascript. Despite all my efforts, still couldnot manage.
enter image description here
As you can see, i only want to get name and url. Then i can go to that url and get begin-end time and location.
I dont want to use headless browsers. Do you know any alternatives?
Sometimes javascript and json based web pages are easier to scrape than plain html ones.
If you inspect carefully the network traffic (for example, with browser developer tools) you'll realize that page is making a GET request that returns a json string with all the data you need. You'll be able to parse that json with any json library.
URL is:
http://www.biletix.com/solr/en/select/?start=0&rows=100&fq=end%3A[2015-12-12T00%3A00%3A00Z%20TO%202015-12-19T00%3A00%3A00Z%2B1DAY]&sort=vote%20desc,start%20asc&&wt=json
You can generate this URL in a similar way you are generating the URL you put in your question.
A fragment of the json you'll get is:
....
"id":"SZ683",
"venuecount":"1",
"category":"ART",
"start":"2015-12-12T18:30:00Z",
"subcategory":"tiyatro$ART",
"name":"The Last Couple to Meet Online",
"venuecode":"BT",
.....
There you can see the name and URL is easily generated using id field (SZ683), for example: http://www.biletix.com/etkinlik/SZ683/TURKIYE/en
------- EDIT -------
Get the json data is more difficult than I initially thought. Server requires a cookie in order to return correct data so we need:
To do a first GET, fetch the cookie and do a second GET for obtain the json data. This is easy using Jsoup.
Then we will parse the response using org.json.
This is a working example:
//Only as example please DON'T use in production code without error control and more robust parsing
//note the smaller change in server will break this code!!
public static void main(String[] args) throws IOException {
//We do a initial GET to retrieve the cookie
Document doc = Jsoup.connect("http://www.biletix.com/").get();
Element body = doc.head();
//needs error control
String script = body.select("script").get(0).html();
//Not the more robust way of doing it ...
Pattern p = Pattern.compile("document\\.cookie\\s*=\\s*'(\\w+)=(.*?);");
Matcher m = p.matcher(script);
m.find();
String cookieName = m.group(1);
String cookieValue = m.group(2);
//I'm supposing url is already built
//removing url last part (json.wrf=jsonp1450136314484) result will be parsed more easily
String url = "http://www.biletix.com/solr/tr/select/?start=0&rows=100&q=subcategory:tiyatro$ART&qt=standard&fq=region:%22ISTANBUL%22&fq=end%3A%5B2015-12-15T00%3A00%3A00Z%20TO%202017-12-15T00%3A00%3A00Z%2B1DAY%5D&sort=start%20asc&&wt=json";
Document document = Jsoup.connect(url)
.cookie(cookieName, cookieValue) //introducing the cookie we will get the corect results
.get();
String bodyText = document.body().text();
//We parse the json and extract the data
JSONObject jsonObject = new JSONObject(bodyText);
JSONArray jsonArray = jsonObject.getJSONObject("response").getJSONArray("docs");
for (Object object : jsonArray) {
JSONObject item = (JSONObject) object;
System.out.println("name = " + item.getString("name"));
System.out.println("link = " + "http://www.biletix.com/etkinlik/" + item.getString("id") + "/TURKIYE/en");
//similarly you can fetch more info ...
System.out.println();
}
}
I skipped the URL generation as I suppose you know how to generate it.
I hope all the explanation is clear, english isn't my first language so it is difficult for me to explain myself.
I am trying to validate a webhook with Podio (https://developers.podio.com/doc/hooks/validate-hook-verificated-215241) using google apps script.
Currently I have the following script successfully writing data to a document (after the Podio Post is activated):
function doPost(l) {
var doc = DocumentApp.openById('1to3-JzhE27-LK0Zw7hEsdYgiSd7xQq7jjp13m6YwRh0');
var jstring = Utilities.jsonStringify(l);
doc.appendParagraph(jstring);
}
With the data appearing as follows:
{"queryString":null,"parameter":{"hook_id":"38035","code":"a92e06a2","type":"hook.verify"},"contextPath":"","parameters":{"hook_id":["38035"],"code":["a92e06a2"],"type":["hook.verify"]},"contentLength":44}
For some reason, google apps script won't let me take this data and access the properties like this:
jstring.parameter.code;
If I copy the (seemingly) JSON string into a separate script under a new variable, I can then access the data within the JSON.
What am I doing wrong here?
It looks like you have a JavaScript object that you convert to a JSON string, jstring. It is just a string. If you want to access the properties represented in the string, use the original object, l. Ie, l.parameter.code
function doPost(l) {
var doc = DocumentApp.openById('1to3-JzhE27-LK0Zw7hEsdYgiSd7xQq7jjp13m6YwRh0');
var jstring = Utilities.jsonStringify(l);
doc.appendParagraph(jstring);
dosomething(l.parameter.code);
}