/** Create the initial message context for the file */
 private org.apache.synapse.MessageContext createMessageContext() {
   org.apache.synapse.MessageContext msgCtx = synapseEnvironment.createMessageContext();
   MessageContext axis2MsgCtx =
       ((org.apache.synapse.core.axis2.Axis2MessageContext) msgCtx).getAxis2MessageContext();
   axis2MsgCtx.setServerSide(true);
   axis2MsgCtx.setMessageID(UUIDGenerator.getUUID());
   return msgCtx;
 }
 /** Create the initial message context for the file */
 private org.apache.synapse.MessageContext createMessageContext() {
   org.apache.synapse.MessageContext msgCtx = synapseEnvironment.createMessageContext();
   // Need to set this to build the message
   msgCtx.setProperty(SynapseConstants.INBOUND_JMS_PROTOCOL, true);
   MessageContext axis2MsgCtx =
       ((org.apache.synapse.core.axis2.Axis2MessageContext) msgCtx).getAxis2MessageContext();
   axis2MsgCtx.setServerSide(true);
   axis2MsgCtx.setMessageID(UUIDGenerator.getUUID());
   PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
   axis2MsgCtx.setProperty(MultitenantConstants.TENANT_DOMAIN, carbonContext.getTenantDomain());
   // There is a discrepency in what I thought, Axis2 spawns a nes threads
   // to
   // send a message is this is TRUE - and I want it to be the other way
   msgCtx.setProperty(MessageContext.CLIENT_API_NON_BLOCKING, true);
   return msgCtx;
 }
  private static MessageContext cloneForSend(MessageContext ori, String preserveAddressing)
      throws AxisFault {

    MessageContext newMC = MessageHelper.clonePartially(ori);

    newMC.setEnvelope(ori.getEnvelope());
    if (preserveAddressing != null && Boolean.parseBoolean(preserveAddressing)) {
      newMC.setMessageID(ori.getMessageID());
    } else {
      MessageHelper.removeAddressingHeaders(newMC);
    }

    newMC.setProperty(
        org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS,
        ori.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS));

    return newMC;
  }
    private void send(MessageContext msgctx) throws AxisFault {

      // create the responseMessageContext and set that its related to the current outgoing
      // message, so that it could be tied back to the original request even if the response
      // envelope does not contain addressing headers
      MessageContext responseMessageContext = new MessageContext();
      responseMessageContext.setMessageID(msgctx.getMessageID());
      responseMessageContext.setProperty(
          SynapseConstants.RELATES_TO_FOR_POX, msgctx.getMessageID());
      responseMessageContext.setOptions(options);
      responseMessageContext.setServerSide(true);
      addMessageContext(responseMessageContext);
      responseMessageContext.setProperty("synapse.send", "true");

      AxisEngine.send(msgctx);

      // did the engine receive a immediate synchronous response?
      // e.g. sometimes the transport sender may listen for a syncronous reply
      if (msgctx.getProperty(MessageContext.TRANSPORT_IN) != null) {

        responseMessageContext.setOperationContext(msgctx.getOperationContext());
        responseMessageContext.setAxisMessage(
            msgctx
                .getOperationContext()
                .getAxisOperation()
                .getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE));
        responseMessageContext.setAxisService(msgctx.getAxisService());

        responseMessageContext.setProperty(
            MessageContext.TRANSPORT_OUT, msgctx.getProperty(MessageContext.TRANSPORT_OUT));
        responseMessageContext.setProperty(
            org.apache.axis2.Constants.OUT_TRANSPORT_INFO,
            msgctx.getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO));

        responseMessageContext.setProperty(
            org.apache.synapse.SynapseConstants.ISRESPONSE_PROPERTY, Boolean.TRUE);
        responseMessageContext.setTransportIn(msgctx.getTransportIn());
        responseMessageContext.setTransportOut(msgctx.getTransportOut());

        // If request is REST assume that the responseMessageContext is REST too
        responseMessageContext.setDoingREST(msgctx.isDoingREST());

        responseMessageContext.setProperty(
            MessageContext.TRANSPORT_IN, msgctx.getProperty(MessageContext.TRANSPORT_IN));
        responseMessageContext.setTransportIn(msgctx.getTransportIn());
        responseMessageContext.setTransportOut(msgctx.getTransportOut());

        // Options object reused above so soapAction needs to be removed so
        // that soapAction+wsa:Action on response don't conflict
        responseMessageContext.setSoapAction("");

        if (responseMessageContext.getEnvelope() == null) {
          // If request is REST we assume the responseMessageContext is
          // REST, so set the variable

          Options options = responseMessageContext.getOptions();
          if (options != null) {
            RelatesTo relatesTo = options.getRelatesTo();
            if (relatesTo != null) {
              relatesTo.setValue(msgctx.getMessageID());
            } else {
              options.addRelatesTo(new RelatesTo(msgctx.getMessageID()));
            }
          }

          SOAPEnvelope resenvelope = TransportUtils.createSOAPMessage(responseMessageContext);

          if (resenvelope != null) {
            responseMessageContext.setEnvelope(resenvelope);
            AxisEngine.receive(responseMessageContext);
            if (responseMessageContext.getReplyTo() != null) {
              sc.setTargetEPR(responseMessageContext.getReplyTo());
            }

            complete(msgctx);
          } else {
            throw new AxisFault(Messages.getMessage("blockingInvocationExpectsResponse"));
          }
        }
      }
    }
