0
MTOM을 사용하여 파일을받는 웹 서비스 (jBoss 7.4에서 실행 중)가 있습니다.MTOM - 테스트 파일 내용
클라이언트 (테스트 용 다른 응용 프로그램 인 SoapUI)가 파일을 보내면 수신합니다.
첨부 파일이있는 요청을 수행 한 후 첨부 파일이 실제로 수신되었는지 (이진 데이터 비교) 검사를 수행하는 가장 좋은 방법은 무엇입니까?
어떻게해야합니까?
MTOM을 사용하여 파일을받는 웹 서비스 (jBoss 7.4에서 실행 중)가 있습니다.MTOM - 테스트 파일 내용
클라이언트 (테스트 용 다른 응용 프로그램 인 SoapUI)가 파일을 보내면 수신합니다.
첨부 파일이있는 요청을 수행 한 후 첨부 파일이 실제로 수신되었는지 (이진 데이터 비교) 검사를 수행하는 가장 좋은 방법은 무엇입니까?
어떻게해야합니까?
필자는 며칠 전 비슷한 테스트 케이스를 작성했다. 예, 실제 내용을 비교합니다. 다음은 소스 코드입니다. 이것은 당신에게 도움이 될 수 있습니다.
/**
* Compares the contents of SOAP attachment and contents of actual file used for creating the attachment
* Useful for XML/HTML/Plain text attachments
* @throws SOAPException
* @throws IOException
* @throws IllegalArgumentException
* @throws ClassNotFoundException
*/
@Test
public void testSetAndGetContentForTextualAttachment() throws SOAPException, IOException,
IllegalArgumentException, ClassNotFoundException {
SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
SOAPMTOMMessageImpl soapImpl = new SOAPMTOMMessageImpl(soapMessage);
SOAPPart part = soapMessage.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
SOAPBody body = envelope.getBody();
SOAPBodyElement element = body.addBodyElement(envelope.createName(
"test", "test", "http://namespace.com/"));
// Create an Attachment from a file
File attachmentFile = new File ("C:\\temp\\temp.txt");
// get the expected contents from a file
StringBuffer expectedContent = new StringBuffer();
String line = null;
BufferedReader br = new BufferedReader(new FileReader(attachmentFile));
while((line = br.readLine()) != null){
expectedContent = expectedContent.append(line);
}
// create attachment
// Uses my application's custom classes, but you can use normal SAAJ classes for doing the same.
Attachment fileAttachment = soapImpl.createAttachmentFromFile(attachmentFile, "text/plain");
// content id will be used for downloading the attachment
fileAttachment.setContentID(attachmentFile.getName()+".restore");
// create MTOM type soap object from this attachment
QName fileSoapAttachmentQname = new QName("http://namespace.com/", "AttachFileAsSOAPAttachmentMTOM", "AttachmentElement");
soapImpl.setXopQname(fileSoapAttachmentQname);
soapImpl.addAttachmentAsMTOM(fileAttachment, element);
// Extract the attachment and cross check the contents
StringBuffer actualContent = new StringBuffer();
List<Attachment> attachments = soapImpl.getAllAttachments();
for(int i=0; i<attachments.size(); i++){
AttachmentPart attachmentPart = ((AttachmentImpl) attachments.get(i)).getAttachmentPart();
BufferedInputStream bis = new BufferedInputStream (attachmentPart.getDataHandler().getInputStream());
byte[] data = new byte[1024];
int numOfBytesRead = 0;
while(bis.available() > 0){
numOfBytesRead = bis.read(data);
String tmp = new String(data,0,numOfBytesRead);
actualContent = actualContent.append(tmp);
}
bis.close();
}
try {
Assert.assertEquals(true,
(expectedContent.toString()).equals(actualContent.toString()));
} catch (Throwable e) {
collector.addError(e);
}
}
는 서버 측에서 유사한 검증을하려면, 당신은 비교를 위해 내용 길이 헤더 값을 사용할 수 있습니다. 또는 추가 특성을 추가하여 예상되는 첨부 파일 크기 또는 종류의 체크섬을 결정할 수 있습니다.
_Thanks, 부샨