|
From: <bob...@us...> - 2004-01-13 10:42:02
|
Update of /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/packaging
In directory sc8-pr-cvs1:/tmp/cvs-serv847/src/hk/hku/cecid/phoenix/message/packaging
Modified Files:
EbxmlMessage.java PKISignatureImpl.java
Log Message:
Change the MSH to support Customize Persistence Handler.
However, haven't changed the code on backup, archive and export yet.
Index: EbxmlMessage.java
===================================================================
RCS file: /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/packaging/EbxmlMessage.java,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** EbxmlMessage.java 15 Dec 2003 09:51:34 -0000 1.40
--- EbxmlMessage.java 13 Jan 2004 10:41:58 -0000 1.41
***************
*** 70,73 ****
--- 70,74 ----
import hk.hku.cecid.phoenix.message.handler.MessageServer;
import hk.hku.cecid.phoenix.message.handler.MessageServerException;
+ import hk.hku.cecid.phoenix.message.handler.PersistenceHandler;
import hk.hku.cecid.phoenix.message.packaging.validation.EbxmlValidationException;
import hk.hku.cecid.phoenix.message.packaging.validation.SOAPValidationException;
***************
*** 189,193 ****
*/
private String filename;
!
/**
* Constructs an <code>EbxmlMessage</code> using the default JAXM
--- 190,202 ----
*/
private String filename;
!
! /**
! * Optional persistence name in which the message is persisted
! */
! private String persistenceName;
! /**
! * Optional persistence handler in which the message is persisted
! */
! private PersistenceHandler persistenceHandler;
/**
* Constructs an <code>EbxmlMessage</code> using the default JAXM
***************
*** 1596,1599 ****
--- 1605,1635 ----
this.soapEnvelopeBytes = soapEnvelopeBytes;
}
+
+ /**
+ * set the persistence info to the message
+ * @param persistenceName the name on the persistence handler
+ * @param handler the persistence handler
+ */
+ public void setPersistenceInfo(String persistenceName,
+ PersistenceHandler handler) {
+ this.persistenceName = persistenceName;
+ persistenceHandler = handler;
+ }
+
+ /**
+ * get the Persistence name if it is stored
+ * @return the persitence name
+ */
+ public String getPersistenceName() {
+ return persistenceName;
+ }
+
+ /**
+ * get the persistence handler if it is stored
+ * @return the persistence handler
+ */
+ public PersistenceHandler getPersistenceHandler() {
+ return persistenceHandler;
+ }
}
Index: PKISignatureImpl.java
===================================================================
RCS file: /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/packaging/PKISignatureImpl.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** PKISignatureImpl.java 15 Dec 2003 09:51:35 -0000 1.13
--- PKISignatureImpl.java 13 Jan 2004 10:41:58 -0000 1.14
***************
*** 70,75 ****
import hk.hku.cecid.phoenix.message.handler.ErrorMessages;
- import hk.hku.cecid.phoenix.message.packaging.Signature;
- import hk.hku.cecid.phoenix.message.packaging.SignatureException;
import hk.hku.cecid.phoenix.message.packaging.validation.SOAPValidationException;
import hk.hku.cecid.phoenix.pki.ApacheXMLDSigner;
--- 70,73 ----
***************
*** 81,88 ****
--- 79,91 ----
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
+ import java.io.IOException;
+ import java.io.InputStream;
+ import java.io.OutputStream;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
import java.util.Iterator;
+
+ import javax.activation.DataSource;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.soap.SOAPElement;
***************
*** 248,251 ****
--- 251,290 ----
throw new Error("Not supported");
}
+
+ private int loadInputStreamToOutputStream(InputStream istream,
+ OutputStream ostream, int skipped, int expectedLength)
+ throws IOException {
+ int bufferSize = 2048;
+ byte[] buffer = new byte[bufferSize];
+ int skippedBytes = 0;
+ int read = 0;
+ while(read != -1 && skippedBytes < skipped) {
+ read = istream.read(buffer, 0,
+ calculateReadSize(skippedBytes, skipped, bufferSize));
+ if (read != -1) {
+ skippedBytes += read;
+ }
+ }
+ int length = 0;
+ read = 0;
+ while(read != -1 && length < expectedLength) {
+ read = istream.read(buffer, 0,
+ calculateReadSize(length, expectedLength, bufferSize));
+ if (read != -1) {
+ ostream.write(buffer, 0, read);
+ length += read;
+ }
+ }
+ return length;
+ }
+
+ private int calculateReadSize(int read, int expected, int bufferSize) {
+ int remain = expected - read;
+ if (remain > bufferSize) {
+ return bufferSize;
+ } else {
+ return remain;
+ }
+ }
boolean verify(char[] password, String keyStoreLocation,
***************
*** 255,263 ****
ByteArrayOutputStream baos = new ByteArrayOutputStream();
String fileName = ebxmlMessage.getFileName();
byte[] soapEnvelopeBytes = ebxmlMessage.getSoapEnvelopeBytes();
if (soapEnvelopeBytes != null) {
baos.write(soapEnvelopeBytes);
} else if (fileName != null) {
! FileInputStream fis = new FileInputStream(fileName);
int skipped = ebxmlMessage.getSOAPMessageFileOffset()[0];
byte[] buffer = new byte[skipped];
--- 294,323 ----
ByteArrayOutputStream baos = new ByteArrayOutputStream();
String fileName = ebxmlMessage.getFileName();
+ String persistenceName = ebxmlMessage.getPersistenceName();
byte[] soapEnvelopeBytes = ebxmlMessage.getSoapEnvelopeBytes();
if (soapEnvelopeBytes != null) {
baos.write(soapEnvelopeBytes);
+ } else if (persistenceName != null) {
+ DataSource dataSource
+ = ebxmlMessage.getPersistenceHandler().getObject(
+ persistenceName);
+ if (dataSource == null) {
+ throw new SignatureException(
+ "Inconsistence Persistence on ebxmlMessage");
+ }
+ InputStream istream = dataSource.getInputStream();
+ int[] soapMessageOffset
+ = ebxmlMessage.getSOAPMessageFileOffset();
+ try {
+ //istream = new FileInputStream(fileName);
+ loadInputStreamToOutputStream(istream, baos,
+ soapMessageOffset[0], soapMessageOffset[1]);
+ } catch (IOException e) {
+ throw e;
+ } finally {
+ istream.close();
+ }
} else if (fileName != null) {
! /*
int skipped = ebxmlMessage.getSOAPMessageFileOffset()[0];
byte[] buffer = new byte[skipped];
***************
*** 279,284 ****
}
fis.close();
! }
! else {
final SOAPPart soapPart = ebxmlMessage.getSOAPMessage().
getSOAPPart();
--- 339,358 ----
}
fis.close();
! */
! InputStream istream = null;
! int[] soapMessageOffset
! = ebxmlMessage.getSOAPMessageFileOffset();
! try {
! istream = new FileInputStream(fileName);
! loadInputStreamToOutputStream(istream, baos,
! soapMessageOffset[0], soapMessageOffset[1]);
! } catch (IOException e) {
! throw e;
! } finally {
! if (istream != null) {
! istream.close();
! }
! }
! } else {
final SOAPPart soapPart = ebxmlMessage.getSOAPMessage().
getSOAPPart();
|