Creates HTTP carbon message.

@param httpMessage HTTP message
@param ctx Channel handler context
@return HttpCarbonMessage
971482
public static HttpCarbonMessage createHTTPCarbonMessage(HttpMessage httpMessage, ChannelHandlerContext ctx) {
        Listener contentListener = new DefaultListener(ctx);
        return new HttpCarbonMessage(httpMessage, contentListener);
    }
607376
protected UserMessage createTellMessage (BodyObject source, String message)
    {
        return UserMessage.create(source.getVisibleName(), message);
    }
841336
protected RequestEntity createStringRequestContent(HTTPRequest httpRequest)
    {
        RequestEntity requestEntity=null;
        String contentString=httpRequest.getContentAsString();
        if(contentString!=null)
        {
            try
            {
                requestEntity=new StringRequestEntity(contentString,"text/plain",null);
            }
            catch(UnsupportedEncodingException exception)
            {
                throw new FaxException("Unable to set string request entity.",exception);
            }
        }
        
        return requestEntity;
    }
1071016
public Message createReplyMessage(Message message)
    {
        Object objResponseID = ((BaseMessage)message).getMessageHeader().get(TrxMessageHeader.MESSAGE_RESPONSE_ID);
        if (objResponseID == null)
            return null;    // TODO (don) FIX this - return an error.
        MessageProcessInfo recMessageProcessInfo = (MessageProcessInfo)this.getMessageProcessInfo(objResponseID.toString());
        MessageInfo recMessageInfo = (MessageInfo)((ReferenceField)recMessageProcessInfo.getField(MessageProcessInfo.MESSAGE_INFO_ID)).getReference();
        BaseMessage replyMessage = new TreeMessage(null, null);
        MessageRecordDesc messageRecordDesc = recMessageInfo.createNewMessage(replyMessage, null);
        return replyMessage;
    }
1222735
public CallProgressMessage createCPG(int cic) {
        CircuitIdentificationCode c = this.parameterFactory.createCircuitIdentificationCode();
        c.setCIC(cic);
        CallProgressMessage msg = this.createCPG();
        msg.setCircuitIdentificationCode(c);
        return msg;
    }
1117531
@Override
    public IQueueMessage<ID, DATA> createMessage(DATA content) {
        return messageFactory.createMessage(content);
    }
839981
public function createMessage() {
        $message = new Message($this->getContext());
        $this->addChild($message);
        $qry = new CreateEntityQuery($message);
        $this->getContext()->addQuery($qry, $message);
        return $message;
    }
757262
static void handle(ChannelHandlerContext ctx, Http2Connection connection,
                              Http2FrameListener listener, FullHttpMessage message) throws Http2Exception {
        try {
            int streamId = getStreamId(connection, message.headers());
            Http2Stream stream = connection.stream(streamId);
            if (stream == null) {
                stream = connection.remote().createStream(streamId, false);
            }
            message.headers().set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), HttpScheme.HTTP.name());
            Http2Headers messageHeaders = HttpConversionUtil.toHttp2Headers(message, true);
            boolean hasContent = message.content().isReadable();
            boolean hasTrailers = !message.trailingHeaders().isEmpty();
            listener.onHeadersRead(
                    ctx, streamId, messageHeaders, 0, !(hasContent || hasTrailers));
            if (hasContent) {
                listener.onDataRead(ctx, streamId, message.content(), 0, !hasTrailers);
            }
            if (hasTrailers) {
                Http2Headers headers = HttpConversionUtil.toHttp2Headers(message.trailingHeaders(), true);
                listener.onHeadersRead(ctx, streamId, headers, 0, true);
            }
            stream.closeRemoteSide();
        } finally {
            message.release();
        }
    }
