Skip to content

Commit

Permalink
Merge branch 'release/ceridwen-standard-interchange-protocol-library-…
Browse files Browse the repository at this point in the history
…2.9.3'
  • Loading branch information
mdovey committed Oct 12, 2016
2 parents 45f59c0 + d89a353 commit 91a0db1
Show file tree
Hide file tree
Showing 27 changed files with 1,225 additions and 356 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Version 2.9.3: 10/10/2016
Update sample to use netty server
Added SSL Socket client connection
Updated Netty SSL server to load certificates
Dependencies: ceridwen utilitiy 1.6.2
apache commons beanutils 1.9.3
apache commons lang 3.4
apache commons logging 1.2
apache commons net 3.5
io.netty transport 4.1.5.Final
io.netty handler 4.1.5.Final

Version 2.9.2: 20/04/2016
Added netty server implementation
Added field ordering options (alphabetic or specification listed)
Expand Down
127 changes: 125 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,126 @@
## ceridwen-standard-interchange-protocol-library
## Ceridwen 3M SIP Circulation Library for Java

Java Implementation of the 3M SIP2 and NISO SIP3 Protocols for library circulation and self-check facilities.
3M SIP is an industry standard protocol by 3M to allow automatec check out terminals communicate with library systems.

The Ceridwen 3M SIP Circulation Library for Java is an Open Source (GPL v3) implementation of the 3M SIP version 2 protocol (also known as SIP2). It includes both client and server implementations and support both telnet and socket based communications.

### Problems and Issues

For general problems please contact [[email protected]](mailto:[email protected]). For bugs and feature requests, please use our [online issue tracker]().

### License

