Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Seekers of Perl Wisdom

( #479=superdoc: print w/ replies, xml ) Need Help??

If you have a question on how to do something in Perl, or you need a Perl solution to an actual real-life problem, or you're unsure why something you've tried just isn't working... then this section is the place to ask. Post a new question!

However, you might consider asking in the chatterbox first (if you're a registered user). The response time tends to be quicker, and if it turns out that the problem/solutions are too much for the cb to handle, the kind monks will be sure to direct you here.

User Questions
A dreaded SOAP server with ws-security
3 direct replies — Read more / Contribute
by SuperSparky
on Jun 30, 2015 at 14:11

    I have been pulling my hair out with this one, and it shouldn't be too difficult (but then again, when is SOAP simple?). I have been tasked with coding a SOAP server (NOT client) that incorporates WS-Security. I realize everyone must be pointing and laughing by now, but I have no choice with this. I've used the sample code in the SOAP::Lite docs as a starting point, but it always rejects ANY transaction with " mustUnderstand="1" " in it. I turn that off, I am able to read the header and process the WS header myself, but with that on, I don't get that far. SOAP::Lite just bounces it back saying it doesn't understand.

    So... How do I get SOAP::Lite to "understand" or at least accept the envelope and give me a SOM to work with?

    Please keep in mind I HAVE to write this server according to WSDL, and sample envelope given to me, as this is how the (very large) customer's system works. I also cannot tell them to turn off "mustUnderstand" either.

    Luckily, their authentication mechanism is only "passwordText", so no need for decryption etc, as it is on HTTPS. I just need to get to the header once a SOM is given to me is all. I need to make SOAP::Lite ""understand" what it doesn't understand, and I cannot find anything anywhere about WS-Security for SERVERS. There's a boat load about clients, but nothing on servers.

    Here's the sample posted envelope I am to make work (without the body for disclosure reasons):

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header> <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-2 +00401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1"> <wsse:UsernameToken wsu:Id="unt_5KBJ2WZxfTuiyZqf" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasi +s-200401-wss-wssecurity-utility-1.0.xsd"> <wsse:Username>SA_User</wsse:Username> <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis +-200401-wss-username-token-profile-1.0#PasswordText"> sa </wsse:Password> <wsse:Nonce>MC45NzcwNjA5MTgyMDk2OTIz</wsse:Nonce> <wsu:Created>2010-08-31T20:56:14Z</wsu:Created> </wsse:UsernameToken> </wsse:Security> </soapenv:Header> <soapenv:Body> blah... blah... blah... </soapenv:Body> </soapenv:Envelope>

    This is my test server code running as a CGI on Apache

    use strict; use SOAP::Transport::HTTP; SOAP::Transport::HTTP::CGI ->dispatch_to('Quote') ->handle; BEGIN { package Quote; use vars qw(@ISA); @ISA = qw(Exporter SOAP::Server::Parameters); use SOAP::Lite; use Data::Dumper::Simple; sub GetQuote { my @params = @_; print STDERR Dumper(\@params); return('ok'); } }

    This is my test code to send my test envelope:

    use strict; use LWP::UserAgent; use HTTP::Request::Common; my $ua = LWP::UserAgent->new(agent => 'perl post'); my $file = $ARGV[0]; my $msg = slurp_file($file); my $resp = $ua->request(POST 'http://localhost/perl/server.cgi', Content_Type => 'text/xml', Content => $msg); print $resp->error_as_HTML unless $resp->is_success; print $resp->as_string; exit(0); sub slurp_file { my $file = shift; # Read in a text file without using open return(do { local( @ARGV, $/ ) = $file ; <> }); }

    Here's the response back:

    <?xml version="1.0" encoding="UTF-8"?><soap:Envelope soap:encodingStyl +e="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://sche +mas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap +.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xml +ns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><soap:F +ault><faultcode>soap:MustUnderstand</faultcode><faultstring>Unrecogni +zed header has mustUnderstand attribute set to 'true'</faultstring></ +soap:Fault></soap:Body></soap:Envelope>

    I REALLY don't want to have to create my own SOAP handler to get around this. I'm hoping for some override, something.

wild cards in Vertica
1 direct reply — Read more / Contribute
by pragov
on Jun 30, 2015 at 14:00
    Hi All,

    I have a perl-Vertica question. I need to pass a combination of a wild card and complete value of a field. It will be a combination of prefix and others. The example is ('A','BCD-UT1','MDO-CT1'). The actual value of A is ABC-EF2.But users can just click on Prefix,A to get all values starting with A. I tried,

    if ($clnm ne ""){ $cnt = @parts = split(/\,/, $ clnm ); $clnm = "'"; for ($i = 0; $i < $cnt; $i++) { $clnm = $clnm . $parts[$i]; ($clnm = $clnm . "%','") if ($i < $cnt - 1); } $clnm = $clnm . "%'"; } and then used it in if ($clnm ne "") { $Where = $Where . "AND m.CLNAME LIKE $clnm %’ OR m. +CLNAME IN ($clnm ) "; }.

    It is not working. The SQL either takes LIKE('A%') or IN ('ABC-EF2','BCD-UT1','MDO-CT1'), but not the combination. How to retrieve the value,('A','BCD-UT1','MDO-CT1')?

    Thanks, pragov
CGI to redirect using sessions
3 direct replies — Read more / Contribute
by lewars
on Jun 30, 2015 at 13:24

    We have built a simple Perl CGI to allow us to check for SiteMinder SM Session cookies, variables passed in the URI and to redirect the browser to our Federation server while maintaining the Federation Session ticket.

    The requestor will be sent to an error page if any of these conditions exist:

  • If no SiteMinder SM Session is provided there is an error
  • If no Resume Path is set, meaning there is no Ping Federation ticket
  • If browser posts the request and was already sent to the script within 15 seconds, indicating a loop
  • I have used several code examples on Perl Monks, forgive me for not detailing each one in the script below....

    I will gladly accept any tips to make the code more terse/concise, thanks in advance!

    The script is hosted on Apache and is executed called like the following:

  • https://localhost/wrp/resumepath.pl?resumePath=%2Fidp%2FXRTG8%2Fresume%2Fidp%2Fprp.ping&env=prod
  • #!/usr/bin/perl # # PROGRAM: resumepath.pl # # PURPOSE: This script checks the request for cookies and environ +ment variables and redirects customer # back to the federation environment with good session # CREATED: June 30, 2015 by Mitchell Lewars # Thanks for help to Björn Vildljung # Lots of examples used from Perl Monks web site use CGI qw(:standard); #use warnings; $query = new CGI; $perror = 0; #//Set to 1 in case of an error. $wearelooping = 0; #//Set to one if a user returns withing 15 secon +ds, indicating a redirect-loop. $redirectURL = "https://federate-qa.localhost.com"; #---- Next get the current values $gotcookies = $ENV{"HTTP_COOKIE"}; $env = $query->param('env'); $resumepath = $query->param('resumePath'); #// Check for the env= entry in the URL. If it is set to prod, use pro +d federation, else use QA. if ( $env =~ 'prod') { $redirectURL = "https://federate.localhost.co +m"} #// Check that the PF-session information is passed as expected, if no +t, we got an error. Otherwise, add it to redirectURL if ( $resumepath ) { $redirectURL .= $resumepath } else { $perror=1 } # Verify that there is an SMSESSION, otherwise we got somebody accessi +ng us the wrong way, and therefor probably for the wrong reasons. ERR +OR! #$perror = 1; # if customer has no SMSESSION they reached this page in + error if (!( $gotcookies =~ /smsession/i)) { $perror = 1} # Check if there is already an SMPF, if so we are looping if ( $gotcookies =~ /smpf/i) { $wearelooping = 1} #// Check to see if a Cookie named SMPF is avalible. If not, we set it + and give it a 15 second lifetime. If it is there, we got a redirect +loop. if (($wearelooping eq 0) && ($perror eq 0)) { $cookie = $query->cookie(-name=>'SMPF', -value=>'1', -expires=>'+15s', -path=>'/'); print $query->redirect( -cookie => $cookie, -uri => "$redirectURL"); print $query->start_html( -title=>'Login'); print $query->end_html; } else { $cookie = $query->cookie(-name=>'SMPF', -value=>'', -expires=>'now', -path=>'/'); print $query->header(-cookie=>$cookie); print $query->meta(''); print $query->start_html('Login'); print $query->body("<big><big><b>Redirect loop!</b></big></big><b +r><br> You have been assigned a SESSION-cookie, as confirmation that +you have successfully logged in. For some reason the login-servers wh +o needs this cookie is not getting it from your browser, causing a lo +op of redirection. Please try to go back to the site you want to logi +n to and try again. <b>You should not need to enter your credentials +again</b>. If this error is reoccurring for you, try using a differen +t browser."); print $query->end_html; }
Get the number of the current test when debugging a test script
4 direct replies — Read more / Contribute
by Dumu
on Jun 30, 2015 at 07:00

    I'm testing a module I'm developing.

    To run the module, I have a test script which initialises the module.

    e.g.:
    • tests.t
    • module.pm

    There's a bug in the module that is causing the test to fail after a certain test number.

    I'd like to run the test using the Perl debugger perl5db.pl and break after the nth test. Is there a way to monitor the variable showing how many tests have been run?

    Test::Builder has a $current_test package variable but I can't seem to access it. I'm using Test::Most.

how to get the local variable value outside the box
4 direct replies — Read more / Contribute
by bhushanQA
on Jun 30, 2015 at 05:53
    I have this code:
    if ($resp->is_success) { my $location_id= $resp->header( 'Location' ); #my $str = print "Received reply: $message\n"; # print "$message\n"; $location_id=~ /.*\/(\d+)$/; my $location_id= $1 || ''; print "$location_id\n"; }
    The variable location_id's scope is inside the box only, but I want to use the same variable and its value. How Can I use that variable and its value outside the box.
How to pass variable in the LWP module
4 direct replies — Read more / Contribute
by bhushanQA
on Jun 30, 2015 at 05:10
    I am writing code using LWP module ( to send the HTTP request) I am sending HTTP request with following content: $req->content('{"type":"mcc","expression":"716*","order":1,"match-type":"regex-match","category"->'$location_id'}') I want to pass the variable to the "category" part, how Can I pass the variable "$location_id" ( variable is already defined and having some value.)
[perl]how to do using threads to write worksheets of excel
3 direct replies — Read more / Contribute
by L_WC
on Jun 30, 2015 at 04:23
    It can't be wrote in threads in different worksheet, like "$workbookNodeList->sheets()->2->write(0,0, 'j8', $formatNodeList;" it does not work. could anyone help me? How to write worksheets on same time by threads? thanks.
    my $nodeList = [ ['AMS', 'a'], ['APJ', 'ap'], ['EMEA', 'e'], ]; my $workbookNodeList = Excel::Writer::XLSX->new("Node_List.xlsx"); $workbookNodeList->set_properties( title => 'Node List', author => 'L_WC demo', comments => 'Node List', ); my $formatNodeList = $workbookNodeList->add_format(bg_color => 44); $formatNodeList->set_align('center'); my $worksheetNodeList = $workbookNodeList->add_worksheet('AMS'); my $worksheetNodeList1 = $workbookNodeList->add_worksheet('APJ'); my $worksheetNodeList2 = $workbookNodeList->add_worksheet('EMEA'); my @arr = ($nodeList->[0], $nodeList->[1], $nodeList->[2]); my @ar = ('fff'); foreach (@arr) { $_ = threads->new(\&doSomething, $_->[0], $_->[1], $workbookNodeLis +t, $formatNodeList); } foreach(@arr){ $_->join(); } $workbookNodeList->close(); print "Node List is Done."; sub doSomething{ my ($region, $sql, $workbookNodeList, $formatNodeList) = @_; if($region eq 'AMS'){ [$workbookNodeList->sheets()]->[0]->write(0,0, 'rrrrrr', $formatNo +deList); print "AMS -----DONE.\n"; } if($region eq 'APJ'){ [$workbookNodeList->sheets()]->[1]->write(0,0, '1', $formatNodeLis +t); print "APJ -----DONE.\n"; } if($region eq 'EMEA'){ [$workbookNodeList->sheets()]->[2]->write(0,0, 'j8', $formatNodeLi +st); print "EMEA -----DONE.\n"; } }
reading a text file into hash
4 direct replies — Read more / Contribute
by Anonymous Monk
on Jun 30, 2015 at 03:50

    I am new to perl.I have a text file.I want to read it into hash and array.Please help

    { "InstanceStatuses": [ { "InstanceId": "i-308c0b3c", "InstanceState": { "Code": 16, "Name": "running" }, "AvailabilityZone": "us-west-2b", "SystemStatus": { "Status": "ok", "Details": [ { "Status": "passed", "Name": "reachability" } ] }, "InstanceStatus": { "Status": "ok", "Details": [ { "Status": "passed", "Name": "reachability" } ] } } ] }
Perl Scripts Terminates unexpectedly
2 direct replies — Read more / Contribute
by gvbals
on Jun 30, 2015 at 02:13
    We have a set of perl scripts. We don't have any exception handling. Sometime the scripts terminates unexpectedly. How to find out the reason for the same/
multiple backreferences in a substitution
1 direct reply — Read more / Contribute
by wrinkles
on Jun 29, 2015 at 23:02
    Gentle Monks,

    I wrote a (perl6) script that collects class definitions from the HTML head in a hash, and inlines the style by substitution into the body. Here's the substitution:

    UPDATE: match is actually coming from the "if" and "while" statements, not the repeated regex as I thought. Works without capture braces in repeated block. Yikes, never mind!

    repeat { # Replace class with inline styles (repeatedly) $new ~~ s/ class \= \" \w+ \" / style="%classes{ $0.Str }" /; } while $new ~~ / class \= \" (\w+) \" /;

    Yes it works, I'm just not convinced there isn't a slicker way. In particular, is there a simple way to substitute a capture at the corresponding match location, using a global substitution ( or something else entirely)?

    TIA! The full script is below:


Add your question
Title:
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":


  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (7)
    As of 2015-07-01 00:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      What kind of chocolate gives you the most pleasure?















      Results (805 votes), past polls