318040
public static HttpCarbonRequest setupCarbonRequest(HttpRequest httpRequest, Http2SourceHandler http2SourceHandler) {
        ChannelHandlerContext ctx = http2SourceHandler.getChannelHandlerContext();
        HttpCarbonRequest sourceReqCMsg = new HttpCarbonRequest(httpRequest, new DefaultListener(ctx));
        sourceReqCMsg.setProperty(POOLED_BYTE_BUFFER_FACTORY, new PooledDataStreamerFactory(ctx.alloc()));
        sourceReqCMsg.setProperty(CHNL_HNDLR_CTX, ctx);
        sourceReqCMsg.setProperty(Constants.SRC_HANDLER, http2SourceHandler);
        HttpVersion protocolVersion = httpRequest.protocolVersion();
        sourceReqCMsg.setProperty(HTTP_VERSION, protocolVersion.majorVersion() + "." + protocolVersion.minorVersion());
        sourceReqCMsg.setProperty(HTTP_METHOD, httpRequest.method().name());

        InetSocketAddress localAddress = null;
        //This check was added because in case of netty embedded channel, this could be of type 'EmbeddedSocketAddress'.
        if (ctx.channel().localAddress() instanceof InetSocketAddress) {
            localAddress = (InetSocketAddress) ctx.channel().localAddress();
        }
        sourceReqCMsg.setProperty(LOCAL_ADDRESS, localAddress);
        sourceReqCMsg.setProperty(LISTENER_PORT, localAddress != null ? localAddress.getPort() : null);
        sourceReqCMsg.setProperty(LISTENER_INTERFACE_ID, http2SourceHandler.getInterfaceId());
        sourceReqCMsg.setProperty(PROTOCOL, HTTP_SCHEME);
        String uri = httpRequest.uri();
        sourceReqCMsg.setProperty(REQUEST_URL, uri);
        sourceReqCMsg.setProperty(TO, uri);
        return sourceReqCMsg;
    }
45402
@POST
    @Produces({ MediaType.APPLICATION_OCTET_STREAM })
    public Response postMessage(@PathParam("ccid") String ccid, byte[] serializedMessage) {
        ImmutableMessage message;

        try {
            message = new ImmutableMessage(serializedMessage);
        } catch (EncodingException | UnsuppportedVersionException e) {
            throw new JoynrHttpException(Status.BAD_REQUEST, JOYNRMESSAGINGERROR_DESERIALIZATIONFAILED);
        }

        try {
            log.debug("POST message to channel: {} message: {}", ccid, message);

            // TODO Can this happen at all with empty path parameter???
            if (ccid == null) {
                log.error("POST message to channel: NULL. message: {} dropped because: channel Id was not set",
                          message);
                throw new JoynrHttpException(Status.BAD_REQUEST, JOYNRMESSAGINGERROR_CHANNELNOTSET);
            }

            // send the message to the receiver.
            if (message.getTtlMs() == 0) {
                log.error("POST message to channel: {} message: {} dropped because: TTL not set", ccid, message);
                throw new JoynrHttpException(Status.BAD_REQUEST, JOYNRMESSAGINGERROR_EXPIRYDATENOTSET);
            }

            if (message.getTtlMs() < timestampProvider.getCurrentTime()) {
                log.warn("POST message {} to cluster controller: {} dropped because: TTL expired",
                         ccid,
                         message.getId());
                throw new JoynrHttpException(Status.BAD_REQUEST,
                                             JOYNRMESSAGINGERROR_EXPIRYDATEEXPIRED,
                                             request.getRemoteHost());
            }

            if (!messagingService.isAssignedForChannel(ccid)) {
                // scalability extensions: in case that other component should handle this channel
                log.debug("POST message {}: Bounce Proxy not assigned for channel: {}", message, ccid);

                if (messagingService.hasChannelAssignmentMoved(ccid)) {
                    // scalability extension: in case that this component was responsible before but isn't any more
                    log.debug("POST message {}: Bounce Proxy assignment moved for channel: {}", message, ccid);
                    return Response.status(410 /* Gone */).build();
                } else {
                    log.debug("POST message {}: channel  unknown: {}", message, ccid);
                    return Response.status(404 /* Not Found */).build();
                }
            }

            // if the receiver has never registered with the bounceproxy
            // (or his registration has expired) then return 204 no
            // content.
            if (!messagingService.hasMessageReceiver(ccid)) {
                log.debug("POST message {}: no receiver for channel: {}", message, ccid);
                return Response.noContent().build();
            }

            messagingService.passMessageToReceiver(ccid, serializedMessage);

            // the location that can be queried to get the message
            // status
            // TODO REST URL for message status?
            URI location = ui.getBaseUriBuilder().path("messages/" + message.getId()).build();

            // encode URL in case we use sessions
            String encodeURL = response.encodeURL(location.toString());

            // return the message status location to the sender.
            return Response.created(URI.create(encodeURL)).header("msgId", message.getId()).build();

        } catch (WebApplicationException e) {
            throw e;
        } catch (Exception e) {
            log.debug("POST message to channel: {} error: {}", ccid, e.getMessage());
            throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
        }

    }
