# We have invalid xml, or we can't figure out what kind of request this is
# Handle error here
}
- my $response =
-"<HTML> <HEAD> <TITLE>Hello There</TITLE> </HEAD> <BODY> <H1>Hello You Big JERK!</H1> Who would take this book seriously if the first eaxample didn't say \"hello world\"? </BODY> </HTML>";
- return $response;
+#my $response = "<HTML> <HEAD> <TITLE>Hello There</TITLE> </HEAD> <BODY> <H1>Hello You Big JERK!</H1> Who would take this book seriously if the first eaxample didn't say \"hello world\"? </BODY> </HTML>";
+
+ #return $response;
+ return $request_type;
}
=head2 handle_initiation
warn "Invalid xml, caught error: $_";
};
if ($dom) {
- return ('lookup_item');
+
+ # should check validity with validate at this point
+ my $request_type = $self->parse_request($dom);
+ return $request_type;
}
else {
return;
}
}
+sub validate {
+
+ # this should perhaps be in it's own module
+ my $self = shift;
+ my $dom = shift;
+ my $validity = $dom->is_valid();
+
+ # we could validate against the dtd here, might be good?
+ # my $dtd = XML::LibXML::Dtd->parse_string($dtd_str);
+ # my $validity = $dom->is_valid($dtd);
+ # perhaps we could check the ncip version and validate that too
+ return $validity;
+}
+
+sub parse_request {
+ my $self = shift;
+ my $dom = shift;
+ my $nodes = $dom->findnodes('/*');
+ if ( $nodes->[0]->nodeName() ne 'ns1:NCIPMessage' ) {
+
+ # we don't have a valid ncip message
+ # bail out
+ warn "bad xml";
+ }
+ else {
+ my @childnodes = $nodes->[0]->childNodes();
+
+ # the second child should be the type of request
+ if ( $childnodes[1] && $childnodes[1]->nodeName =~ /ns1\:(.*)/ ) {
+ return $1;
+ }
+ else {
+ # just while developing return not found
+ return ('Not_found');
+ }
+ }
+
+ return 0;
+}
+
1;
use strict;
use warnings;
+use File::Slurp;
-use Test::More tests => 5; # last test to print
+use Test::More tests => 7; # last test to print
use lib 'lib';
ok( my $ncip = NCIP->new('t/config_sample'), 'Create new object' );
my $xml = <<'EOT';
-<xml>
-</xml>
+<?xml version="1.0" encoding="UTF-8"?>
+<ns1:NCIPMessage
+ ns1:version="http://www.niso.org/schemas/ncip/v2_0/imp1/xsd/ncip_v2_0.xsd" xmlns:ns1="http://www.niso.org/2008/ncip">
+</ns1:NCIPMessage>
EOT
ok( my $response = $ncip->process_request($xml), 'Process a request' );
# anyway
ok( !$ncip->handle_initiation($xmlbad), 'Bad xml' );
ok( $ncip->handle_initiation($xml), 'Good XML' );
+
+my $lookupitem = read_file('t/sample_data/LookupItem.xml');
+
+ok( my $response = $ncip->process_request($lookupitem), 'Try looking up an item');
+is ($response, 'LookupItem', 'We got lookupitem');