How to set a nillable attribute for SOAP::Lite object in Perl? - perl

I'm receiving the following error:
Exception: Error code: , messge: com.sun.istack.XMLStreamException2: org.xml.sax.SAXParseException: cvc-elt.3.1: Attribute 'http://www.w3.org/2001/XMLSchema-instance,nil' must not appear on element 'v1:get_list', because the {nillable} property of 'v1:get_list' is false. at ./soap.pl line 42.
This is my Perl code:
my $client = SOAP::Lite
->on_fault( \&faultHandler )
->uri('http://api.domain.net/')
->proxy('https://api.domain.net/MyAPI');
# Execute
$client->get_list();
How do I change/add the nillable attribute and how ?

How do I change/add the nillable attribute and how ?
You use SOAP::Data to create argument for get_list, or for call
Switch to SOAP::Simple , it has better WSDL support cpan BERLE/SOAP-Simple-0.00_03.tar.gz

Related

Add node CATEGORIES to vcard with perl module "vCard::AddressBook"

I do not find a possibility to add nodes like CATEGORIES or ORG to a vcard object when using the perl module vCard::AddressBook (https://metacpan.org/pod/vCard::AddressBook).
The output should look like this:
BEGIN:VCARD
VERSION:4.0
...
N:Doe;John;;;
...
ORG:Organization_01;
CATEGORIES:Cat_01
...
END:VCARD
When I use the following code:
use vCard::AddressBook;
my $address_book = vCard::AddressBook->new();
my $vcard = $address_book->add_vcard;
$vcard->given_names(['John']);
$vcard->family_names(['Doe']);
$vcard->categories(['Cat_01']); ## DOES NOT WORK
my $file = $address_book->as_file('file.vcf');
I get the following error:
Can't locate object method "categories" via package "vCard" at tmp2.pl line 6.
What is the best way to get other nodes like CATEGORIES in my vcard file?
BTW: RFC6350 defines it... https://www.rfc-editor.org/rfc/rfc6350#section-6.7.1
There is https://metacpan.org/pod/Text::vCard::Precisely which seems to be more compliant with RFC6350:
use Text::vCard::Precisely;
my $vcard = Text::vCard::Precisely->new( version => '4.0' );
$vcard->n(['John','Doe']);
$vcard->categories([qw/Cat_01 Cat_02 Cat_03/]);
print $vcard->as_string();
prints:
BEGIN:VCARD
VERSION:4.0
N:John;Doe;;;
CATEGORIES:Cat_01,Cat_02,Cat_03
END:VCARD

KIE workbench integration with Java: mismatched input '<' expecting one of the following tokens: '[package, import, global, declare,..]'

I'm trying to integrate drools kie workbench with java application. I'm Using jboss-as-7.1.1.Final as my workbench. Here is the rule definition:
package com.sample;
rule "set isEligible"
ruleflow-group "sample"
lock-on-active true
when
$p : Student(gpa > 2.0)
then
System.out.println("GPA is greater than 2..");
$p.setEligible(true);
end
From the java application i'm passing the student POJO object to the kieSession object and firing up the rules.
Here is the code:
Student s = new Student();
s.setName("Virat");
s.setGpa(5.0f);
URL u = new URL("http://localhost:8080/kie-wb-distribution-wars-6.2.0.Final-jboss-as7/kie-wb.html#%5Bnull%5D?path_uri=default://master#com/sample/src/main/resources/com/sample/sampleDRL.drl&file_name=sampleDRL.drl&has_version_support=true");
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newUrlResource(u), ResourceType.DRL );
kbuilder.hasErrors();
if (kbuilder.hasErrors() ) {
System.out.println( kbuilder.getErrors() );
}
kbuilder.getKnowledgePackages();
KieBase kieBase = kieContainer.getKieBase();
KieSession kieSession = kieBase.newKieSession();
kieSession.insert(s);
kieSession.fireAllRules();
I'm able to connect to the workbench repository (com:sample:1.0) from the java app. But the problem is, i'm getting the following exception while executing the rule:
[8,0]: [ERR 107] Line 8:0 mismatched input '<' expecting one of the following tokens: '[package, import, global, declare, function, rule, query]'.
[0,0]: Parser returned a null Package
I don't know where i went wrong (because no where i have used '<' symbol).
Ask me for any missing detail. Any help on this would be greatly appreciated. Thank you.

Errors in codeigniter-restserver library

