Esempio n. 1
1
    /**
     * Called for an incoming message.
     *
     * @param inMessage
     */
    public void onMessage(Message inMessage) {
      // disposable exchange, swapped with real Exchange on correlation
      inMessage.setExchange(new ExchangeImpl());
      inMessage.getExchange().put(Bus.class, bus);
      inMessage.put(Message.DECOUPLED_CHANNEL_MESSAGE, Boolean.TRUE);
      inMessage.put(Message.RESPONSE_CODE, HttpURLConnection.HTTP_OK);

      // remove server-specific properties
      // inMessage.remove(AbstractHTTPDestination.HTTP_REQUEST);
      // inMessage.remove(AbstractHTTPDestination.HTTP_RESPONSE);
      inMessage.remove(Message.ASYNC_POST_RESPONSE_DISPATCH);
      updateResponseCode(inMessage);

      // cache this inputstream since it's defer to use in case of async
      try {
        InputStream in = inMessage.getContent(InputStream.class);
        if (in != null) {
          CachedOutputStream cos = new CachedOutputStream();
          IOUtils.copy(in, cos);
          inMessage.setContent(InputStream.class, cos.getInputStream());
        }
        observer.onMessage(inMessage);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  @Override
  public void handleMessage(Message message) {
    if (!shouldSchemaValidate(message)) {
      return;
    }
    if (checkContextProperty(message)) {
      return;
    }

    // 1. Try to get and transform XMLStreamWriter message content
    XMLStreamWriter xWriter = message.getContent(XMLStreamWriter.class);
    if (xWriter != null) {
      transformXWriter(message, xWriter);
    } else {
      // 2. Try to get and transform OutputStream message content
      OutputStream out = message.getContent(OutputStream.class);
      if (out != null) {
        transformOS(message, out);
      } else {
        // 3. Try to get and transform Writer message content (actually used for JMS TextMessage)
        Writer writer = message.getContent(Writer.class);
        if (writer != null) {
          transformWriter(message, writer);
        }
      }
    }
  }
  public void handleMessage(Message message) throws Fault {
    // check the fault from the message
    Throwable ex = message.getContent(Throwable.class);
    if (ex != null) {
      if (ex instanceof Fault) {
        throw (Fault) ex;
      } else {
        throw new Fault(ex);
      }
    }

    List<?> params = message.getContent(List.class);
    if (null != params) {
      InputStream is = (InputStream) params.get(0);
      OutputStream os = message.getContent(OutputStream.class);
      try {
        if (is instanceof StreamCache) {
          ((StreamCache) is).writeTo(os);
        } else {
          IOUtils.copy(is, os);
        }
      } catch (Exception e) {
        throw new Fault(e);
      } finally {
        IOHelper.close(is, "input stream", null);
        // Should not close the output stream as the interceptor chain will close it
      }
    }
  }
Esempio n. 4
0
 private void checkCachedStream(Message m, OutputStream osOriginal, boolean enabled)
     throws Exception {
   XMLStreamWriter writer = null;
   if (enabled) {
     writer = m.getContent(XMLStreamWriter.class);
   } else {
     writer = (XMLStreamWriter) m.get(XMLStreamWriter.class.getName());
   }
   if (writer instanceof CachingXmlEventWriter) {
     CachingXmlEventWriter cache = (CachingXmlEventWriter) writer;
     if (cache.getEvents().size() != 0) {
       XMLStreamWriter origWriter = null;
       try {
         origWriter = StaxUtils.createXMLStreamWriter(osOriginal);
         for (XMLEvent event : cache.getEvents()) {
           StaxUtils.writeEvent(event, origWriter);
         }
       } finally {
         StaxUtils.close(origWriter);
       }
     }
     m.setContent(XMLStreamWriter.class, null);
     return;
   }
   if (enabled) {
     OutputStream os = m.getContent(OutputStream.class);
     if (os != osOriginal && os instanceof CachedOutputStream) {
       CachedOutputStream cos = (CachedOutputStream) os;
       if (cos.size() != 0) {
         cos.writeCacheTo(osOriginal);
       }
     }
   }
 }
Esempio n. 5
0
 public void handleMessage(Message message) throws Fault {
   final OutputStream os = message.getContent(OutputStream.class);
   final Writer iowriter = message.getContent(Writer.class);
   if (os == null && iowriter == null) {
     return;
   }
   Logger logger = getMessageLogger(message);
   if (logger.isLoggable(Level.INFO) || writer != null) {
     // Write the output while caching it for the log message
     boolean hasLogged = message.containsKey(LOG_SETUP);
     if (!hasLogged) {
       message.put(LOG_SETUP, Boolean.TRUE);
       if (os != null) {
         final CacheAndWriteOutputStream newOut = new CacheAndWriteOutputStream(os);
         if (threshold > 0) {
           newOut.setThreshold(threshold);
         }
         if (limit > 0) {
           newOut.setCacheLimit(limit);
         }
         message.setContent(OutputStream.class, newOut);
         newOut.registerCallback(new LoggingCallback(logger, message, os));
       } else {
         message.setContent(Writer.class, new LogWriter(logger, message, iowriter));
       }
     }
   }
 }
Esempio n. 6
0
  public void handleMessage(Message msg) {
    Fault fault = (Fault) msg.getContent(Exception.class);

    if (fault.getDetail() != null
        && !MessageUtils.getContextualBoolean(msg, DISABLE_FAULT_MAPPING, false)) {
      processFaultDetail(fault, msg);
      setStackTrace(fault, msg);
    }

    FaultMode faultMode = FaultMode.UNCHECKED_APPLICATION_FAULT;

    // Check if the raised exception is declared in the WSDL or by the JAX-RS resource
    Method m = msg.getExchange().get(Method.class);
    if (m != null) {
      Exception e = msg.getContent(Exception.class);
      for (Class<?> cl : m.getExceptionTypes()) {
        if (cl.isInstance(e)) {
          faultMode = FaultMode.CHECKED_APPLICATION_FAULT;
          break;
        }
      }
    }

    msg.getExchange().put(FaultMode.class, faultMode);
  }
Esempio n. 7
0
 public void handleMessage(Message message) throws Fault {
   createExchangeId(message);
   final OutputStream os = message.getContent(OutputStream.class);
   if (os != null) {
     LoggingCallback callback = new LoggingCallback(sender, message, os, limit);
     message.setContent(OutputStream.class, createCachingOut(message, os, callback));
   } else {
     final Writer iowriter = message.getContent(Writer.class);
     if (iowriter != null) {
       message.setContent(
           Writer.class, new LogEventSendingWriter(sender, message, iowriter, limit));
     }
   }
 }
  /* (non-Javadoc)
   * @see org.apache.cxf.interceptor.Interceptor#handleMessage(org.apache.cxf.message.Message)
   */
  public void handleMessage(Message message) {
    try {
      if (message != null) {

        List<Object> params = message.getContent(List.class); // parameter instances
        if (params.get(0) instanceof HasXsl) {

          OperationResourceInfo ori = message.getExchange().get(OperationResourceInfo.class);
          JAXBElementProvider provider =
              (JAXBElementProvider)
                  ProviderFactory.getInstance(message)
                      .createMessageBodyWriter(
                          ori.getMethodToInvoke().getReturnType(),
                          ori.getMethodToInvoke().getGenericReturnType(),
                          ori.getMethodToInvoke().getAnnotations(),
                          MediaType.APPLICATION_XML_TYPE,
                          message);
          Map<String, Object> properties = new HashMap<String, Object>();

          HasXsl hasXsl = (HasXsl) params.get(0);
          // System.out.println("Stylesheet params " + hasXsl.getClass() + " " + hasXsl.getXsl());
          if (hasXsl == null || hasXsl.getXsl().equalsIgnoreCase(Constants.NO_XSL)) {
            properties.put(XML_HEADERS, "<!-- no stylesheet -->");
          } else {
            properties.put(
                XML_HEADERS,
                "<?xml-stylesheet type='application/xml' href='" + hasXsl.getXsl() + "'?>");
          }
          provider.setMarshallerProperties(properties);
        }
      }
    } catch (Throwable x) {
      throw new WebApplicationException(Response.status(Status.BAD_REQUEST).build());
    }
  }
Esempio n. 9
0
 private void setStackTrace(Fault fault, Message msg) {
   Throwable cause = null;
   Map<String, String> ns = new HashMap<String, String>();
   XPathUtils xu = new XPathUtils(ns);
   ns.put("s", Fault.STACKTRACE_NAMESPACE);
   String ss =
       (String)
           xu.getValue(
               "//s:" + Fault.STACKTRACE + "/text()", fault.getDetail(), XPathConstants.STRING);
   List<StackTraceElement> stackTraceList = new ArrayList<StackTraceElement>();
   if (!StringUtils.isEmpty(ss)) {
     Iterator<String> linesIterator = Arrays.asList(CAUSE_SUFFIX_SPLITTER.split(ss)).iterator();
     while (linesIterator.hasNext()) {
       String oneLine = linesIterator.next();
       if (oneLine.startsWith("Caused by:")) {
         cause = getCause(linesIterator, oneLine);
         break;
       }
       stackTraceList.add(parseStackTrackLine(oneLine));
     }
     if (stackTraceList.size() > 0 || cause != null) {
       Exception e = msg.getContent(Exception.class);
       if (!stackTraceList.isEmpty()) {
         StackTraceElement[] stackTraceElement = new StackTraceElement[stackTraceList.size()];
         e.setStackTrace(stackTraceList.toArray(stackTraceElement));
       }
       if (cause != null) {
         e.initCause(cause);
       }
     }
   }
 }
Esempio n. 10
0
  protected void invokeInboundChain(Exchange ex, Endpoint ep) {
    Message m = getInBoundMessage(ex);
    Message inMsg = ep.getBinding().createMessage();
    MessageImpl.copyContent(m, inMsg);

    // Copy Response Context to Client inBound Message
    // TODO a Context Filter Strategy required.
    inMsg.putAll(m);

    inMsg.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
    inMsg.put(Message.INBOUND_MESSAGE, Boolean.TRUE);
    inMsg.setExchange(ex);

    Exception exc = inMsg.getContent(Exception.class);
    if (exc != null) {
      ex.setInFaultMessage(inMsg);
      ColocInFaultObserver observer = new ColocInFaultObserver(bus);
      observer.onMessage(inMsg);
    } else {
      // Handle Response
      ex.setInMessage(inMsg);
      PhaseManager pm = bus.getExtension(PhaseManager.class);
      SortedSet<Phase> phases = new TreeSet<Phase>(pm.getInPhases());
      ColocUtil.setPhases(phases, Phase.USER_LOGICAL, Phase.PRE_INVOKE);

      InterceptorChain chain = ColocUtil.getInInterceptorChain(ex, phases);
      inMsg.setInterceptorChain(chain);
      chain.doIntercept(inMsg);
    }
    ex.put(ClientImpl.FINISHED, Boolean.TRUE);
  }
  private void doFromSoapMessage(Message message, Object sm) {
    SOAPMessage m = (SOAPMessage) sm;
    MessageContentsList list = (MessageContentsList) message.getContent(List.class);
    if (list == null) {
      list = new MessageContentsList();
      message.setContent(List.class, list);
    }
    Object o = m;

    if (StreamSource.class.isAssignableFrom(type)) {
      try {
        try (CachedOutputStream out = new CachedOutputStream()) {
          XMLStreamWriter xsw = StaxUtils.createXMLStreamWriter(out);
          StaxUtils.copy(new DOMSource(m.getSOAPPart()), xsw);
          xsw.close();
          o = new StreamSource(out.getInputStream());
        }
      } catch (Exception e) {
        throw new Fault(e);
      }
    } else if (SAXSource.class.isAssignableFrom(type)) {
      o = new StaxSource(new W3CDOMStreamReader(m.getSOAPPart()));
    } else if (Source.class.isAssignableFrom(type)) {
      o = new DOMSource(m.getSOAPPart());
    }
    list.set(0, o);
  }
Esempio n. 12
0
  protected void handle(Message message) throws SequenceFault, RMException {
    LOG.entering(getClass().getName(), "handleMessage");
    // This message capturing mechanism will need to be changed at some point.
    // Until then, we keep this interceptor here and utilize the robust
    // option to avoid the unnecessary message capturing/caching.
    if (!MessageUtils.isTrue(message.getContextualProperty(Message.ROBUST_ONEWAY))) {
      InputStream is = message.getContent(InputStream.class);
      if (is != null) {
        CachedOutputStream saved = new CachedOutputStream();
        try {
          IOUtils.copy(is, saved);

          saved.flush();
          is.close();
          saved.lockOutputStream();

          LOG.fine("Capturing the original RM message");
          RewindableInputStream ris = RewindableInputStream.makeRewindable(saved.getInputStream());
          message.setContent(InputStream.class, ris);
          message.put(RMMessageConstants.SAVED_CONTENT, ris);
        } catch (Exception e) {
          throw new Fault(e);
        }
      }
    }
  }
 public void handleMessage(Message message) throws Fault {
   XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
   try {
     setSchemaInMessage(message, writer);
   } catch (XMLStreamException e) {
     throw new Fault(new org.apache.cxf.common.i18n.Message("SCHEMA_ERROR", LOG), e);
   }
 }
Esempio n. 14
0
 @Override
 public void handleMessage(Message message) throws Fault {
   try {
     XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
     StaxUtils.copy(reader, writer);
   } catch (XMLStreamException e) {
     throw new Fault("COULD_NOT_READ_XML_STREAM", LOG, e);
   }
 }
Esempio n. 15
0
  /** @return the current payload */
  public Object getPayload() {
    List<Object> objs = CastUtils.cast(payload.getContent(List.class));

    if (objs == null) {
      // Seems Providers get objects stored this way
      Object o = payload.getContent(Object.class);
      if (o != null) {
        return o;
      } else {
        return new Object[0];
      }
    }
    if (objs.size() == 1 && objs.get(0) != null) {
      return objs.get(0);
    } else {
      return objs.toArray();
    }
  }
  public void handleMessage(Message message) throws Fault {
    createExchangeId(message);
    final LogEvent event = new DefaultLogEventMapper().map(message);
    try {
      CachedOutputStream cos = message.getContent(CachedOutputStream.class);
      if (cos != null) {
        handleOutputStream(event, message, cos);
      } else {
        CachedWriter writer = message.getContent(CachedWriter.class);
        if (writer != null) {
          handleWriter(event, writer);
        }
      }
    } catch (IOException e) {
      throw new Fault(e);
    }

    sender.send(event);
  }
Esempio n. 17
0
    public void handleMessage(Message outMessage) throws Fault {

      MessageContentsList objs = MessageContentsList.getContentsList(outMessage);
      if (objs == null || objs.size() == 0) {
        return;
      }

      OutputStream os = outMessage.getContent(OutputStream.class);
      if (os == null) {
        XMLStreamWriter writer = outMessage.getContent(XMLStreamWriter.class);
        if (writer == null) {
          return;
        }
      }

      Object body = objs.get(0);
      Annotation[] customAnns = (Annotation[]) outMessage.get(Annotation.class.getName());
      Type t = outMessage.get(Type.class);
      doWriteBody(outMessage, body, t, customAnns, os);
    }
 private void doDataSource(final Message message) {
   MessageContentsList list = (MessageContentsList) message.getContent(List.class);
   // reconstitute all the parts into a Mime data source
   if (message.getAttachments() != null
       && !message.getAttachments().isEmpty()
       && list != null
       && !list.isEmpty()
       && list.get(0) instanceof DataSource) {
     list.set(0, new MultiPartDataSource(message, (DataSource) list.get(0)));
   }
 }
 public void handleMessage(Message message) throws Fault {
   BindingOperationInfo bop = message.getExchange().getBindingOperationInfo();
   if (bop == null || !bindingName.equals(bop.getBinding().getName())) {
     return;
   }
   Object o = message.getContent(soapMsgClass);
   if (o != null) {
     doFromSoapMessage(message, o);
   } else if (DataSource.class.isAssignableFrom(type)) {
     doDataSource(message);
   }
 }
Esempio n. 20
0
  protected Object[] preProcessResult(Message message) throws Exception {

    Exchange exchange = message.getExchange();

    Exception ex = message.getContent(Exception.class);
    if (ex != null) {
      getConfiguration().getConduitSelector().complete(exchange);
      checkClientException(message, ex);
    }
    checkClientException(message, message.getExchange().get(Exception.class));

    List<?> result = message.getExchange().get(List.class);
    return result != null ? result.toArray() : null;
  }
Esempio n. 21
0
 private String getFaultNameFromMessage(final Message message) {
   Exception e = message.getContent(Exception.class);
   Throwable cause = e.getCause();
   if (cause == null) {
     cause = e;
   }
   if (e instanceof Fault) {
     WebFault t = cause.getClass().getAnnotation(WebFault.class);
     if (t != null) {
       return t.name();
     }
   }
   return cause.getClass().getSimpleName();
 }
Esempio n. 22
0
  /**
   * Verfies one of the tenents of our interface -- the Conduit sets up an OutputStream on the
   * message after a "prepare".
   */
  @Test
  public void testConduitOutputStream() throws Exception {
    Bus bus = new ExtensionManagerBus();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress("http://nowhere.com/bar/foo");
    HTTPConduit conduit = new URLConnectionHTTPConduit(bus, ei, null);
    conduit.finalizeConfig();

    Message message = getNewMessage();

    // Test call
    conduit.prepare(message);

    assertNotNull(
        "Conduit should always set output stream.", message.getContent(OutputStream.class));
  }
Esempio n. 23
0
  public void handleMessage(Message message) throws Fault {
    Document doc = (Document) message.get(WSDLGetInterceptor.DOCUMENT_HOLDER);
    if (doc == null) {
      return;
    }
    message.remove(WSDLGetInterceptor.DOCUMENT_HOLDER);

    XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
    if (writer == null) {
      return;
    }
    message.put(Message.CONTENT_TYPE, "text/xml");
    try {
      StaxUtils.writeNode(doc, writer, true);
    } catch (XMLStreamException e) {
      throw new Fault(e);
    }
  }
Esempio n. 24
0
  @Override
  public void close(Message msg) throws IOException {
    CachedOutputStream output = (CachedOutputStream) msg.getContent(OutputStream.class);
    if (targetNode != null && output != null) {
      StringBuilder soapEnvelope = new StringBuilder();
      output.writeCacheTo(soapEnvelope);

      SimplePayload payload =
          new SimplePayload(
              "Envelope", "http://www.w3.org/2003/05/soap-envelope", soapEnvelope.toString());

      PayloadItem<SimplePayload> pi = new PayloadItem<SimplePayload>(payload);
      try {
        targetNode.send(pi);
      } catch (XMPPException e) {
        throw new IOException(e);
      }
    }
  }
Esempio n. 25
0
    @Override
    public void close(Message message) throws IOException {
      if (Boolean.TRUE.equals(message.getExchange().get(LocalConduit.DIRECT_DISPATCH))) {
        final Exchange exchange = (Exchange) message.getExchange().get(LocalConduit.IN_EXCHANGE);

        MessageImpl copy = new MessageImpl();
        copy.putAll(message);
        MessageImpl.copyContent(message, copy);
        CachedOutputStream stream = (CachedOutputStream) message.getContent(OutputStream.class);
        copy.setContent(InputStream.class, stream.getInputStream());
        if (exchange != null && exchange.getInMessage() == null) {
          exchange.setInMessage(copy);
        }
        conduit.getMessageObserver().onMessage(copy);
        return;
      }

      super.close(message);
    }
  /**
   * Xml json.
   *
   * @see http://jettison.codehaus.org/User's+Guide
   * @see http://cxf.apache.org/docs/service-routing.html
   * @see http://permalink.gmane.org/gmane.comp.apache.cxf.user/14983
   * @see
   *     http://illegalargumentexception.blogspot.com/2009/05/java-rough-guide-to-character-encoding.html#javaencoding_streams
   * @param message the message
   * @throws XMLStreamException the xML stream exception
   * @throws IOException Signals that an I/O exception has occurred.
   */
  private void xml2json(Message message) {

    try {
      OutputStream os = message.getContent(OutputStream.class);
      System.out.println("xml2json os " + os.toString());
      StringWriter writer = new StringWriter();

      // Mapped convention
      MappedNamespaceConvention con = new MappedNamespaceConvention();
      AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, writer);

      w.flush();
      System.out.println("w " + w.toString());
      w.close();
      writer.close();
      System.out.println("writer " + writer.toString());
    } catch (Throwable x) {
      x.printStackTrace();
    }
  }
Esempio n. 27
0
    protected void doWriteBody(
        Message outMessage, Object body, Type bodyType, Annotation[] customAnns, OutputStream os)
        throws Fault {

      OperationResourceInfo ori = outMessage.getContent(OperationResourceInfo.class);
      if (ori == null) {
        return;
      }

      Method method = ori.getMethodToInvoke();
      int bodyIndex = (Integer) outMessage.get("BODY_INDEX");

      Annotation[] anns =
          customAnns != null
              ? customAnns
              : getMethodAnnotations(ori.getAnnotatedMethod(), bodyIndex);
      try {
        if (bodyIndex != -1) {
          Class<?> paramClass = method.getParameterTypes()[bodyIndex];
          Class<?> bodyClass =
              paramClass.isAssignableFrom(body.getClass()) ? paramClass : body.getClass();
          Type genericType = method.getGenericParameterTypes()[bodyIndex];
          if (bodyType != null) {
            genericType = bodyType;
          }
          genericType =
              InjectionUtils.processGenericTypeIfNeeded(
                  ori.getClassResourceInfo().getServiceClass(), bodyClass, genericType);
          bodyClass = InjectionUtils.updateParamClassToTypeIfNeeded(bodyClass, genericType);
          writeBody(body, outMessage, bodyClass, genericType, anns, os);
        } else {
          Type paramType = body.getClass();
          if (bodyType != null) {
            paramType = bodyType;
          }
          writeBody(body, outMessage, body.getClass(), paramType, anns, os);
        }
      } catch (Exception ex) {
        throw new Fault(ex);
      }
    }
  @SuppressWarnings({"ThrowableResultOfMethodCallIgnored"})
  public void handleMessage(Message message) throws Fault {
    handleMessageCalled = true;
    Exception ex = message.getContent(Exception.class);
    if (ex == null) {
      throw new RuntimeException("Exception is expected");
    }
    Fault fault = (Fault) ex;
    final Throwable t = fault.getCause();

    final int status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    String requestId = UUID.randomUUID().toString();
    final ErrorMessage error = new ErrorMessage(ERROR_TEXT, requestId);

    logger.error("Caught unhandled exception! This may be a bug. " + "RequestID: " + requestId, t);

    HttpServletResponse response =
        (HttpServletResponse)
            message.getExchange().getInMessage().get(AbstractHTTPDestination.HTTP_RESPONSE);

    this.responseUtil.sendServletError(response, error, status);

    message.getInterceptorChain().abort();
  }
Esempio n. 29
0
  protected static Object getContentFromCxf(Message message, DataFormat dataFormat) {
    Set<Class<?>> contentFormats = message.getContentFormats();
    Object answer = null;
    if (contentFormats != null) {

      if (LOG.isTraceEnabled()) {
        for (Class<?> contentFormat : contentFormats) {
          LOG.trace("Content format={} value={}", contentFormat, message.getContent(contentFormat));
        }
      }

      if (dataFormat == DataFormat.POJO) {
        answer = message.getContent(List.class);
        if (answer == null) {
          answer = message.getContent(Object.class);
          if (answer != null) {
            answer = new MessageContentsList(answer);
          }
        }
      } else if (dataFormat == DataFormat.PAYLOAD) {
        List<SoapHeader> headers = CastUtils.cast((List<?>) message.get(Header.HEADER_LIST));
        Map<String, String> nsMap = new HashMap<String, String>();
        answer = new CxfPayload<SoapHeader>(headers, getPayloadBodyElements(message, nsMap), nsMap);

      } else if (dataFormat.dealias() == DataFormat.RAW) {
        answer = message.getContent(InputStream.class);

      } else if (dataFormat.dealias() == DataFormat.CXF_MESSAGE
          && message.getContent(List.class) != null) {
        // CAMEL-6404 added check point of message content
        // The message content of list could be null if there is a fault message is received
        answer = message.getContent(List.class).get(0);
      }

      LOG.trace("Extracted body from CXF message = {}", answer);
    }
    return answer;
  }
Esempio n. 30
0
  /**
   * Mediate message flow.
   *
   * @param message the current message
   * @param isFault true if a fault is being mediated
   * @return true if processing should continue on dispatch path
   */
  protected boolean mediate(Message message, boolean isFault) {
    boolean continueProcessing = true;
    if (ContextUtils.isOutbound(message)) {
      if (usingAddressing(message)) {
        // request/response MAPs must be aggregated
        aggregate(message, isFault);
      }
      AddressingProperties theMaps =
          ContextUtils.retrieveMAPs(message, false, ContextUtils.isOutbound(message));
      if (null != theMaps) {
        if (ContextUtils.isRequestor(message)) {
          assertAddressing(message, theMaps.getReplyTo(), theMaps.getFaultTo());
        } else {
          checkReplyTo(message, theMaps);
        }
      }
    } else if (!ContextUtils.isRequestor(message)) {
      // responder validates incoming MAPs
      AddressingProperties maps = getMAPs(message, false, false);
      // check responses
      if (maps != null) {
        checkAddressingResponses(maps.getReplyTo(), maps.getFaultTo());
        assertAddressing(message, maps.getReplyTo(), maps.getFaultTo());
      }
      boolean isOneway = message.getExchange().isOneWay();
      if (null == maps && !addressingRequired) {
        return false;
      }
      continueProcessing = validateIncomingMAPs(maps, message);
      if (maps != null) {
        AddressingProperties theMaps =
            ContextUtils.retrieveMAPs(message, false, ContextUtils.isOutbound(message));
        if (null != theMaps) {
          assertAddressing(message, theMaps.getReplyTo(), theMaps.getFaultTo());
        }

        if (isOneway || !ContextUtils.isGenericAddress(maps.getReplyTo())) {
          InternalContextUtils.rebaseResponse(maps.getReplyTo(), maps, message);
        }
        if (!isOneway) {
          if (ContextUtils.isNoneAddress(maps.getReplyTo())) {
            LOG.warning("Detected NONE value in ReplyTo WSA header for request-respone MEP");
          } else {
            // ensure the inbound MAPs are available in both the full & fault
            // response messages (used to determine relatesTo etc.)
            ContextUtils.propogateReceivedMAPs(maps, message.getExchange());
          }
        }
      }
      if (continueProcessing) {
        // any faults thrown from here on can be correlated with this message
        message.put(FaultMode.class, FaultMode.LOGICAL_RUNTIME_FAULT);
      } else {
        // validation failure => dispatch is aborted, response MAPs
        // must be aggregated
        // isFault = true;
        // aggregate(message, isFault);
        if (isSOAP12(message)) {
          SoapFault soap12Fault =
              new SoapFault(
                  ContextUtils.retrieveMAPFaultReason(message), Soap12.getInstance().getSender());
          soap12Fault.setSubCode(
              new QName(Names.WSA_NAMESPACE_NAME, ContextUtils.retrieveMAPFaultName(message)));
          throw soap12Fault;
        }
        throw new SoapFault(
            ContextUtils.retrieveMAPFaultReason(message),
            new QName(Names.WSA_NAMESPACE_NAME, ContextUtils.retrieveMAPFaultName(message)));
      }
    } else {
      AddressingProperties theMaps =
          ContextUtils.retrieveMAPs(message, false, ContextUtils.isOutbound(message));
      if (null != theMaps) {
        assertAddressing(message, theMaps.getReplyTo(), theMaps.getFaultTo());
      }
      // If the wsa policy is enabled , but the client sets the
      // WSAddressingFeature.isAddressingRequired to false , we need to assert all WSA assertion to
      // true
      if (!ContextUtils.isOutbound(message)
          && ContextUtils.isRequestor(message)
          && getWSAddressingFeature(message) != null
          && !getWSAddressingFeature(message).isAddressingRequired()) {
        assertAddressing(message);
      }
      // CXF-3060 :If wsa policy is not enforced, AddressingProperties map is null and
      // AddressingFeature.isRequired, requestor checks inbound message and throw exception
      if (null == theMaps
          && !ContextUtils.isOutbound(message)
          && ContextUtils.isRequestor(message)
          && getWSAddressingFeature(message) != null
          && getWSAddressingFeature(message).isAddressingRequired()) {
        boolean missingWsaHeader = false;
        AssertionInfoMap aim = message.get(AssertionInfoMap.class);
        if (aim == null || aim.size() == 0) {
          missingWsaHeader = true;
        }
        if (aim != null && aim.size() > 0) {
          missingWsaHeader = true;
          QName[] types =
              new QName[] {
                MetadataConstants.ADDRESSING_ASSERTION_QNAME,
                MetadataConstants.USING_ADDRESSING_2004_QNAME,
                MetadataConstants.USING_ADDRESSING_2005_QNAME,
                MetadataConstants.USING_ADDRESSING_2006_QNAME
              };
          for (QName type : types) {
            for (AssertionInfo assertInfo : aim.getAssertionInfo(type)) {
              if (assertInfo.isAsserted()) {
                missingWsaHeader = false;
              }
            }
          }
        }
        if (missingWsaHeader) {
          throw new SoapFault(
              "MISSING_ACTION_MESSAGE",
              BUNDLE,
              new QName(Names.WSA_NAMESPACE_NAME, Names.HEADER_REQUIRED_NAME));
        }
      }
      if (MessageUtils.isPartialResponse(message)
          && message.getExchange().getOutMessage() != null) {
        // marked as a partial response, let's see if it really is
        MessageInfo min = message.get(MessageInfo.class);
        MessageInfo mout = message.getExchange().getOutMessage().get(MessageInfo.class);
        if (min != null
            && mout != null
            && min.getOperation() == mout.getOperation()
            && message.getContent(List.class) != null) {
          // the in and out messages are on the same operation
          // and we were able to get a response for it.
          message.remove(Message.PARTIAL_RESPONSE_MESSAGE);
        }
      }
    }
    return continueProcessing;
  }