@SuppressWarnings("unchecked")
  @Test
  public void testInvokingServiceFromCxfProducer() throws Exception {
    if (MtomTestHelper.isAwtHeadless(logger, null)) {
      return;
    }

    final Holder<byte[]> photo = new Holder<byte[]>(MtomTestHelper.REQ_PHOTO_DATA);
    final Holder<Image> image = new Holder<Image>(getImage("/java.jpg"));

    Exchange exchange =
        context
            .createProducerTemplate()
            .send(
                "direct://testEndpoint",
                new Processor() {

                  @Override
                  public void process(Exchange exchange) throws Exception {
                    exchange.getIn().setBody(new Object[] {photo, image});
                  }
                });

    assertEquals("The attachement size should be 2 ", 2, exchange.getOut().getAttachments().size());

    Object[] result = exchange.getOut().getBody(Object[].class);
    Holder<byte[]> photo1 = (Holder<byte[]>) result[1];
    MtomTestHelper.assertEquals(MtomTestHelper.RESP_PHOTO_DATA, photo1.value);
    Holder<Image> image1 = (Holder<Image>) result[2];
    Assert.assertNotNull(image1.value);
    if (image.value instanceof BufferedImage) {
      Assert.assertEquals(560, ((BufferedImage) image1.value).getWidth());
      Assert.assertEquals(300, ((BufferedImage) image1.value).getHeight());
    }
  }
  @Test
  public void testConsumer() throws Exception {
    if (MtomTestHelper.isAwtHeadless(logger, null)) {
      return;
    }

    context
        .createProducerTemplate()
        .send(
            "cxf:bean:consumerEndpoint",
            new Processor() {

              public void process(Exchange exchange) throws Exception {
                exchange.setPattern(ExchangePattern.InOut);
                assertEquals(
                    "Get a wrong Content-Type header",
                    "application/xop+xml",
                    exchange.getIn().getHeader("Content-Type"));
                List<Source> elements = new ArrayList<Source>();
                elements.add(
                    new DOMSource(
                        DOMUtils.readXml(new StringReader(getRequestMessage()))
                            .getDocumentElement()));
                CxfPayload<SoapHeader> body =
                    new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(), elements, null);
                exchange.getIn().setBody(body);
                exchange
                    .getIn()
                    .addAttachment(
                        MtomTestHelper.REQ_PHOTO_CID,
                        new DataHandler(
                            new ByteArrayDataSource(
                                MtomTestHelper.REQ_PHOTO_DATA, "application/octet-stream")));

                exchange
                    .getIn()
                    .addAttachment(
                        MtomTestHelper.REQ_IMAGE_CID,
                        new DataHandler(
                            new ByteArrayDataSource(MtomTestHelper.requestJpeg, "image/jpeg")));
              }
            });
  }