2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.helios.internal.ws.soap;
15 import javax.xml.namespace.QName;
16 import javax.xml.soap.SOAPEnvelope;
17 import javax.xml.soap.SOAPHeader;
18 import javax.xml.soap.SOAPHeaderElement;
19 import javax.xml.soap.SOAPMessage;
20 import javax.xml.ws.handler.MessageContext;
21 import javax.xml.ws.handler.soap.SOAPMessageContext;
23 import org.openhab.binding.helios.internal.handler.HeliosHandler27;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * The {@link SOAPSubscriptionActionHandler} is a custom SOAP handler that modifies
29 * some SOAP headers in order to get the Helios comm. working
31 * @author Karel Goderis - Initial contribution
33 public class SOAPSubscriptionActionHandler extends SOAPActionHandler {
35 private Logger logger = LoggerFactory.getLogger(SOAPSubscriptionActionHandler.class);
37 private HeliosHandler27 handler;
39 public SOAPSubscriptionActionHandler(HeliosHandler27 heliosHandler) {
40 this.handler = heliosHandler;
44 public boolean handleMessage(SOAPMessageContext context) {
45 Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
49 SOAPMessage soapMsg = context.getMessage();
50 SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
51 SOAPHeader soapHeader = soapEnv.getHeader();
53 if (soapHeader == null) {
54 soapHeader = soapEnv.addHeader();
57 QName qname = new QName("http://www.2n.cz/2013/event", "SubscriptionId");
58 SOAPHeaderElement soapHeaderElement = soapHeader.addHeaderElement(qname);
60 soapHeaderElement.addAttribute(
61 new QName("http://www.w3.org/2005/08/addressing", "IsReferenceParameter"), "true");
62 if (handler.getSubscriptionID() != null) {
63 soapHeaderElement.addTextNode(handler.getSubscriptionID());
65 soapMsg.saveChanges();
66 } catch (Exception e) {
67 logger.debug("An exception occurred while formatting a SOAP header : '{}'", e.getMessage());