@Test
  public void testXPathRouterNoChannelResolver() {

    // Build the route
    DirectChannel inputChannel = new DirectChannel();
    inputChannel.setBeanName("input");
    XPathRouter router = new XPathRouter("//subject/text()");
    router.setEvaluateAsString(true);
    inputChannel.subscribe(router);

    // Create message
    Object correlationId = "123-ABC";
    String xmlSource = "<xml><subject>test</subject></xml>";
    Message<String> message =
        MessageBuilder.withPayload(xmlSource).setCorrelationId(correlationId).build();

    // Send and receive message synchronously
    MessagingTemplate template = new MessagingTemplate(inputChannel);
    try {
      Message<?> reply = template.sendAndReceive(message);
      assertFalse("should fail", true);
    } catch (MessageHandlingException ex) {
      assertTrue(ex.getMessage().contains("error occurred in message handler"));
      assertTrue(
          ex.getCause()
              .getMessage()
              .contains("unable to resolve channel names, no ChannelResolver available"));
    }
  }
 /**
  * Writes the message payload to the underlying socket, using the specified message format.
  *
  * @see
  *     org.springframework.messaging.MessageHandler#handleMessage(org.springframework.messaging.Message)
  */
 @Override
 public void handleMessageInternal(final Message<?> message) throws MessageHandlingException {
   if (this.serverConnectionFactory != null) {
     // We don't own the connection, we are asynchronously replying
     Object connectionId = message.getHeaders().get(IpHeaders.CONNECTION_ID);
     TcpConnection connection = null;
     if (connectionId != null) {
       connection = connections.get(connectionId);
     }
     if (connection != null) {
       try {
         connection.send(message);
       } catch (Exception e) {
         logger.error("Error sending message", e);
         connection.close();
         if (e instanceof MessageHandlingException) {
           throw (MessageHandlingException) e;
         } else {
           throw new MessageHandlingException(message, "Error sending message", e);
         }
       } finally {
         if (this.isSingleUse) { // close after replying
           connection.close();
         }
       }
     } else {
       logger.error("Unable to find outbound socket for " + message);
       MessageHandlingException messageHandlingException =
           new MessageHandlingException(message, "Unable to find outbound socket");
       publishNoConnectionEvent(messageHandlingException, (String) connectionId);
       throw messageHandlingException;
     }
     return;
   } else {
     // we own the connection
     TcpConnection connection = null;
     try {
       connection = doWrite(message);
     } catch (MessageHandlingException e) {
       // retry - socket may have closed
       if (e.getCause() instanceof IOException) {
         if (logger.isDebugEnabled()) {
           logger.debug("Fail on first write attempt", e);
         }
         connection = doWrite(message);
       } else {
         throw e;
       }
     } finally {
       if (connection != null
           && this.isSingleUse
           && this.clientConnectionFactory.getListener() == null) {
         // if there's no collaborating inbound adapter, close immediately, otherwise
         // it will close after receiving the reply.
         connection.close();
       }
     }
   }
 }