|
7 | 7 | use MIME::Parser;
|
8 | 8 | use autodie;
|
9 | 9 |
|
10 |
| -my ($inputDirectory, $newEmottakDirectory, $oldEmottakDirectory) = @ARGV; |
| 10 | +my ($inputDirectory, $newEmottakDirectory, $oldEmottakDirectory, $errorDirectory) = @ARGV; |
11 | 11 |
|
12 | 12 | if (
|
13 | 13 | not defined $inputDirectory or
|
14 | 14 | not defined $newEmottakDirectory or
|
15 |
| - not defined $oldEmottakDirectory |
| 15 | + not defined $oldEmottakDirectory or |
| 16 | + not defined $errorDirectory |
16 | 17 | ) {
|
17 |
| - die "Need directory parameters (call with command line arguments 'inputDirectory' 'newEmottakDirectory' 'oldEmottakDirectory'\n"; |
| 18 | + die "Need directory parameters (call with command line arguments 'inputDirectory' 'newEmottakDirectory' 'oldEmottakDirectory' 'errorDirectory\n"; |
18 | 19 | }
|
19 | 20 |
|
20 | 21 | my $dryRunMode = 1;
|
| 22 | + |
21 | 23 | if ($dryRunMode ne 0) {
|
22 | 24 | print "OBS! dryRunMode active, will not actually move any files!\n";
|
23 | 25 | }
|
|
28 | 30 | 'testType' => ["testService", "testAction"]
|
29 | 31 | );
|
30 | 32 |
|
31 |
| -printf "Input directory : %s\n", $inputDirectory; |
32 |
| -printf "New eMottak directory : %s\n", $newEmottakDirectory; |
33 |
| -printf "Old eMottak directory : %s\n", $oldEmottakDirectory; |
| 33 | +printf "Input directory : %s\n", $inputDirectory; |
| 34 | +printf "New eMottak directory : %s\n", $newEmottakDirectory; |
| 35 | +printf "Old eMottak directory : %s\n\n", $oldEmottakDirectory; |
34 | 36 |
|
35 | 37 | opendir(DIR, $inputDirectory) or die "Can't open $inputDirectory: $!";
|
36 | 38 |
|
37 | 39 | my $newCounter = 0;
|
38 | 40 | my $oldCounter = 0;
|
| 41 | +my $errorCounter = 0; |
39 | 42 | my $fileCounter = 0;
|
40 | 43 |
|
41 | 44 | foreach my $filename (readdir(DIR)) {
|
|
44 | 47 | my $parser = MIME::Parser->new;
|
45 | 48 | $parser->output_to_core(1); #ikke skriv fil til disk
|
46 | 49 |
|
47 |
| - # Leser epost |
48 |
| - my $entity = $parser->parse_open("$inputDirectory/$filename"); |
49 |
| - # $entity->dump_skeleton(); |
50 |
| - my $first_part = $entity->parts(0); |
51 |
| - my $body = (defined $first_part) ? $first_part->bodyhandle->as_string : $entity->bodyhandle->as_string; |
52 |
| - |
53 |
| - # Leser ebxml dokument |
54 |
| - my $xml_parser = XML::LibXML->new; |
55 |
| - my $dom = $xml_parser->parse_string($body); |
| 50 | + my $dom = eval { |
| 51 | + # Leser epost |
| 52 | + my $entity = $parser->parse_open("$inputDirectory/$filename"); |
| 53 | + # $entity->dump_skeleton(); |
| 54 | + my $first_part = $entity->parts(0); |
| 55 | + my $body = (defined $first_part) ? $first_part->bodyhandle->as_string : $entity->bodyhandle->as_string; |
| 56 | + |
| 57 | + # Leser ebxml dokument |
| 58 | + my $xml_parser = XML::LibXML->new; |
| 59 | + $xml_parser->parse_string($body); |
| 60 | + }; |
| 61 | + if ($@ ne '') { |
| 62 | + if ($dryRunMode eq 0) { |
| 63 | + move("$inputDirectory/$filename", "$errorDirectory/$filename"); |
| 64 | + } |
| 65 | + printf "Message '%s' failed with error %s", $filename, $@; |
| 66 | + $errorCounter++; |
| 67 | + next; |
| 68 | + }; |
56 | 69 |
|
57 | 70 | my $xpc = XML::LibXML::XPathContext->new($dom);
|
58 | 71 | $xpc->registerNs('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
|
|
87 | 100 | }
|
88 | 101 | }
|
89 | 102 |
|
90 |
| -printf "%s of %s files moved to new system\n", $newCounter, $fileCounter; |
91 |
| -printf "%s of %s files moved to old system\n", $oldCounter, $fileCounter; |
| 103 | +printf "\nMessages processed : %s/%s\n", $newCounter+$oldCounter+$errorCounter, $fileCounter; |
| 104 | +printf "Messages sent to new system : %s\n", $newCounter; |
| 105 | +printf "Messages sent to old system : %s\n", $oldCounter; |
| 106 | +printf "Messages sent to error : %s\n", $errorCounter; |
92 | 107 |
|
93 | 108 | closedir(DIR);
|
0 commit comments