@Override
    protected Soap createMessage(byte[] rawXml, SOAPMessage soap, String charset) throws Exception {
      if (soap.getSOAPHeader() != null) {
        SoapHeader header = unmarshalHeader(SoapHeader.class, soap.getSOAPHeader());
        if (header.getCentralService() != null) {
          if (header.getService() != null) {
            throw new CodedException(
                X_MALFORMED_SOAP,
                "Message header must contain either service id" + " or central service id");
          }

          ServiceId serviceId = GlobalConf.getServiceId(header.getCentralService());
          header.setService(serviceId);

          SOAPEnvelope envelope = soap.getSOAPPart().getEnvelope();
          envelope.removeChild(soap.getSOAPHeader());

          Node soapBody = envelope.removeChild(soap.getSOAPBody());
          envelope.removeContents(); // removes newlines etc.

          Marshaller marshaller =
              JaxbUtils.createMarshaller(SoapHeader.class, new SoapNamespacePrefixMapper());
          marshaller.marshal(header, envelope);

          envelope.appendChild(soapBody);

          byte[] newRawXml = SoapUtils.getBytes(soap);
          return super.createMessage(newRawXml, soap, charset);
        }
      }
      return super.createMessage(rawXml, soap, charset);
    }
  private void checkConsistency() throws Exception {
    log.trace("checkConsistency()");
    try {
      SoapUtils.checkConsistency(requestSoap, response.getSoap());
    } catch (CodedException e) {
      log.error("Inconsistent request-response", e);
      // The error code includes ServiceFailed because it indicates
      // faulty response from service (problem on the other side).
      throw new CodedException(
              X_INCONSISTENT_RESPONSE, "Response from server proxy is not consistent with request")
          .withPrefix(X_SERVICE_FAILED_X);
    }

    checkRequestHash();
  }