Skip to content
This repository was archived by the owner on Dec 8, 2017. It is now read-only.

Commit 47d537d

Browse files
committed
Refactor connect_vbms:
- Reorganize Java files into standard Maven directory structure. - Remove unused xml files. - Move templates - Remove non-working decrypt hack. - Update calls to java. - Add classes/ directory. - Updates to logging. - Change location of log4j.xml. - Add lib directory to classpath to pick up .xml files. - Don't make changes from parseresponse branch.
1 parent 37dae0a commit 47d537d

13 files changed

+26
-62
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
*.env
22
*.class
3+
*.log
34
src/intermediate_files/*
45
src/out.txt
56
src/*.log
6-
envs
77
.ruby-version
88
.ruby-gemset

classes/.keep

Whitespace-only changes.

src/log4j.xml lib/log4j.xml

File renamed without changes.

log/.keep

Whitespace-only changes.

src/Makefile

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
UploadDocumentWithAssociations.class: UploadDocumentWithAssociations.java
2-
javac -classpath '../lib/*' UploadDocumentWithAssociations.java
1+
UploadDocumentWithAssociations.class: main/java/UploadDocumentWithAssociations.java
2+
javac -classpath '../lib/*' -d ../classes main/java/UploadDocumentWithAssociations.java
33

4-
DecryptMessage.class: DecryptMessage.java
5-
javac -classpath '../lib/*' DecryptMessage.java
4+
DecryptMessage.class: main/java/DecryptMessage.java
5+
javac -classpath '../lib/*' -d ../classes main/java/DecryptMessage.java
66

77
.PHONY: build
88
build: UploadDocumentWithAssociations.class DecryptMessage.class
99

1010
.PHONY:run
1111
run:
12-
java -classpath '.:../lib/*' UploadDocumentWithAssociations | ./run.rb
12+
java -classpath '../classes:../lib/*:../lib' UploadDocumentWithAssociations
1313

1414
.PHONY:decrypt
1515
decrypt: DecryptMessage.class
1616
# Decrypt fails... but run decrypt_hack to pull the message out of the log
17-
-java -classpath '.:../lib/*' DecryptMessage
17+
java -classpath '../classes:../lib/*:../lib' DecryptMessage
1818
./decrypt_hack.rb

src/decrypt_hack.rb

-7
This file was deleted.

src/getDocumentTypes.xml

-7
This file was deleted.
File renamed without changes.

src/send.rb

+19-24
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
require 'xml'
88

99
# global log function
10-
$logfile = "/usr/local/var/log/connect_vbms.log"
10+
$logfile = "../log/connect_vbms.log"
1111
def log(msg)
12-
log = File.open($logfile, 'a')
12+
log = open_relative($logfile, 'a')
1313
log.write("#{Time.now.utc.iso8601}: #{msg}")
1414
log.write("\n")
15+
log.write msg
1516
end
1617

1718
# needs to happen before we change directories
@@ -21,7 +22,7 @@ def rel(name)
2122
end
2223

2324
# return open file relative to this file's current directory
24-
def openrel(name, mode='r')
25+
def open_relative(name, mode='r')
2526
File.open(rel(name), mode)
2627
end
2728

@@ -41,22 +42,19 @@ def sh(cmd, ignore_errors=false)
4142

4243
# Given an env name (like "test", "uat", "pre") go get the appropriate environment
4344
# variables and make them relative to this file. Return an env hash.
44-
def getenv(envname)
45-
envdir = File.join(ENV["CONNECT_VBMS_ENV_DIR"], envname)
46-
45+
def getenv(environment_name)
4746
env = {}
47+
environment_directory = File.join(ENV["CONNECT_VBMS_ENV_DIR"], environment_name)
4848
env[:url] = ENV.fetch("CONNECT_VBMS_URL", nil)
4949
env[:keyfile] = ENV.fetch("CONNECT_VBMS_KEYFILE", nil)
5050
env[:saml] = ENV.fetch("CONNECT_VBMS_SAML", nil)
5151
env[:key] = ENV.fetch("CONNECT_VBMS_KEY", nil)
5252
env[:keypass] = ENV.fetch("CONNECT_VBMS_KEYPASS", nil)
5353
env[:cacert] = ENV.fetch("CONNECT_VBMS_CACERT", nil)
5454
env[:cert] = ENV.fetch("CONNECT_VBMS_CERT", nil)
55-
5655
[:keyfile, :saml, :key, :cacert, :cert].each do |k|
57-
env[k] = File.absolute_path(File.join(envdir, env[k])) if env[k]
56+
env[k] = File.absolute_path(File.join(environment_directory, env[k])) if env[k]
5857
end
59-
6058
env
6159
end
6260

@@ -76,14 +74,14 @@ def upload_doc(options)
7674
log("Connecting with env: #{env}")
7775
file = prepare_xml(options[:pdf], options[:file_number], options[:received_dt], options[:first_name], options[:middle_name], options[:last_name], options[:exam_name])
7876
encrypted_xml = prepare_upload(file, env)
79-
response = send_document(encrypted_xml, env, options[:pdf])
77+
response = send_document(encrypted_xml, env, options)
8078
#handle_response(response)
8179
rescue Exception => e
8280
puts e.backtrace
8381
log(e.backtrace)
8482
puts e.message
8583
log(e.message)
86-
File.open("/tmp/signed.xml", 'w').write(encrypted_xml)
84+
open_relative("../log/#{options[:file_number]}-signed.xml.log", 'a').write(encrypted_xml)
8785
ensure
8886
file.close
8987
file.unlink
@@ -127,16 +125,14 @@ def prepare_xml(pdf, file_number, received_dt, first_name, middle_name, last_nam
127125
# TODO: true if the claim associated with this evaluation is still pending,
128126
# false otherwise
129127
newMail = "true"
130-
131-
template = openrel("upload_document_xml_template.xml.erb").read
128+
template = open_relative("templates/upload_document_xml_template.xml.erb").read
132129
xml = ERB.new(template).result(binding)
133130
log("Unencrypted XML:\n#{xml}")
134-
135131
write_tempfile(xml)
136132
end
137133

138134
def prepare_upload(xmlfile, env)
139-
sh "java -classpath '.:../lib/*' UploadDocumentWithAssociations #{xmlfile.path} #{env[:keyfile]} #{env[:keypass]}"
135+
sh "java -classpath '../classes:../lib/*:../lib' UploadDocumentWithAssociations #{xmlfile.path} #{env[:keyfile]} #{env[:keypass]}"
140136
end
141137

142138
def inject_saml(doc, env)
@@ -172,17 +168,16 @@ def build_request(url, data, headers, key: nil, keypass: nil, cert: nil, cacert:
172168
request
173169
end
174170

175-
def send_document(xml, env, pdf)
171+
def send_document(xml, env, options)
176172
# inject SAML header
177173
doc = XML::Parser.string(xml).parse
178174
inject_saml(doc, env)
179175
remove_mustUnderstand(doc)
180176
xml = doc.to_s
181-
File.open("/tmp/final.xml", 'w').write(xml)
182-
filename = File.split(pdf)[1]
183-
pdf = IO.read(pdf)
184-
185-
req = ERB.new(openrel("mtom_request.erb").read).result(binding)
177+
open_relative("../log/#{options[:file_number]}-final.xml.log", 'a').write(xml)
178+
filename = File.split(options[:pdf])[1]
179+
pdf = IO.read(options[:pdf])
180+
req = ERB.new(open_relative("templates/mtom_request.erb").read).result(binding)
186181
headers = {
187182
'Content-Type' => 'Multipart/Related; type="application/xop+xml"; start-info="application/soap+xml"; boundary="boundary_1234"'
188183
}
@@ -230,7 +225,7 @@ def handle_response(response)
230225
# now here's the hackiest thing in the world. This command is going to fail,
231226
# because we can't get the signatures to properly get decrypted. So run the
232227
# command, handle the error, and pull the message out of the file >:|
233-
sh "java -classpath '.:../lib/*' DecryptMessage", true
228+
sh "java -classpath '../classes:../lib/*' DecryptMessage", true
234229

235230
end
236231

@@ -273,7 +268,7 @@ def parse(args)
273268
options[:env] = v
274269
end
275270

276-
opts.on("--logfile [logfile]", "Logfile to use. Defaults to /usr/local/var/log/connect_vbms.log") do |v|
271+
opts.on("--logfile [logfile]", "Logfile to use. Defaults to ../log/connect_vbms.log") do |v|
277272
$logfile = v
278273
end
279274
end
@@ -291,4 +286,4 @@ def parse(args)
291286
end
292287

293288
options = parse(ARGV)
294-
upload_doc(options)
289+
upload_doc(options)
File renamed without changes.

src/uploadDocumentWithAssociations.xml

-17
This file was deleted.

0 commit comments

Comments
 (0)