Exemplo n.º 5
0
  /**
   * Create an Axis2 message context for the given http request. The request may be in the process
   * of being streamed
   *
   * @param request the http request to be used to create the corresponding Axis2 message context
   * @return the Axis2 message context created
   */
  private MessageContext createMessageContext(HttpRequest request) {

    MessageContext msgContext = new MessageContext();
    msgContext.setMessageID(UIDGenerator.generateURNString());

    // There is a discrepency in what I thought, Axis2 spawns a new threads to
    // send a message if this is TRUE - and I want it to be the other way
    msgContext.setProperty(MessageContext.CLIENT_API_NON_BLOCKING, Boolean.FALSE);
    msgContext.setConfigurationContext(cfgCtx);
    if ("https".equalsIgnoreCase(schemeName)) {
      msgContext.setTransportOut(
          cfgCtx.getAxisConfiguration().getTransportOut(Constants.TRANSPORT_HTTPS));
      msgContext.setTransportIn(
          cfgCtx.getAxisConfiguration().getTransportIn(Constants.TRANSPORT_HTTPS));
      msgContext.setIncomingTransportName(Constants.TRANSPORT_HTTPS);
      SSLIOSession session = (SSLIOSession) (conn.getContext()).getAttribute("SSL_SESSION");
      msgContext.setProperty(
          "ssl.client.auth.cert.X509", session.getAttribute("ssl.client.auth.cert.X509"));

    } else {
      msgContext.setTransportOut(
          cfgCtx.getAxisConfiguration().getTransportOut(Constants.TRANSPORT_HTTP));
      msgContext.setTransportIn(
          cfgCtx.getAxisConfiguration().getTransportIn(Constants.TRANSPORT_HTTP));
      msgContext.setIncomingTransportName(Constants.TRANSPORT_HTTP);
    }
    msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, this);
    // the following statement causes the soap session services to be failing - ruwan
    // msgContext.setServiceGroupContextId(UUIDGenerator.getUUID());
    msgContext.setServerSide(true);
    msgContext.setProperty(
        Constants.Configuration.TRANSPORT_IN_URL, request.getRequestLine().getUri());

    // http transport header names are case insensitive
    Map<String, String> headers =
        new TreeMap<String, String>(
            new Comparator<String>() {
              public int compare(String o1, String o2) {
                return o1.compareToIgnoreCase(o2);
              }
            });

    for (Header header : request.getAllHeaders()) {

      String headerName = header.getName();

      // if this header is already added
      if (headers.containsKey(headerName)) {
        /* this is a multi-value header */
        // generate the key
        String key = NhttpConstants.EXCESS_TRANSPORT_HEADERS;
        // get the old value
        String oldValue = headers.get(headerName);
        // adds additional values to a list in a property of message context
        Map map;
        if (msgContext.getProperty(key) != null) {
          map = (Map) msgContext.getProperty(key);
          map.put(headerName, oldValue);
        } else {
          map = new MultiValueMap();
          map.put(headerName, oldValue);
          // set as a property in message context
          msgContext.setProperty(key, map);
        }
      }
      headers.put(header.getName(), header.getValue());
    }
    msgContext.setProperty(MessageContext.TRANSPORT_HEADERS, headers);

    // find the remote party IP address and set it to the message context
    if (conn instanceof HttpInetConnection) {
      HttpInetConnection inetConn = (HttpInetConnection) conn;
      InetAddress remoteAddr = inetConn.getRemoteAddress();
      if (remoteAddr != null) {
        msgContext.setProperty(MessageContext.REMOTE_ADDR, remoteAddr.getHostAddress());
        msgContext.setProperty(NhttpConstants.REMOTE_HOST, NhttpUtil.getHostName(remoteAddr));
        remoteAddress = remoteAddr.getHostAddress();
      }
    }

    msgContext.setProperty(
        RequestResponseTransport.TRANSPORT_CONTROL,
        new HttpCoreRequestResponseTransport(msgContext));

    msgContext.setProperty(
        ServerHandler.SERVER_CONNECTION_DEBUG,
        conn.getContext().getAttribute(ServerHandler.SERVER_CONNECTION_DEBUG));

    msgContext.setProperty(NhttpConstants.NHTTP_INPUT_STREAM, is);
    msgContext.setProperty(NhttpConstants.NHTTP_OUTPUT_STREAM, os);

    return msgContext;
  }