2009-03-11 12 views
1

私は、(javax.xml.messaging.JAXMServlet)というクラス(2005年に書かれています)を持つアプリケーションを維持しています。最新のJ2EE標準を実装している新しいアプリケーションサーバーにアップグレードしているときに、this questionによると、JAXMServletがJWSDP 2.0(Java Web Services Developer Pack)で削除されていることがわかりました(そして明らかにJWSDP自体はdeprecatedでした)。依存しているコードは、書かれてから大きく変更されておらず、このコードが既にテストされてデバッグされている大規模な既存のプロダクションシステムの一部です。したがって、回帰テストの影響により、クラスを一から書き直すのは嫌です。JAXMServletの置き換えですか?

このクラスは「簡単に」置き換えられますか? Googleにはこのコードの使用例がたくさんありますが(2003〜2004年頃)、それを置き換えることについては驚くほど黙っています。ありがとう。

答えて

0

自分の質問に答えるために、http://www.java.happycodings.com/Java%5fUtil%5fPackage/code23.htmlでいくつかの置換コードが見つかりました:

import java.io.ByteArrayInputStream; 
import java.net.MalformedURLException; 
import java.net.URL; 
import java.util.Enumeration; 
import java.util.Iterator; 
import java.util.StringTokenizer; 
import javax.activation.DataHandler; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
import javax.xml.soap.AttachmentPart; 
import javax.xml.soap.MimeHeader; 
import javax.xml.soap.MimeHeaders; 
import javax.xml.soap.SOAPException; 
import javax.xml.soap.SOAPMessage; 

public class SaajUtils { 
    /** 
    * extract the MIME header information from within the HTTP Request 
    * @param req the http request 
    * @return MimeHeaders as defined within the SAAJ API 
    */ 
    public static MimeHeaders getHeaders(HttpServletRequest req) { 
     Enumeration<String> en = req.getHeaderNames(); 
     MimeHeaders headers = new MimeHeaders(); 

     while(en.hasMoreElements()) { 
     String headerName = (String) en.nextElement(); 
     String headerValue = req.getHeader(headerName); 

     StringTokenizer values = new StringTokenizer(headerValue, ","); 
     while(values.hasMoreTokens()) { 
      headers.addHeader(headerName, values.nextToken().trim()); 
     } 
     } 
     return headers; 
    } 

    /** 
    * stuff the MIME headers into the HTTP response 
    * @param headers the SAAJ MIME headers 
    * @param res the Http servlet response 
    */ 
    public static void putHeaders(MimeHeaders headers, HttpServletResponse res) { 
     for(Iterator<MimeHeader> it = headers.getAllHeaders(); it.hasNext();) { 
      MimeHeader header = it.next(); 
      String[] values = headers.getHeader(header.getName()); 
      if(values.length == 1) { 
      res.setHeader(header.getName(), header.getValue()); 
      } 
      else { 
      StringBuffer concat = new StringBuffer(); 
      for(int i = 0; i < values.length; i++) { 
       if(i != 0) { 
       concat.append(','); 
       } 
       concat.append(values[i]); 
      } 
      res.setHeader(header.getName(), concat.toString()); 
     } 
     } 
    } 

    public static void attachBytes(SOAPMessage soapMessage, byte[] theBytes, String contentType) 
    throws SOAPException { 
     AttachmentPart attachment = soapMessage.createAttachmentPart(); 
     attachment.setContent(new ByteArrayInputStream(theBytes), contentType); 
     soapMessage.addAttachmentPart(attachment); 
    } 

    public static void attachUrlContents(SOAPMessage soapMessage, String urlLocation, String contentType) 
    throws SOAPException, MalformedURLException { 
     URL url = new URL(urlLocation); 
     AttachmentPart attachment = soapMessage.createAttachmentPart(new DataHandler(url)); 
     attachment.setContentType(contentType); 
     soapMessage.addAttachmentPart(attachment); 
    } 

    public static String getAttachmentReport(SOAPMessage soapMessage) throws SOAPException { 
     int numOfAttachments = soapMessage.countAttachments(); 
     Iterator<AttachmentPart> attachments = soapMessage.getAttachments(); 

     StringBuffer buf = new StringBuffer("Number of attachments: "); 
     buf.append(numOfAttachments); 

     while(attachments.hasNext()) { 
     buf.append("\n--------------------------------------------\n"); 
     AttachmentPart attachment = attachments.next(); 
     buf.append("\nContent Location: " + attachment.getContentLocation()); 
     buf.append("\nContent Id: " + attachment.getContentId()); 
     buf.append("\nContent Size: " + attachment.getSize()); 
     buf.append("\nContent Type: " + attachment.getContentType()); 
     } 

     return buf.toString(); 
    } 
}