001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.binding.soap;
019:
020: import java.io.IOException;
021: import java.net.URISyntaxException;
022: import java.net.URL;
023: import java.util.ArrayList;
024: import java.util.Collection;
025:
026: import javax.activation.DataHandler;
027: import javax.mail.util.ByteArrayDataSource;
028:
029: import org.apache.cxf.attachment.AttachmentImpl;
030: import org.apache.cxf.attachment.AttachmentUtil;
031: import org.apache.cxf.interceptor.InterceptorChain;
032: import org.apache.cxf.message.Attachment;
033: import org.apache.cxf.message.Exchange;
034: import org.apache.cxf.message.ExchangeImpl;
035: import org.apache.cxf.message.MessageImpl;
036: import org.apache.cxf.mime.types.XopType;
037:
038: public final class TestUtil {
039:
040: private TestUtil() {
041: }
042:
043: public static XopType createXopObject(Class<?> clazz)
044: throws IOException, URISyntaxException {
045:
046: XopType xopObj = new XopType();
047: xopObj.setName("hello world");
048:
049: URL url1 = clazz.getResource("my.wav");
050:
051: xopObj.setAttachinfo(new DataHandler(url1));
052:
053: return xopObj;
054: }
055:
056: public static SoapMessage createSoapMessage(
057: SoapVersion soapVersion, InterceptorChain chain,
058: Class<?> clazz) throws IOException {
059:
060: SoapMessage soapMessage = createEmptySoapMessage(soapVersion,
061: chain);
062: // setup the message result with attachment.class
063: ByteArrayDataSource bads = new ByteArrayDataSource(clazz
064: .getResourceAsStream("primarySoapPart.xml"),
065: "Application/xop+xml");
066: String cid = AttachmentUtil
067: .createContentID("http://cxf.apache.org");
068: soapMessage.setContent(Attachment.class, new AttachmentImpl(
069: cid, new DataHandler(bads)));
070:
071: // setup the message attachments
072: Collection<Attachment> attachments = new ArrayList<Attachment>();
073: soapMessage.setAttachments(attachments);
074: // String cidAtt1 = "cid:http://cxf.apache.org/me.bmp";
075: // bads = new ByteArrayDataSource(clazz.getResourceAsStream("me.bmp"), "image/bmp");
076: // AttachmentImpl att1 = new AttachmentImpl(cidAtt1, new DataHandler(bads));
077: // att1.setXOP(true);
078: // attachments.add(att1);
079: String cidAtt2 = "cid:http://cxf.apache.org/my.wav";
080: bads = new ByteArrayDataSource(clazz
081: .getResourceAsStream("my.wav"),
082: "Application/octet-stream");
083: AttachmentImpl att2 = new AttachmentImpl(cidAtt2,
084: new DataHandler(bads));
085: att2.setXOP(true);
086: attachments.add(att2);
087:
088: return soapMessage;
089: }
090:
091: public static SoapMessage createEmptySoapMessage(
092: SoapVersion soapVersion, InterceptorChain chain) {
093: Exchange exchange = new ExchangeImpl();
094: MessageImpl messageImpl = new MessageImpl();
095: messageImpl.setInterceptorChain(chain);
096: messageImpl.setExchange(exchange);
097: SoapMessage soapMessage = new SoapMessage(messageImpl);
098: soapMessage.setVersion(soapVersion);
099: return soapMessage;
100: }
101: }
|