Skip to content

Commit

Permalink
Merge pull request #56 from UCL-RITS/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Raquel Alegre committed Mar 9, 2016
2 parents 523a76f + fec8775 commit e18a31a
Show file tree
Hide file tree
Showing 123 changed files with 614 additions and 74,204 deletions.
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ dependency-reduced-pom.xml
target/
temp/
/parser.out
*.py
python/nammu/controller/NammuController$py.class
python/nammu/controller/__init__$py.class
*$py.class
*.jar
*.pyc
parsetab.py
.tags
**/.cache
**/effective-pom*.xml
200 changes: 107 additions & 93 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>uk.ac.ucl.rc.development.oracc</groupId>
<artifactId>nammu</artifactId>
<version>0.0.2-SNAPSHOT</version>
<version>0.0.3</version>
<packaging>jar</packaging>

<name>nammu</name>
Expand All @@ -19,63 +19,72 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
<version>2.7-rc1</version>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jython</artifactId>
<version>1.2.4</version>
</dependency>
</dependencies>

<build>

<resources>
<resource>
<directory>python</directory>
</resource>
</resources>

<plugins>
<!-- Make sure resources like toolbar icons are copied to final

<!-- Make sure resources like toolbar icons are copied to final
jar -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/resources</outputDirectory>
<resources>
<resource>
<directory>${basedir}/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

<!-- A little outdated plugin needed to import all the python
modules needed by pyoracc. It works using easy_install + <param>.
It is old (2011) and the latest version of Mako and Ply won't work,
thus I needed to force older versions.
TODO: Update this plugin in my own mvn repo and use latest versions
of all <param>s. -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/resources</outputDirectory>
<resources>
<resource>
<directory>${basedir}/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

<!-- A little outdated plugin needed to import all the python
modules needed by pyoracc. It works using easy_install + <param>. -->
<plugin>
<groupId>net.sf.mavenjython</groupId>
<artifactId>jython-compile-maven-plugin</artifactId>
<version>1.1</version>
<version>1.3</version>
<executions>
<execution>
<id>before-tests</id>
<phase>test-compile</phase>
<goals>
<goal>jython</goal>
</goals>
</execution>
<execution>
<id>packaging</id>
<phase>package</phase>
<goals>
<goal>jython</goal>
Expand All @@ -84,33 +93,36 @@
</executions>
<configuration>
<libraries>
<param>nose</param>
<param>ply==3.4</param>
<param>https://pypi.python.org/packages/source/M/Mako/Mako-0.9.1.tar.gz</param>
<param>requests</param>
<param>pytest</param>
<param>mako</param>
<param>ply</param>
<param>https://github.com/ucl/pyoracc/archive/master.tar.gz</param>
</libraries>
</configuration>
</plugin>
<!-- Aggregate the project output along with its dependencies, and
other files into a single distributable archive. Note if this plugin
is not used, jython.jar which is essential won't be attached and

<!-- Aggregate the project output along with its dependencies, and
other files into a single distributable archive. Note if this plugin
is not used, jython.jar which is essential won't be attached and
Nammu won't work. -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>uk.ac.ucl.rc.development.oracc.nammu.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- The jar-with-dependencies is our main distributable jar, so
give it a sensible name and remove the default suffix
reated by this plugin -->
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<mainClass>uk.ac.ucl.rc.development.oracc.nammu.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- The jar-with-dependencies is our main distributable jar, so
give it a sensible name and remove the default suffix
reated by this plugin -->
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<phase>package</phase>
Expand All @@ -119,44 +131,46 @@
</goals>
</execution>
</executions>
</plugin>
</plugin>

</plugins>

</build>

<reporting>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.15</version>
<reportSets>
<reportSet>
<reports>
<report>checkstyle</report>
</reports>
</reportSet>
</reportSets>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
</plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.15</version>
<reportSets>
<reportSet>
<reports>
<report>checkstyle</report>
</reports>
</reportSet>
</reportSets>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.3</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.5</version>
</plugin>

</plugins>
</reporting>

Expand Down
117 changes: 117 additions & 0 deletions python/nammu/SOAPClient/HTTPRequest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
from email.mime.application import MIMEApplication
from email.encoders import encode_7or8bit
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase

class HTTPRequest(object):
"""
Builds an HTTP GET or POST request that ORACC's server understands to send
and retrieve ATF data.
"""
def __init__(self, url, method, **kwargs):
self.method = method
self.url = url
if method == 'POST':
if 'command' in kwargs.keys():
self.create_request_message(kwargs['command'], kwargs['keys'],
kwargs['attachment'])
else:
self.create_response_message(kwargs['keys'])

def create_request_message(self, command, keys, attachment):
"""
Send attachment to server containing ATF file and necessary data to
run given command (validate, lemmatise, etc).
"""
self.create_soap_envelope(command=command,
keys=keys,
attachment=attachment)

def create_response_message(self, keys):
"""
Asks the server for the response request.zip attachment containing
validated/lemmantised/etc ATF file.
"""
self.create_soap_envelope(keys=keys)

def create_request_body(self):
pass

def create_request_headers(self):
request_headers = ['Host', 'Content-Length', 'Connection']
body_headers = ['Content-ID', 'Content-Transfer-Encoding']
request_header_values = [self.url, len(str(mtombody)), 'close']
envelope_header_values = ['<SOAP-ENV:Envelope>', 'binary']
attachment_header_values = ['request_zip', 'binary']

pass

def create_soap_envelope(self, **kwargs):
"""
Format SOAP envelope to be attached in HTTP POST request.
"""
#The number of keys in the SOAP envelope depends on the command and
#the message type (Request/Response)
osc_data_keys = ''

#Only Request messages have data, but the template has a reference to
#it in both cases.
data = ''

if 'command' in kwargs.keys():
osc_data_keys += '<osc-data:key>{}</osc-data:key>'.format(kwargs['command'])
message_type = 'Request'
data += """<osc-data:data>
<osc-data:item xmime5:contentType="*/*">
<xop:Include href="cid:request_zip"/>
</osc-data:item>
</osc-data:data>"""
else:
message_type = 'Response'

for key in kwargs['keys']:
osc_data_keys += '<osc-data:key>{}</osc-data:key>'.format(key)

envelope = """<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xop="http://www.w3.org/2004/08/xop/include"
xmlns:xmime5="http://www.w3.org/2005/05/xmlmime"
xmlns:osc-data="http://oracc.org/wsdl/ows.xsd"
xmlns:osc-meth="http://oracc.org/wsdl/ows.wsdl">
<SOAP-ENV:Body>
<osc-meth:{type}>
<osc-data:keys>
{keys}
</osc-data:keys>
{data}
</osc-meth:{type}>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>""".format(type=message_type,
keys=osc_data_keys,
data=data)
self.envelope = envelope

def get_soap_envelope(self):
return self.envelope

def get_headers(self):
"""
Return dict with message headers - ready to use by requests module.
"""
pass

def get_body(self):
"""
Return dict with message body/payload - ready to use by requests module.
"""
pass

def handle_server_error(self):
"""
Raise an exception when server can't be reached or request times out.
"""
pass
Loading

0 comments on commit e18a31a

Please sign in to comment.