예제 #1
1
 public static OMElement serializeHandlerConfiguration(HandlerConfigurationBean bean) {
   OMFactory factory = OMAbstractFactory.getOMFactory();
   OMElement handler = factory.createOMElement("handler", null);
   handler.addAttribute(factory.createOMAttribute("class", null, bean.getHandlerClass()));
   if (bean.getTenant() != null) {
     handler.addAttribute(factory.createOMAttribute("tenant", null, bean.getTenant()));
   }
   StringBuilder sb = new StringBuilder();
   for (String method : bean.getMethods()) {
     if (method != null && method.length() > 0) {
       sb.append(method).append(",");
     }
   }
   // Remove last ","
   if (sb.length() > 0) {
     sb.deleteCharAt(sb.length() - 1);
     handler.addAttribute(factory.createOMAttribute("methods", null, sb.toString()));
   }
   for (String property : bean.getPropertyList()) {
     OMElement temp = factory.createOMElement("property", null);
     temp.addAttribute(factory.createOMAttribute("name", null, property));
     OMElement xmlProperty = bean.getXmlProperties().get(property);
     if (xmlProperty != null) {
       //                The serialization happens by adding the whole XML property value to the
       // bean.
       //                Therefore if it is a XML property, we take that whole element.
       handler.addChild(xmlProperty);
     } else {
       String nonXMLProperty = bean.getNonXmlProperties().get(property);
       if (nonXMLProperty != null) {
         temp.setText(nonXMLProperty);
         handler.addChild(temp);
       }
     }
   }
   OMElement filter = factory.createOMElement("filter", null);
   filter.addAttribute(
       factory.createOMAttribute("class", null, bean.getFilter().getFilterClass()));
   for (String property : bean.getFilter().getPropertyList()) {
     OMElement temp = factory.createOMElement("property", null);
     temp.addAttribute(factory.createOMAttribute("name", null, property));
     OMElement xmlProperty = bean.getFilter().getXmlProperties().get(property);
     if (xmlProperty != null) {
       temp.addAttribute(factory.createOMAttribute("type", null, "xml"));
       temp.addChild(xmlProperty);
       filter.addChild(temp);
     } else {
       String nonXMLProperty = bean.getFilter().getNonXmlProperties().get(property);
       if (nonXMLProperty != null) {
         temp.setText(nonXMLProperty);
         filter.addChild(temp);
       }
     }
   }
   handler.addChild(filter);
   return handler;
 }
  public void sendUsingMTOM(String fileName, String targetEPR) throws IOException {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
    OMElement payload = factory.createOMElement("uploadFileUsingMTOM", ns);
    OMElement request = factory.createOMElement("request", ns);
    OMElement image = factory.createOMElement("image", ns);

    FileDataSource fileDataSource = new FileDataSource(new File(fileName));
    DataHandler dataHandler = new DataHandler(fileDataSource);
    OMText textData = factory.createOMText(dataHandler, true);
    image.addChild(textData);
    request.addChild(image);
    payload.addChild(request);

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(targetEPR));
    options.setAction("urn:uploadFileUsingMTOM");
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
    options.setCallTransportCleanup(true);
    serviceClient.setOptions(options);
    OMElement response = serviceClient.sendReceive(payload);
    Assert.assertTrue(
        response
            .toString()
            .contains(
                "<m:testMTOM xmlns:m=\"http://services.samples/xsd\">"
                    + "<m:test1>testMTOM</m:test1></m:testMTOM>"));
  }