@Override
 public void mapTo(Context context, SOAPBindingData target) throws Exception {
   SOAPMessage soapMessage = target.getSOAPMessage();
   MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
   SOAPHeader soapHeader = soapMessage.getSOAPHeader();
   for (Property property : context.getProperties(Scope.IN)) {
     Object value = property.getValue();
     if (value != null) {
       String name = property.getName();
       QName qname = XMLHelper.createQName(name);
       boolean qualifiedForSoapHeader = Strings.trimToNull(qname.getNamespaceURI()) != null;
       if (qualifiedForSoapHeader && matches(qname)) {
         if (value instanceof Node) {
           Node domNode = soapHeader.getOwnerDocument().importNode((Node) value, true);
           soapHeader.appendChild(domNode);
         } else if (value instanceof Configuration) {
           Element configElement = new ElementPuller().pull(new StringReader(value.toString()));
           Node configNode = soapHeader.getOwnerDocument().importNode(configElement, true);
           soapHeader.appendChild(configNode);
         } else {
           String v = value.toString();
           if (SOAPHeadersType.XML.equals(getSOAPHeadersType())) {
             try {
               Element xmlElement = new ElementPuller().pull(new StringReader(v));
               Node xmlNode = soapHeader.getOwnerDocument().importNode(xmlElement, true);
               soapHeader.appendChild(xmlNode);
             } catch (Throwable t) {
               soapHeader.addChildElement(qname).setValue(v);
             }
           } else {
             soapHeader.addChildElement(qname).setValue(v);
           }
         }
       } else {
         if (matches(name)) {
           mimeHeaders.addHeader(name, String.valueOf(value));
         }
       }
     }
   }
 }
 public static void main(String... args) throws Exception {
   Set<String> policies = new HashSet<String>();
   for (String arg : args) {
     arg = Strings.trimToNull(arg);
     if (arg != null) {
       if (arg.equals(CONFIDENTIALITY) || arg.equals(CLIENT_AUTHENTICATION) || arg.equals(HELP)) {
         policies.add(arg);
       } else {
         LOGGER.error(MAVEN_USAGE);
         throw new Exception(MAVEN_USAGE);
       }
     }
   }
   if (policies.contains(HELP)) {
     LOGGER.info(MAVEN_USAGE);
   } else {
     final String scheme;
     final int port;
     if (policies.contains(CONFIDENTIALITY)) {
       scheme = "https";
       port = getPort(8443);
       SSLContext sslcontext = SSLContext.getInstance("TLS");
       sslcontext.init(null, null, null);
       SSLSocketFactory sf =
           new SSLSocketFactory(sslcontext, SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
       Scheme https = new Scheme(scheme, port, sf);
       SchemeRegistry sr = new SchemeRegistry();
       sr.register(https);
     } else {
       scheme = "http";
       port = getPort(8080);
     }
     String binarySecurityToken =
         policies.contains(CLIENT_AUTHENTICATION)
             ? new StringPuller().pull("/xml/BinarySecurityToken.xml")
             : null;
     invokeWorkService(scheme, port, getContext(), binarySecurityToken);
   }
 }
 /**
  * Appends a namespace on the end of the specified uri.
  *
  * @param uri the specified uri
  * @param namespace the specified namespace
  * @return the appended uri
  */
 public static final String addNamespaceParameter(String uri, String namespace) {
   if (uri != null && uri.startsWith("switchyard://")) {
     namespace = Strings.trimToNull(namespace);
     if (namespace != null) {
       if (!uri.contains("?namespace=") && !uri.contains("&namespace=")) {
         try {
           namespace = URLEncoder.encode(namespace, "UTF-8");
         } catch (UnsupportedEncodingException uee) {
           throw new SwitchYardException(uee);
         }
         StringBuilder sb = new StringBuilder(uri);
         if (uri.indexOf('?') < 0) {
           sb.append('?');
         } else {
           sb.append('&');
         }
         sb.append("namespace=");
         sb.append(namespace);
         uri = sb.toString();
       }
     }
   }
   return uri;
 }
 /** {@inheritDoc} */
 @Override
 public void handleAction(Exchange exchange, KnowledgeAction action) throws HandlerException {
   RulesActionType actionType = (RulesActionType) action.getType();
   switch (actionType) {
     case EXECUTE:
       {
         KnowledgeSession session = newStatelessSession();
         setGlobals(exchange, action, session, true);
         List<Object> input = getInputList(exchange, action);
         session.getStateless().execute(input);
         break;
       }
     case INSERT:
     case FIRE_ALL_RULES:
       {
         /*
         if (!isContinue(exchange)) {
             disposeStatefulSession();
         }
         */
         KnowledgeSession session = getStatefulSession();
         setGlobals(exchange, action, session, true);
         List<Object> input = getInputList(exchange, action);
         for (Object fact : input) {
           session.getStateful().insert(fact);
         }
         if (RulesActionType.FIRE_ALL_RULES.equals(actionType)) {
           session.getStateful().fireAllRules();
         }
         if (isDispose(exchange)) {
           disposeStatefulSession();
         }
         break;
       }
     case FIRE_UNTIL_HALT:
       {
         /*
         if (!isContinue(exchange)) {
             disposeStatefulSession();
         }
         */
         KnowledgeSession session = getStatefulSession();
         setGlobals(exchange, action, session, false);
         if (_fireUntilHaltThread == null) {
           FireUntilHalt fireUntilHalt = new FireUntilHalt(this, session, getLoader());
           session.addDisposals(fireUntilHalt);
           _fireUntilHaltThread = fireUntilHalt.startThread();
         }
         final String undefinedVariable = toVariable(exchange);
         Map<String, List<Object>> listMap =
             getListMap(exchange, action.getInputExpressionMappings(), true, undefinedVariable);
         if (listMap.size() > 0) {
           for (Entry<String, List<Object>> entry : listMap.entrySet()) {
             String key = entry.getKey();
             if (undefinedVariable.equals(key)) {
               String id = Strings.trimToNull(action.getId());
               if (id != null) {
                 key = id;
               }
             }
             List<Object> input = entry.getValue();
             if (undefinedVariable.equals(key)) {
               for (Object fact : input) {
                 session.getStateful().insert(fact);
               }
             } else {
               SessionEntryPoint sep = session.getStateful().getEntryPoint(key);
               if (sep != null) {
                 for (Object fact : input) {
                   sep.insert(fact);
                 }
               } else {
                 throw new HandlerException(
                     "Unknown entry point: " + sep + "; please check your rules source.");
               }
             }
           }
         } else {
           Object content = exchange.getMessage().getContent();
           if (content != null) {
             session.getStateful().insert(content);
           }
         }
         if (isDispose(exchange)) {
           disposeStatefulSession();
         }
         break;
       }
     default:
       {
         throw new HandlerException("Unsupported action type: " + actionType);
       }
   }
   Object output = getOutput(exchange, action);
   if (ExchangePattern.IN_OUT.equals(
       exchange.getContract().getProviderOperation().getExchangePattern())) {
     Message message = exchange.createMessage().setContent(output);
     exchange.send(message);
   }
 }