1108409
function(cb) {
        var self = this,
            carbonParams = {
                type: 'set',
                from: self.helpers.getUserCurrentJid(),
                id: chatUtils.getUniqueId('enableCarbons')
            },
            builder = Utils.getEnv().browser ? $iq : XMPP.Stanza;

        var iq = chatUtils.createStanza(builder, carbonParams, 'iq');

        iq.c('enable', {
            xmlns: chatUtils.MARKERS.CARBONS
        });

        if (Utils.getEnv().browser) {
            self.connection.sendIQ(iq);
        } else {
            self.Client.send(iq);
        }
    }
416960
@Override
  protected void channelRead0(final ChannelHandlerContext ctx, final HttpObject msg) throws Exception {
    if (msg instanceof HttpContent) {
      HttpContent content = (HttpContent) msg;
      decodeChunk((InetSocketAddress) ctx.channel().remoteAddress(), content.content());
    }
  }
938790
@Override
    public AddressMessage makeAddressMessage(byte[] payloadBytes, int length) throws ProtocolException {
        return new AddressMessage(params, payloadBytes, this, length);
    }
703862
public BaseMessage sendMessageRequest(BaseMessage messageOut)
    {
        String strTrxID = null;
        try {
            // Create a message from the message factory.
            String strXmlMessageOut = messageOut.getExternalMessage().toString();
            // Create an endpoint for the recipient of the message.
            TrxMessageHeader trxMessageHeader = (TrxMessageHeader)messageOut.getMessageHeader();
            String strDest = (String)trxMessageHeader.get(TrxMessageHeader.DESTINATION_PARAM);
            String strMsgDest = (String)trxMessageHeader.get(TrxMessageHeader.DESTINATION_MESSAGE_PARAM);
            if (strMsgDest != null)
                strDest = strDest + strMsgDest;
            strTrxID = (String)trxMessageHeader.get(TrxMessageHeader.LOG_TRX_ID);

            URL url = new URL(strDest);
            Properties properties = new Properties();
            properties.setProperty("xml", strXmlMessageOut);
            // Send the message to the provider using the connection.
            // Create a message from the message factory.
//x            msg.setProperty(SOAPMessage.WRITE_XML_DECLARATION, DBConstants.TRUE);
//x            msg.getMimeHeaders().setHeader("Content-Type", "text/xml");

            ServletMessage servlet = new ServletMessage(url);
            InputStream in = servlet.sendMessage(properties);

            this.logMessage(strTrxID, messageOut, MessageInfoTypeModel.REQUEST, MessageTypeModel.MESSAGE_OUT, MessageStatusModel.SENT, null, null);
            
            InputStreamReader reader = new InputStreamReader(in);
            BufferedReader buffReader = new BufferedReader(reader);
            StringBuffer sbReply = new StringBuffer();
            while (true)
            {
                String str = buffReader.readLine();
                if ((str == null) || (str.length() == 0))
                    break;
                if (sbReply.length() > 0)
                    sbReply.append("\n");
                sbReply.append(str);
            }
            if (sbReply.length() > 0)
            {
                BaseMessage messageReply = new TreeMessage(null, null);
                new XmlTrxMessageIn(messageReply, sbReply.toString());
                return messageReply;
            } else {
                System.err.println("No reply");
            }
        } catch(Throwable ex) {
            ex.printStackTrace();
            String strErrorMessage = ex.getMessage();
            this.logMessage(strTrxID, messageOut, MessageInfoTypeModel.REQUEST, MessageTypeModel.MESSAGE_OUT, MessageStatusModel.ERROR, strErrorMessage, null);
            return BaseMessageProcessor.processErrorMessage(this, messageOut, strErrorMessage);
        }            

        return null;
    }
