Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.openehealth.ipf.platform.camel.ihe.hl7v3.iti55;
 
 import java.util.List;
 import java.util.Map;
 
 
Helper functions for handling TTL SOAP header in XCPD.

Author(s):
Dmytro Rud
 
 public class TtlHeaderUtils {
 
     private static final QName TTL_HEADER_QNAME = new QName("urn:ihe:iti:xcpd:2009""CorrelationTimeToLive"); 
     
     private TtlHeaderUtils() {
         throw new IllegalStateException("cannot instantiate utility class");
     }
    
    
    
Returns the XCPD TTL value stored in incoming SOAP headers associated with the given message, or null, when none found.
 
     public static Duration getTtl(Message message) {
         Map<QNameHeadersoapHeaders = CastUtils.cast(message.getHeader(
                 .,
                 Map.class));
         if ((soapHeaders != null) && soapHeaders.containsKey()) {
             Object o = soapHeaders.get().getObject();
             if (o instanceof Element) {
                 Node child = ((Elemento).getFirstChild();
                 if (child instanceof Text) {
                     String value = child.getNodeValue();
                     try {
                         return DatatypeFactory.newInstance().newDuration(value);
                     } catch (Exception e) {
                         throw new RuntimeException("Cannot parse TTL header " + valuee); 
                     }
                 }
             }
         }
         return null;
     }
    
    
    
Stores the user-defined XCPD TTL value into outgoing SOAP headers associated with the given message.
 
     public static void setTtl(Duration duraMessage message) {
         List<HeadersoapHeaders = CastUtils.cast(message.getHeader(
                 .List.class));
         if (soapHeaders == null) {
             soapHeaders = new ArrayList<>();
             message.setHeader(.soapHeaders);
         }
         
         Header ttlHeader = new Header(dura.toString(), getStringDataBinding());
         soapHeaders.add(ttlHeader);
     }
     
     
     private static JAXBDataBinding getStringDataBinding() {
         try {
             return new JAXBDataBinding(String.class);
         } catch (JAXBException e) {
             // actually cannot occur
             throw new RuntimeException(e);
         }
     }
New to GrepCode? Check out our FAQ X