本文整理汇总了Java中org.apache.cxf.message.Attachment类的典型用法代码示例。如果您正苦于以下问题:Java Attachment类的具体用法?Java Attachment怎么用?Java Attachment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Attachment类属于org.apache.cxf.message包,在下文中一共展示了Attachment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDataWriter
import org.apache.cxf.message.Attachment; //导入依赖的package包/类
protected <T> DataWriter<T> getDataWriter(Message message, Service service, Class<T> output) {
DataWriter<T> writer = service.getDataBinding().createWriter(output);
Collection<Attachment> atts = message.getAttachments();
if (MessageUtils.isTrue(message.getContextualProperty(Message.MTOM_ENABLED))
&& atts == null) {
atts = new ArrayList<Attachment>();
message.setAttachments(atts);
}
writer.setAttachments(atts);
writer.setProperty(DataWriter.ENDPOINT, message.getExchange().getEndpoint());
writer.setProperty(Message.class.getName(), message);
setDataWriterValidation(service, message, writer);
return writer;
}
示例2: readInclude
import org.apache.cxf.message.Attachment; //导入依赖的package包/类
private Object readInclude(String type, MessageReader reader,
Context context) throws DatabindingException {
String href = reader.getAttributeReader(XOP_HREF).getValue().trim();
Attachment att = org.jrubycxf.aegis.type.mtom.AttachmentUtil.getAttachment(href, context.getAttachments());
if (att == null) {
throw new DatabindingException("Could not find the attachment " + href);
}
try {
return readAttachment(att, context);
} catch (IOException e) {
throw new DatabindingException("Could not read attachment", e);
}
}
示例3: getAttachment
import org.apache.cxf.message.Attachment; //导入依赖的package包/类
private Attachment getAttachment(String id) {
// this method is based off org.apache.cxf.aegis.type.mtom.AttachmentUtil implementation
if (id == null) {
log.debug("Null attachment ID.");
return null;
}
try {
id = URLDecoder.decode(id, "UTF-8");
} catch (UnsupportedEncodingException e) {
log.info("Unable to decode attachment ID " + id, e);
return null;
}
Collection<Attachment> attachments = AttachmentCachingInterceptor.getAttachments();
for(Attachment a : attachments) {
if (id.contains(a.getId())) {
if (log.isInfoEnabled()) {
log.info("Id: " + id + " matches " + a.getId());
}
return a;
}
}
if (log.isInfoEnabled()) {
log.info("Unable to find attachment matching id: " + id);
}
return null;
}
示例4: testPopulateCxfRequestFromExchange
import org.apache.cxf.message.Attachment; //导入依赖的package包/类
@Test
public void testPopulateCxfRequestFromExchange() {
DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
Exchange exchange = new DefaultExchange(context);
org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl();
exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
Map<String, Object> requestContext = new HashMap<String, Object>();
exchange.getIn().setHeader("soapAction", "urn:hello:world");
exchange.getIn().setHeader("MyFruitHeader", "peach");
exchange.getIn().setHeader("MyBrewHeader", Arrays.asList("cappuccino", "espresso"));
exchange.getIn().addAttachment("att-1", new DataHandler(new FileDataSource("pom.xml")));
cxfBinding.populateCxfRequestFromExchange(cxfExchange, exchange, requestContext);
// check the protocol headers
Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>)requestContext.get(Message.PROTOCOL_HEADERS));
assertNotNull(headers);
assertEquals(3, headers.size());
verifyHeader(headers, "soapaction", "urn:hello:world");
verifyHeader(headers, "SoapAction", "urn:hello:world");
verifyHeader(headers, "SOAPAction", "urn:hello:world");
verifyHeader(headers, "myfruitheader", "peach");
verifyHeader(headers, "myFruitHeader", "peach");
verifyHeader(headers, "MYFRUITHEADER", "peach");
verifyHeader(headers, "MyBrewHeader", Arrays.asList("cappuccino", "espresso"));
Set<Attachment> attachments
= CastUtils.cast((Set<?>)requestContext.get(CxfConstants.CAMEL_CXF_ATTACHMENTS));
assertNotNull(attachments);
assertNotNull(attachments.size() == 1);
Attachment att = attachments.iterator().next();
assertEquals("att-1", att.getId());
}
示例5: testPopupalteExchangeFromCxfResponse
import org.apache.cxf.message.Attachment; //导入依赖的package包/类
@Test
public void testPopupalteExchangeFromCxfResponse() {
DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
Exchange exchange = new DefaultExchange(context);
org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl();
exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
Map<String, Object> responseContext = new HashMap<String, Object>();
responseContext.put(org.apache.cxf.message.Message.RESPONSE_CODE, Integer.valueOf(200));
Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
headers.put("content-type", Arrays.asList("text/xml;charset=UTF-8"));
headers.put("Content-Length", Arrays.asList("241"));
responseContext.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers);
org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
cxfExchange.setInMessage(cxfMessage);
Set<Attachment> attachments = new HashSet<Attachment>();
attachments.add(new AttachmentImpl("att-1", new DataHandler(new FileDataSource("pom.xml"))));
cxfMessage.setAttachments(attachments);
cxfBinding.populateExchangeFromCxfResponse(exchange, cxfExchange, responseContext);
Map<String, Object> camelHeaders = exchange.getOut().getHeaders();
assertNotNull(camelHeaders);
assertEquals(responseContext, camelHeaders.get(Client.RESPONSE_CONTEXT));
Map<String, DataHandler> camelAttachments = exchange.getOut().getAttachments();
assertNotNull(camelAttachments);
assertNotNull(camelAttachments.get("att-1"));
}
示例6: testPopupalteExchangeFromCxfRequest
import org.apache.cxf.message.Attachment; //导入依赖的package包/类
@Test
public void testPopupalteExchangeFromCxfRequest() {
DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
Exchange exchange = new DefaultExchange(context);
org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl();
exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
headers.put("content-type", Arrays.asList("text/xml;charset=UTF-8"));
headers.put("Content-Length", Arrays.asList("241"));
headers.put("soapAction", Arrays.asList("urn:hello:world"));
headers.put("myfruitheader", Arrays.asList("peach"));
headers.put("mybrewheader", Arrays.asList("cappuccino", "espresso"));
cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers);
Set<Attachment> attachments = new HashSet<Attachment>();
attachments.add(new AttachmentImpl("att-1", new DataHandler(new FileDataSource("pom.xml"))));
cxfMessage.setAttachments(attachments);
cxfExchange.setInMessage(cxfMessage);
cxfBinding.populateExchangeFromCxfRequest(cxfExchange, exchange);
Map<String, Object> camelHeaders = exchange.getIn().getHeaders();
assertNotNull(camelHeaders);
assertEquals("urn:hello:world", camelHeaders.get("soapaction"));
assertEquals("urn:hello:world", camelHeaders.get("SoapAction"));
assertEquals("text/xml;charset=UTF-8", camelHeaders.get("content-type"));
assertEquals("241", camelHeaders.get("content-length"));
assertEquals("peach", camelHeaders.get("MyFruitHeader"));
assertEquals(Arrays.asList("cappuccino", "espresso"), camelHeaders.get("MyBrewHeader"));
Map<String, DataHandler> camelAttachments = exchange.getIn().getAttachments();
assertNotNull(camelAttachments);
assertNotNull(camelAttachments.get("att-1"));
}
示例7: message
import org.apache.cxf.message.Attachment; //导入依赖的package包/类
@Override
public void message(MessageHeader messageHeader, SyncReply syncReply, MessageOrder messageOrder, AckRequested ackRequested, Manifest manifest)
{
Collection<Attachment> attachments = AttachmentManager.get();
List<DataSource> dataSources = new ArrayList<DataSource>();
for (Attachment attachment : attachments)
dataSources.add(new EbMSDataSource(attachment.getDataHandler().getDataSource(),attachment.getId(),attachment.getDataHandler().getName()));
messageProcessor.process(new EbMSMessage(MessageManager.get(),SignatureManager.get() == null ? null : SignatureManager.get().getSignature(),messageHeader,syncReply,messageOrder,ackRequested,manifest,dataSources),SignatureManager.get());
}
示例8: handleMessage
import org.apache.cxf.message.Attachment; //导入依赖的package包/类
@Override
public void handleMessage(SoapMessage message) throws Fault
{
Collection<Attachment> attachments = message.getAttachments();
if (attachments != null)
AttachmentManager.set(attachments);
}
示例9: handleMessage
import org.apache.cxf.message.Attachment; //导入依赖的package包/类
@Override
public void handleMessage(final SoapMessage message) throws Fault
{
try
{
KeyStore keyStore = SecurityUtils.loadKeyStore(keyStorePath,keyStorePassword);
KeyPair keyPair = SecurityUtils.getKeyPair(keyStore,keyAlias,keyPassword);
CachedOutputStream os = (CachedOutputStream)message.getContent(OutputStream.class);
StringBuilder sb = new StringBuilder();
os.writeCacheTo(sb);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
Document document = dbf.newDocumentBuilder().parse(new ByteArrayInputStream(sb.toString().getBytes()));
List<EbMSDataSource> dataSources = new ArrayList<EbMSDataSource>();
if (message.getAttachments() != null)
for (Attachment attachment : message.getAttachments())
{
DataSource ds = attachment.getDataHandler().getDataSource();
dataSources.add(new EbMSDataSource(ds,attachment.getId(),attachment.getDataHandler().getName()));
}
sign(keyStore,keyPair,keyAlias,document,dataSources);
OutputStream originalOs = (OutputStream)message.get(OUTPUT_STREAM_HOLDER);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(new DOMSource(document),new StreamResult(originalOs));
message.setContent(OutputStream.class,originalOs);
}
catch (Exception e)
{
throw new Fault(e);
}
}
示例10: handleMessage
import org.apache.cxf.message.Attachment; //导入依赖的package包/类
@Override
public void handleMessage(final SoapMessage message) throws Fault
{
try
{
KeyStore keyStore = SecurityUtils.loadKeyStore(keyStorePath,keyStorePassword);
KeyPair keyPair = SecurityUtils.getKeyPair(keyStore,keyAlias,keyPassword);
CachedOutputStream os = (CachedOutputStream)message.getContent(OutputStream.class);
StringBuilder sb = new StringBuilder();
os.writeCacheTo(sb);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
Document document = dbf.newDocumentBuilder().parse(new ByteArrayInputStream(sb.toString().getBytes()));
if (isSigned(document))
{
List<EbMSDataSource> dataSources = new ArrayList<EbMSDataSource>();
if (message.getAttachments() != null)
for (Attachment attachment : message.getAttachments())
{
DataSource ds = attachment.getDataHandler().getDataSource();
dataSources.add(new EbMSDataSource(ds,attachment.getId(),attachment.getDataHandler().getName()));
}
sign(keyStore,keyPair,keyAlias,document,dataSources);
}
OutputStream originalOs = (OutputStream)message.get(OUTPUT_STREAM_HOLDER);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(new DOMSource(document),new StreamResult(originalOs));
message.setContent(OutputStream.class,originalOs);
}
catch (Exception e)
{
throw new Fault(e);
}
}
示例11: handleMessage
import org.apache.cxf.message.Attachment; //导入依赖的package包/类
@Override
public void handleMessage(SoapMessage message) throws Fault
{
try
{
KeyStore keyStore = SecurityUtils.loadKeyStore(keyStorePath,keyStorePassword);
KeyPair keyPair = SecurityUtils.getKeyPair(keyStore,keyAlias,keyPassword);
CachedOutputStream os = (CachedOutputStream)message.getContent(OutputStream.class);
StringBuilder sb = new StringBuilder();
os.writeCacheTo(sb);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
Document document = dbf.newDocumentBuilder().parse(new ByteArrayInputStream(sb.toString().getBytes()));
List<EbMSDataSource> dataSources = new ArrayList<EbMSDataSource>();
if (message.getAttachments() != null)
for (Attachment attachment : message.getAttachments())
{
DataSource ds = attachment.getDataHandler().getDataSource();
dataSources.add(new EbMSDataSource(ds,attachment.getId(),attachment.getDataHandler().getName()));
}
sign(keyStore,keyPair,keyAlias,document,dataSources);
OutputStream originalOs = (OutputStream)message.get(OUTPUT_STREAM_HOLDER);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(new DOMSource(document),new StreamResult(originalOs));
message.setContent(OutputStream.class,originalOs);
}
catch (Exception e)
{
throw new Fault(e);
}
}
示例12: transform
import org.apache.cxf.message.Attachment; //导入依赖的package包/类
@Override
public Object transform(MuleMessage message, String outputEncoding) throws TransformerException
{
EbMSMessage msg = (EbMSMessage)message.getPayload();
message.setPayload(new Object[]{msg.getMessageHeader(),null,null,msg.getAckRequested(),msg.getManifest()});
Collection<Attachment> attachments = new ArrayList<Attachment>();
for (int i = 0; i < msg.getAttachments().size(); i++)
attachments.add(new nl.clockwork.common.cxf.Attachment("" + (i + 1),msg.getAttachments().get(i)));
AttachmentManager.set(attachments);
return message;
}
示例13: handleMessage
import org.apache.cxf.message.Attachment; //导入依赖的package包/类
@Override
public void handleMessage(SoapMessage message) throws Fault
{
Collection<Attachment> attachments = AttachmentManager.get();
if (attachments != null)
message.setAttachments(attachments);
}
示例14: getAttachment
import org.apache.cxf.message.Attachment; //导入依赖的package包/类
public static Attachment getAttachment(String id, Collection<Attachment> attachments) {
if (id == null) {
throw new DatabindingException("Cannot get attachment: null id");
}
int i = id.indexOf("cid:");
if (i != -1) {
id = id.substring(4).trim();
}
if (attachments == null) {
return null;
}
for (Iterator<Attachment> iter = attachments.iterator(); iter.hasNext();) {
Attachment a = iter.next();
if (a.getId().equals(id)) {
return a;
}
}
// Try loading the URL remotely
try {
URLDataSource source = new URLDataSource(new URL(id));
return new AttachmentImpl(id, new DataHandler(source));
} catch (MalformedURLException e) {
return null;
}
}
示例15: createAttachment
import org.apache.cxf.message.Attachment; //导入依赖的package包/类
@Override
protected Attachment createAttachment(Object object, String id) {
DataSource source = (DataSource)object;
DataHandler handler = new DataHandler(source);
AttachmentImpl att = new AttachmentImpl(id, handler);
att.setXOP(true);
return att;
}