IBM Worklight 6.0 - Getting Error while invoking adapter procedure - ibm-mobilefirst

I am following training module 04_02_HTTP_adapter_-_Communicating_with_HTTP_back-
end_systems, available on IBM Worklight Getting Started website, and when invoking a procedure it gives me an error:
{
"errors": [
"Runtime: Http request failed: java.net.UnknownHostException: rss.cnn.com"
],
"info": [
],
"isSuccessful": false,
"warnings": [
]
}
Adapter -impl.js
function getStories(interest) {
path = getPath(interest);
var input = {
method : 'get',
returnedContentType : 'xml',
path : path
};
return WL.Server.invokeHttp(input);
}
function getStoriesFiltered(interest) {
path = getPath(interest);
var input = {
method : 'get',
returnedContentType : 'xml',
path : path,
transformation : {
type : 'xslFile',
xslFile : 'filtered.xsl'
}
};
return WL.Server.invokeHttp(input);
}
function getPath(interest) {
if (interest == undefined || interest == '') {
interest = '';
}else {
interest = '_' + interest;
}
return 'rss/edition' + interest + '.rss';
}
XML file
<?xml version="1.0" encoding="UTF-8"?>
<wl:adapter name="RSSReader"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wl="http://www.worklight.com/integration"
xmlns:http="http://www.worklight.com/integration/http">
<displayName>RSSReader</displayName>
<description>RSSReader</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>rss.cnn.com</domain>
<port>80</port>
</connectionPolicy>
<loadConstraints maxConcurrentConnectionsPerNode="2" />
</connectivity>
<procedure name="getStories"/>
<procedure name="getStoriesFiltered"/>
</wl:adapter>
ahha, finally I got my answer. I did some proxy settings in the XML file and my adapter started working. Here is the Proxy code that one must add if they are using any Proxy.
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>rss.cnn.com</domain>
<port>80</port>
<proxy>
<protocol>http</protocol>
<domain>proxy.My_company_name.com</domain> ----use proxy URL here
<port>8080</port>
<authentication>
<basic/>
<serverIdentity>
<username>user</username> --------user is username
<password>password</password> ------------Proxy Password
</serverIdentity>
</authentication>
</proxy>
</connectionPolicy>

ahha, finally I got my answer. I did some proxy settings in the XML file and my adapter started working. Here is the Proxy code that one must add if they are using any Proxy.
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>rss.cnn.com</domain>
<port>80</port>
<proxy>
<protocol>http</protocol>
<domain>proxy.My_company_name.com</domain> ----use proxy URL here
<port>8080</port>
<authentication>
<basic/>
<serverIdentity>
<username>user</username> --------user is username
<password>password</password> ------------Proxy Password
</serverIdentity>
</authentication>
</proxy>
</connectionPolicy>

Related

Mobilefirst-8.0 JavaScript Adapter for SOAP service

I have created MobileFirstPlatform-v8.0 Javascript Adapter which invokes a SOAP web service. But I am unable to get a response from my swagger tool and WLRequest invoke procedure also. Kindly assist me.
My project environment : Mfp 8.0 with IONIC2 and AngularJS2
currently my SOAP service running in local tomcat server.
code :
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>localhost</domain>
<port>8080</port>
<connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds>
<socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds>
<maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode>
</connectionPolicy>
</connectivity>
<procedure name="getFeed" secured="false"/>
adapter-impl.js file
function getFeed(type) {
MFP.Logger.error("----------------"+type);
var request =
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://jee.javapapers.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<q0:animalType>
<q0:animal>{type}</q0:animal>
</q0:animalType>
</soapenv:Body>
</soapenv:Envelope>;
MFP.Logger.error("-----request ----"+request);
var input = {
method: 'post',
returnedContentType: 'xml',
path: '/animalType.asmx',
body: {
content: request.toString(),
contentType: 'text/xml; charset=utf-8'
}
};
var result = MFP.Server.invokeHttp(input);
return result.Envelope.Body;
};
invokeAdapter(){
var resourceRequest = new WLResourceRequest("/adapters/HTTPSOAP/getFeed/",WLResourceRequest.POST);
resourceRequest.setQueryParameter("params", "['world']");
resourceRequest.send().then((response) => {
console.log("success"+JSON.stringify(response));
},
function(error){
console.log("---failed--->"+JSON.stringify(error));
});
}
Error mfp message logs:
FWLST0904E: Exception was thrown while invoking procedure: {0} in
adapter: {1} Http request failed: java.net.SocketException: Connection
reset
Thanks advance...