I want to use restful in my ci 3.03 application:
I found this tutplus tutorial
I downloaded codeigniter-restserver-master.zip file and copied Format.php and REST_Controller.php(#version 3.0.0) files into /application/libraries/REST directory
I created control application/controllers/api/Users.php :
require_once("application/libraries/REST/REST_Controller.php");
require_once("application/libraries/REST/Format.php");
class Users extends REST_Controller
{
//protected $rest_format = 'json';
function users_get()
{
//$users = $this->user_model->get_all();
$filter_username= $this->get('filter_username');
$filter_user_group= $this->get('filter_user_group');
$filter_active= $this->get('filter_active');
$sort= $this->get('sort');
$sort_direction= $this->get('sort_direction');
//, $filter_user_group, $filter_active, $sort, $sort_direction
$users_list = $this->muser->getUsersList(false, ''/*, $filter_username, $filter_user_group, $filter_active, $sort, $sort_direction, ''*/);
echo '<pre>'.count($users_list).'::$users_lists::'.print_r($users_list,true).'</pre>';
if($users_list)
{
$this->response($users, 200);
}
else
{
$this->response(NULL, 404);
}
}
AND RUNNING URL http://local-ci3.com/api/users I got many errors:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Users::$format
Filename: REST/REST_Controller.php
Line Number: 734
Backtrace:
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 734
Function: _error_handler
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 649
Function: response
File: /mnt/diskD_Work/wwwroot/ci3/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Users::$format
Filename: REST/REST_Controller.php
Line Number: 752
Backtrace:
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 752
Function: _error_handler
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 649
Function: response
File: /mnt/diskD_Work/wwwroot/ci3/index.php
Line: 292
Function: require_once
Actually I wanted to get some workable library to help me with REST api creation. I think that is preferable way istead of making from zero.
But is this library not workable or does it needs for some fixing? Sorry, what I missed is if this library only for ci 2?
I made search on this forum and found such hint :
I have the same problem when I load both Format.php and
Rest_Controller.php into a controller. After have a quick glance at
Format.php, it appears to be a standalone format conversion helper.
Try to just load Rest_Controller.php and see if your problem goes
away.
I commented line
//require_once("application/libraries/REST/Format.php");
in my controller, but I still get errors like :
Message: Undefined property: Users::$format.
I tried to review code of this library and see that invalid block when data are converted to json format, line 731-757 :
elseif ($data !== NULL)
{
// If the format method exists, call and return the output in that format
if (method_exists($this->format, 'to_' . $this->response->format))
{
// Set the format header
$this->output->set_content_type($this->_supported_formats[$this->response->format], strtolower($this->config->item('charset')));
$output = $this->format->factory($data)->{'to_' . $this->response->format}();
// An array must be parsed as a string, so as not to cause an array to string error
// Json is the most appropriate form for such a datatype
if ($this->response->format === 'array')
{
$output = $this->format->factory($output)->{'to_json'}();
}
}
else
{
// If an array or object, then parse as a json, so as to be a 'string'
if (is_array($data) || is_object($data))
{
$data = $this->format->factory($data)->{'to_json'}();
}
// Format is not supported, so output the raw data as a string
$output = $data;
}
}
If I tried to commented this block, but get error
Message: Array to string conversion
Looks like data are not converted in this case...
Is is possible to fix these errors?
Or can you, please, to tell me advice some codeigniter 3 REST api workable library with similar interface like library above?
Thanks!
I use that lib, work just fine. My suggestion is follow the more relevant installation instruction on github .
you also wrong place the lib file :
Tutorial say :
require(APPPATH'.libraries/REST_Controller.php');
You try :
require_once("application/libraries/REST/REST_Controller.php");
require_once("application/libraries/REST/Format.php");
No need to include the format because on line 407 the lib will load it. And also good to know on line 404 it will load the configuration (application/config/rest.php) it will be your default configuration, and also you can change it to suit your need.
Please let me know if you still got error using my answer :)

Yeoman Generator in CoffeeScript - HookFor Warning

I'm trying to develop a custom generator for Yeoman using CoffeeScript but I'm facing a problem. When I use the hookFor method in the constructor of my class Generator, I get a warning hookFor must be used within the constructor when I try to init my project with Yeoman and my custom generator. Here is the code of my generator in index.coffee :
path = require 'path'
util = require 'util'
yeoman = require '../../../../'
module.exports = class Generator extends yeoman.generators.Base
constructor: ->
super()
#directories = ['controllers', 'helpers', 'models', 'templates', 'views']
#hookFor 'artefact:controller', args: ['App']
deploy: ->
#directory '.', '.'
#mkdir path.join 'dev', directory for directory in #directories
Any help will be appreciated. Thanks.
Apparently, the error comes from Yeoman Generators code in the yeoman-generators/lib/base.js file.
Here is how I led to that conclusion :
The warning is caused by the variable _running set to true in hookFor function (line 296)
This variable is set to true in run function (line 78) and just after that, methods of the class Generator are iterated (line 81-137)
the constructor defined in CoffeeScript for the class Generator is called during the iteration, so #hookFor is called whereas _running is true : warning!
But, the constructor should not be called because a test is done during the iteration to prevent it (line 92) :
if ( method.constructor === '-' )
However, this test, in my opinion, should be :
if ( method === 'constructor' )
The hack does the trick. Feel free to add comment if I'm wrong.

Using Soap in magento

I'm trying to follow the information about how to use soap in magento, but always get same message in error.log
If any one experience something similar, that could give me some tip, it will be welcome.
"PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.site.com/index.php/api/?wsdl' : failed to load external entity "http://www.site.com/index.php/api/?wsdl"\n in /var/www/test.php on line 1"
$client = new SoapClient('http://www.site.com/api/?wsdl');
$session = $client->login('apiUser', 'apiKey');
$result = $client->call($session, 'somestuff.method');
$result = $client->call($session, 'somestuff.method', 'arg1');
$result = $client->call($session, 'somestuff.method', array('arg1', 'arg2', 'arg3'));
$result = $client->multiCall($session, array(
array('somestuff.method'),
array('somestuff.method', 'arg1'),
array('somestuff.method', array('arg1', 'arg2'))
));
// If you don't need the session anymore
$client->endSession($session);
where you have www.site.com in your SOAP code, replace it with localhost or whatever the correct URL is for your server. You'll also need to replace somestuff.method with real objects and methods as per the Magento documentation