612438
public void processHttpRequestMessage(HttpMessage message) {
		// Get the session tokens for this site
		HttpSessionTokensSet siteTokensSet = extension.getHttpSessionTokensSet(getSite());

		// No tokens for this site, so no processing
		if (siteTokensSet == null) {
			log.debug("No session tokens for: " + this.getSite());
			return;
		}

		// Get the matching session, based on the request header
		List<HttpCookie> requestCookies = message.getRequestHeader().getHttpCookies();
		HttpSession session = getMatchingHttpSession(requestCookies, siteTokensSet);
		if (log.isDebugEnabled()) {
			log.debug("Matching session for request message (for site " + getSite() + "): " + session);
		}

		// If any session is active (forced), change the necessary cookies
		if (activeSession != null && activeSession != session) {
			CookieBasedSessionManagementHelper.processMessageToMatchSession(message, requestCookies,
					activeSession);
		} else {
			if (activeSession == session) {
				log.debug("Session of request message is the same as the active session, so no request changes needed.");
			} else {
				log.debug("No active session is selected.");
			}

			// Store the session in the HttpMessage for caching purpose
			message.setHttpSession(session);
		}
	}
1111291
public WxCpXmlOutMessage route(final WxCpXmlMessage wxMessage) {
    if (isDuplicateMessage(wxMessage)) {
      // 如果是重复消息，那么就不做处理
      return null;
    }

    final List<WxCpMessageRouterRule> matchRules = new ArrayList<WxCpMessageRouterRule>();
    // 收集匹配的规则
    for (final WxCpMessageRouterRule rule : rules) {
      if (rule.test(wxMessage)) {
        matchRules.add(rule);
        if(!rule.isReEnter()) {
          break;
        }
      }
    }

    if (matchRules.size() == 0) {
      return null;
    }

    WxCpXmlOutMessage res = null;
    final List<Future> futures = new ArrayList<Future>();
    for (final WxCpMessageRouterRule rule : matchRules) {
      // 返回最后一个非异步的rule的执行结果
      if(rule.isAsync()) {
        futures.add(
            executorService.submit(new Runnable() {
              public void run() {
                rule.service(wxMessage, wxCpService, sessionManager, exceptionHandler);
              }
            })
        );
      } else {
        res = rule.service(wxMessage, wxCpService, sessionManager, exceptionHandler);
        // 在同步操作结束，session访问结束
        log.debug("End session access: async=false, sessionId={}", wxMessage.getFromUserName());
        sessionEndAccess(wxMessage);
      }
    }

    if (futures.size() > 0) {
      executorService.submit(new Runnable() {
        @Override
        public void run() {
          for (Future future : futures) {
            try {
              future.get();
              log.debug("End session access: async=true, sessionId={}", wxMessage.getFromUserName());
              // 异步操作结束，session访问结束
              sessionEndAccess(wxMessage);
            } catch (InterruptedException e) {
              log.error("Error happened when wait task finish", e);
            } catch (ExecutionException e) {
              log.error("Error happened when wait task finish", e);
            }
          }
        }
      });
    }
    return res;
  }
1275616
public ConfusionMessage createCNF(int cic) {
        ConfusionMessage msg = createCNF();
        CircuitIdentificationCode code = this.parameterFactory.createCircuitIdentificationCode();
        code.setCIC(cic);
        msg.setCircuitIdentificationCode(code);
        return msg;
    }