Selenium2 with PhantomJS and PHPUnit - session/cookie issue

I have setup my current project to run with Selenium and PhantomJS. (Similar setup to http://www.nuanced.it/2015/05/using-phantomjs-with-phpunit.html)
However I keep on getting following error
{"errorMessage":"Can only set Cookies for the current domain","request":{"headers":{"Accept":"application/json;charset=UTF-8","Content-Length":"135","Content-type":"application/json;charset=UTF-8","Host":"127.0.0.1:8080"},"httpVersion":"1.1","method":"POST","post":"{\"cookie\":{\"name\":\"PHPUNIT_SELENIUM_TEST_ID\",\"value\":\"PepperLeaf\\\\WebBundle\\\\Tests\\\\MyProject\\\\TestFirstTest__testTitle\",\"secure\":false}}","url":"/cookie","urlParsed":{"anchor":"","query":"","file":"cookie","directory":"/","path":"/cookie","relative":"/cookie","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/cookie","queryKey":{},"chunks":["cookie"]},"urlOriginal":"/session/0d022670-4f79-11e5-abbe-01f06bc40b42/cookie"}}
Output from PhantomJS
[INFO - 2015-08-31T00:41:02.249Z] HUB Register - register - Registered with grid hub: http://127.0.0.1:4444/ (ok)
[INFO - 2015-08-31T00:41:43.258Z] Session [0d022670-4f79-11e5-abbe-01f06bc40b42] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.0.0 Safari/538.1","webSecurityEnabled":true}
[INFO - 2015-08-31T00:41:43.258Z] Session [0d022670-4f79-11e5-abbe-01f06bc40b42] - page.customHeaders: - {}
[INFO - 2015-08-31T00:41:43.258Z] Session [0d022670-4f79-11e5-abbe-01f06bc40b42] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.0.0","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"mac-10.9 (Mavericks)-64bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
[INFO - 2015-08-31T00:41:43.258Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 0d022670-4f79-11e5-abbe-01f06bc40b42
Code that I run on PHPUnit
class TestFirstTest extends \PHPUnit_Extensions_Selenium2TestCase {
/**
* {#inheritDoc}
*/
protected function setUp()
{
$this->setBrowser('phantomjs');
$this->setHost("127.0.0.1");
$this->setPort(8080);
$this->setBrowserUrl('http://www.mywebsite.dev/');
}
public function testTitle()
{
$this->url('/');
$this->assertTitle('Example WWW Page');
}
}
Disclaimer: I'm quite new to front end testing, this is my first go at this. I'm confused why this would be happening as I'm not setting up nor creating any cookies/sessions.
I'm not sure exactly what has caused this problem. However, this is my symfony/phpunit.xml (this is what has caused problems)
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "false"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false"
syntaxCheck = "false"
bootstrap = "../app/bootstrap.php.cache" >
<testsuites>
<testsuite name="PepperLeaf">
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
</testsuite>
</testsuites>
<php>
<server name="KERNEL_DIR" value="app/" />
<ini name="memory_limit" value="2048M" />
<ini name="xdebug.max_nesting_level" value="500" />
</php>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">../src</directory>
<exclude>
<directory>../src/*/*Bundle/Resources</directory>
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Resources</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/FrontTests</directory>
<directory>../src/*/Bundle/*Bundle/DataFixtures</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="coverage" />
<log type="coverage-xml" target="coverage/xml" />
<log type="coverage-clover" target="logs/clover.xml" />
<log type="coverage-crap4j" target="logs/crap4j.xml" />
<log type="junit" target="logs/junit.xml" logIncompleteSkipped="false" />
</logging>
</phpunit>
This is updated (working phpunit.xml script that WORKS). I'm not sure what exactly caused the problem above.
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit>
<testsuites>
<testsuite name="PepperLeaf_Frontend">
<directory>../src/*/*Bundle/FrontTests</directory>
</testsuite>
</testsuites>
<php>
<server name="KERNEL_DIR" value="app/" />
<ini name="memory_limit" value="2048M" />
<ini name="xdebug.max_nesting_level" value="500" />
</php>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">../src</directory>
<exclude>
<directory>../src/*/*Bundle/Resources</directory>
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Resources</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/DataFixtures</directory>
<directory>../src/*/*Bundle/FrontTests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>

Why contents in ModeShape JCR properties are truncated due to Infinispan eviction

We are using ModeShape 4.1.0.Final and Infinispan 6.0.2.Final to build out our content repository. After enabled eviction with maxEntries using singleFile store, I notice that some contents within JCR properties are truncated when number of JCR nodes are exceeded the maxEntries. Is this truncation issue caused by following configuration or a bug in the current release ModeShape 4.1.0.Final?
Here is the ModeShape configuration:
{
"name" : "Persisted-Repository",
"jndiName" : "",
"workspaces" : {
"predefined" : ["otherWorkspace"],
"default" : "default",
"allowCreation" : true
},
"security" : {
"anonymous" : {
"roles" : ["readonly","readwrite","admin"],
"useOnFailedLogin" : false
}
},
"storage" : {
"cacheConfiguration" : "eviction-test-infinispan-config.xml",
"cacheName" : "REPOSITORY",
"binaryStorage" : {
"type" : "file",
"directory": "modeshape/content/binaries",
"minimumBinarySizeInBytes" : 1000000
}
},
}
Here is the Infinispan configuration:
<?xml version="1.0" encoding="UTF-8"?>
<infinispan>
<global>
<globalJmxStatistics enabled="true"
allowDuplicateDomains="true" />
</global>
<namedCache name="REPOSITORY">
<!-- single file store -->
<persistence passivation="false">
<singleFile shared="true" preload="false"
fetchPersistentState="false" ignoreModifications="false"
purgeOnStartup="true" location="./infinispan/eviction">
</singleFile>
</persistence>
<!-- Look for transaction manager first -->
<transaction
transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"
transactionMode="TRANSACTIONAL" lockingMode="OPTIMISTIC" />
<!-- No more that 10K entries per cache, with LIRS eviction. -->
<eviction threadPolicy="DEFAULT" maxEntries="10000" strategy="LIRS" />
</namedCache>
</infinispan>
It's probably caused by this bug in Infinispan: ISPN-4810.

IBM Worklight SQL Adapter - Cannot connect to database. Cannot load JDBC driver class 'com.mysql.jdbc.Driver'

my adapter.xml
<?xml version="1.0" encoding="UTF-8"?>
<wl:adapter name="DbConnect"
<displayName>DbConnect</displayName>
<description>DbConnect</description>
<connectivity>
<connectionPolicy xsi:type="sql:SQLConnectionPolicy">
<!-- Example for using a JNDI data source, replace with actual data source name -->
<!-- <dataSourceJNDIName>java:/data-source-jndi-name</dataSourceJNDIName> -->
<!-- Example for using MySQL connector, do not forget to put the MySQL connector library in the project's lib folder -->
<dataSourceDefinition>
<driverClass>com.mysql.jdbc.Driver</driverClass>
<url>jdbc:mysql://localhost:3036/test</url>
<user>root</user>
<password>root</password>
</dataSourceDefinition>
</connectionPolicy>
<loadConstraints maxConcurrentConnectionsPerNode="5" />
</connectivity>
<!-- Replace this with appropriate procedures -->
<procedure name="select"/>
</wl:adapter>
and adapter-impl.js
var statement = WL.Server.createSQLStatement("select * from categorie");
function select(statement) {
return WL.Server.invokeSQLStatement({
preparedStatement : statement
});
}
I downloaded the connector .jar driver and locate it in the server/lib folder. I don't understand what could be wrong..
edit: below i post the message of console javascript when i run the app in worklight mobile browser simulator
wlclient init started wlgap.android.js:1481
before: app init onSuccess wlgap.android.js:1481
Request [/apps/services/api/Canti_Liturgici/android/query] wlgap.android.js:1481
after: app init onSuccess wlgap.android.js:1481
wlclient init success wlgap.android.js:1481
Failed to load resource: the server responded with a status of 401 (Unauthorized) http://localhost:8080/apps/services/api/Canti_Liturgici/android/query
Request [/apps/services/api/Canti_Liturgici/android/query] wlgap.android.js:1481
response [/apps/services/api/Canti_Liturgici/android/query] success: /*-secure-
{"responseID":"8","errors":["Runtime: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'"],"isSuccessful":false,"warnings":[],"info":[]}*/ wlgap.android.js:1481
Procedure invocation error. Runtime: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver' wlgap.android.js:1487
Failure {"status":200,"invocationContext":null,"errorCode":"PROCEDURE_ERROR","errorMsg":"Procedure invocation error. Runtime: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'","invocationResult":{"responseID":"8","errors":["Runtime: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'"],"isSuccessful":false,"warnings":[],"info":[]}}
I solved the problem. I edited the port of url in .xml file (is 3306 and not 3036), also i corrected the function select(statement) in select().
below the two file corrected.
adapter.xml
<displayName>DbConnect</displayName>
<description>DbConnect</description>
<connectivity>
<connectionPolicy xsi:type="sql:SQLConnectionPolicy">
<!-- Example for using a JNDI data source, replace with actual data source name -->
<!-- <dataSourceJNDIName>java:/data-source-jndi-name</dataSourceJNDIName> -->
<!-- Example for using MySQL connector, do not forget to put the MySQL connector library in the project's lib folder -->
<dataSourceDefinition>
<driverClass>com.mysql.jdbc.Driver</driverClass>
<url>jdbc:mysql://localhost:3306/test</url>
<user>root</user>
<password>mysql</password>
</dataSourceDefinition>
</connectionPolicy>
<loadConstraints maxConcurrentConnectionsPerNode="5" />
</connectivity>
<!-- Replace this with appropriate procedures -->
<procedure name="remoteDbSize"/>
adapter-impl.js
var statement = WL.Server.createSQLStatement("SELECT SUM( data_length + index_length ) FROM information_schema.TABLES WHERE table_schema = \"test\" GROUP BY table_schema");
function remoteDbSize() {
return WL.Server.invokeSQLStatement({
preparedStatement : statement,
parameters: []
});
}

magento event observer (magento1.7)

i am trying to implement an simple observer in my module (app/code/local/Foo/Bar).
My objective is to set the product names to '[product name] is cool' when a product is loaded in the frontend.
These are my files:
app/code/local/Foo/Bar/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<global>
<models>
<foo_bar>
<class>Foo_Bar_Model</class>
</foo_bar>
</models>
</global>
<frontend>
<events>
<catalog_product_load_after>
<observers>
<foo_bar>
<type>model</type>
<class>foo_bar/observer</class>
<method>catalogProductLoadAfter</method>
</foo_bar>
</observers>
</catalog_product_load_after>
</events>
</frontend>
</config>
app/code/local/Foo/Bar/Model/Observer.php
<?php
class Foo_Bar_Model_Observer{
public function catalogProductLoadAfter(Varien_Event_Observer $observer)
{
$product = $observer ->getProduct();
$product ->setName($product.getName().' '.'is cool');
}
}
?>
And i have also configured the module in app/etc/modules/Foo_Bar.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Foo_Bar>
<active>true</active>
<codePool>local</codePool>
</Foo_Bar>
</modules>
</config>
But it doenst work, does anyone have any suggestion?
You only need to module name for the model:
<foo_bar>
<type>model</type>
<class>bar/observer</class>
<method>catalogProductLoadAfter</method>
</foo_bar>
you don't need to specify Foo_Bar
also have you an error in your PHP
$product ->setName($product.getName().' '.'is cool');
should be
$product->setName($product->getName().' '.'is cool');