The Ceridwen Self Issue Client is available as open source under [GPL v3](http://www.gnu.org/licenses/gpl.html). Contact [[email protected]](mailto:[email protected]) for other licensing options.

### Sample Application

The following hava code demonstrates the use of the library. It starts up a simple server implementation, and then uses the client API to check out a book.

```java
public class Sample {

public static void main(String[] args) {
try {
System.setProperty("com.ceridwen.circulation.SIP.charset", "ISO8859_1");

SIPDaemon server;

// Run netty server
server = new SIPDaemon("Sample", "localhost", 12345, false, new DummyDriverFactory(), true);
server.start();

// Do sample checkout
Sample.checkOut();

// Shut down netty server
server.stop();
} catch (Exception ex) {
Logger.getLogger(Sample.class.getName()).log(Level.SEVERE, null, ex);
}
}

public static void checkOut() {
/**
* Now try basic client commands
*/
SocketConnection connection;

connection = new SocketConnection();
connection.setHost("localhost");
connection.setPort(12345);
connection.setConnectionTimeout(30000);
connection.setIdleTimeout(30000);
connection.setRetryAttempts(2);
connection.setRetryWait(500);

try {
connection.connect();
} catch (Exception ex) {
Logger.getLogger(Sample.class.getName()).log(Level.SEVERE, null, ex);
return;
}

/**
* It is necessary to send a SC Status with protocol version 2.0 else server
* will assume 1.0)
*/
SCStatus scStatusRequest = new SCStatus();
scStatusRequest.setProtocolVersion(ProtocolVersion.VERSION_2_00);

Message scStatusResponse;

try {
scStatusResponse = connection.send(scStatusRequest);
} catch (RetriesExceeded | ConnectionFailure | MessageNotUnderstood | ChecksumError | SequenceError | MandatoryFieldOmitted | InvalidFieldLength ex) {
Logger.getLogger(Sample.class.getName()).log(Level.SEVERE, null, ex);
return;
}

if (!(scStatusResponse instanceof ACSStatus)) {
Logger.getLogger(Sample.class.getName()).log(Level.SEVERE, "Error - Status Request did not return valid response from server.");
return;
}

/**
* For debugging XML handling code (but could be useful in Cocoon)
*/
scStatusResponse.xmlEncode(System.out);

/**
* Check if the server can support checkout
*/
if (!((ACSStatus) scStatusResponse).getSupportedMessages().isSet(SupportedMessages.CHECK_OUT)) {
Logger.getLogger(Sample.class.getName()).log(Level.SEVERE, "Check out not supported");
return;
}

CheckOut checkOutRequest = new CheckOut();

/**
* Now try a checkout request
*/
checkOutRequest.setPatronIdentifier("2000000");
checkOutRequest.setItemIdentifier("300000000");
checkOutRequest.setSCRenewalPolicy(Boolean.TRUE);
checkOutRequest.setTransactionDate(new Date());

Message checkOutResponse;

try {
checkOutResponse = connection.send(checkOutRequest);
} catch (RetriesExceeded | ConnectionFailure | MessageNotUnderstood | ChecksumError | SequenceError | MandatoryFieldOmitted | InvalidFieldLength ex) {
Logger.getLogger(Sample.class.getName()).log(Level.SEVERE, null, ex);
return;
}

if (!(checkOutResponse instanceof CheckOutResponse)) {
Logger.getLogger(Sample.class.getName()).log(Level.SEVERE, "Error - CheckOut Request did not return valid response from server");
return;
}
checkOutResponse.xmlEncode(System.out);

connection.disconnect();
}

}
```
51 changes: 32 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<groupId>com.ceridwen.circulation</groupId>
<artifactId>ceridwen-standard-interchange-protocol-library</artifactId>
<version>2.9.2</version>
<version>2.9.3</version>
<packaging>jar</packaging>

<name>ceridwen-standard-interchange-protocol-library</name>
Expand Down Expand Up @@ -62,14 +62,27 @@
<repository>
<id>ceridwen-libs-release</id>
<name>Ceridwen Release Repository</name>
<url>https://software.ceridwen.com/artifactory/libs-release-local</url>
<url>https://software.ceridwen.com/artifactory/libs-release</url>
</repository>
<repository>
<id>ceridwen-libs-snapshot</id>
<name>Ceridwen Snapshot Repository</name>
<url>https://software.ceridwen.com/artifactory/libs-snapshot-local</url>
<url>https://software.ceridwen.com/artifactory/libs-snapshot</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>ceridwen-plugins-release</id>
<name>Ceridwen Release Plugin Repository</name>
<url>https://software.ceridwen.com/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<id>ceridwen-plugins-snapshot</id>
<name>Ceridwen Snapshot Plugin Repository</name>
<url>https://software.ceridwen.com/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>

<dependencies>
<dependency>
Expand All @@ -90,32 +103,27 @@
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.4</version>
<version>3.5</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.2</version>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport</artifactId>
<version>4.0.36.Final</version>
<version>4.1.5.Final</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
<version>4.0.36.Final</version>
<version>4.1.5.Final</version>
</dependency>
</dependencies>

Expand Down Expand Up @@ -143,12 +151,17 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<testSourceDirectory>${basedir}/src/main/java/</testSourceDirectory>
<testClassesDirectory>${project.build.directory}/classes/</testClassesDirectory>
<test>Message#</test>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -158,7 +171,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
Expand All @@ -180,17 +193,17 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<version>2.10.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -215,15 +228,15 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.2</version>
<version>2.3</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>external.atlassian.jgitflow</groupId>
<artifactId>jgitflow-maven-plugin</artifactId>
<version>1.0-m5.1</version>
<version>1.0.0-mjf_276-SNAPSHOT</version>
<configuration>
<flowInitContext>
<masterBranchName>master</masterBranchName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@ public class MessageNotUnderstood extends Exception {
private static final long serialVersionUID = 1857825095575274480L;

public MessageNotUnderstood() {
super();
}

public MessageNotUnderstood(Throwable ex) {
super(ex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@ public class RetriesExceeded extends Exception {
private static final long serialVersionUID = 1416841113916472161L;

public RetriesExceeded() {
super();
}

public RetriesExceeded(Throwable ex) {
super(ex);
}
}
12 changes: 6 additions & 6 deletions src/main/java/com/ceridwen/circulation/SIP/fields/Fields.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ static public PositionedFieldDefinition getPositionedFieldDefinition(String mess
} catch (Exception ex) {
throw new java.lang.AssertionError(messageName + " - Positioned FieldDescriptor not defined: " + fieldName);
}
if (fld == null) {
throw new java.lang.AssertionError(messageName + " - Positioned FieldDescriptor not defined: " + fieldName);
}
// if (fld == null) {
// throw new java.lang.AssertionError(messageName + " - Positioned FieldDescriptor not defined: " + fieldName);
// }
Field fldann = fld.getAnnotation(Field.class);
if (fldann == null) {
throw new java.lang.AssertionError(messageName + " - Positioned FieldDescriptor not defined: " + fieldName);
Expand All @@ -273,9 +273,9 @@ static public TaggedFieldDefinition getTaggedFieldDefinition(String messageName,
} catch (Exception ex) {
throw new java.lang.AssertionError(messageName + " - Tagged FieldDescriptor not defined: " + fieldName);
}
if (fld == null) {
throw new java.lang.AssertionError(messageName + " - Tagged FieldDescriptor not defined: " + fieldName);
}
// if (fld == null) {
// throw new java.lang.AssertionError(messageName + " - Tagged FieldDescriptor not defined: " + fieldName);
// }
Field fldann = fld.getAnnotation(Field.class);
if (fldann == null) {
throw new java.lang.AssertionError(messageName + " - Tagged FieldDescriptor not defined: " + fieldName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
import com.ceridwen.circulation.SIP.types.enumerations.SecurityMarker;

@Command("18")
@TestCaseDefault("1801000119700101 010000AB|AJ|")
@TestCasePopulated("1813030919700101 010000ABitemIdentifier|AFscreenMessage|AGprintLine|AHdueDate|AJtitleIdentifier|APcurrentLocation|AQpermanentLocation|BGowner|BHGBP|BVfeeAmount|CF123456789|CHitemProperties|CJ19700101 010000|CK010|CM19700101 010000|")
@TestCaseDefault("1801000119700101 010000AB|AJ|CF00000|")
@TestCasePopulated("1813030919700101 010000ABitemIdentifier|AFscreenMessage|AGprintLine|AHdueDate|AJtitleIdentifier|APcurrentLocation|AQpermanentLocation|BGowner|BHGBP|BVfeeAmount|CF12345|CHitemProperties|CJ19700101 010000|CK010|CM19700101 010000|")
public class ItemInformationResponse extends Message {
private static final long serialVersionUID = 6408854778106704492L;
@PositionedField(start = 2, end = 3)
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/ceridwen/circulation/SIP/messages/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private String encode(Character sequence, boolean autoPop) throws MandatoryField
desc.getPropertyType().getName());
}
}
if (fixed.containsKey(new Integer(field.start))) {
if (fixed.containsKey(Integer.valueOf(field.start))) {
throw new java.lang.AssertionError("Positioning error inserting field at " + field.start + " for class " + this.getClass().getName());
}
fixed.put(new Integer(field.start), this.pad(value[0], field));
Expand Down Expand Up @@ -411,7 +411,7 @@ private void setProp(PropertyDescriptor desc, String value) {
if (desc.getPropertyType() == Integer.class) {
if (!value.trim().isEmpty()) {
desc.getWriteMethod().invoke(this,
new Object[] { new Integer(value.trim()) });
new Object[] {Integer.valueOf(value.trim()) });
}
return;
}
Expand Down Expand Up @@ -684,13 +684,11 @@ public void xmlEncode(OutputStream strm) {
XMLEncoder out = new XMLEncoder(strm);
out.writeObject(this);
out.flush();
out.close();
}

public static Message xmlDecode(InputStream strm) {
XMLDecoder in = new XMLDecoder(strm);
Message msg = (Message) in.readObject();
in.close();
return msg;
}

Expand Down Expand Up @@ -808,7 +806,7 @@ private Message getDefaultMessage() {
if (field.getType() == Integer.class) {
Method method = desc.getWriteMethod();
if (method != null) {
method.invoke(msg, new Object[]{new Integer(0)});
method.invoke(msg, new Object[]{Integer.valueOf(0)});
}
}
if (field.getType() == Boolean.class) {
Expand Down Expand Up @@ -878,7 +876,7 @@ private Message getPopulatedMessage() {
if (length != 0) {
value = value.substring(0, length);
}
method.invoke(msg, new Object[]{new Integer(value)});
method.invoke(msg, new Object[]{Integer.valueOf(value)});
}
if (type == String.class) {
String value = field.getName();
Expand Down
Loading

0 comments on commit 91a0db1

Please sign in to comment.