Example #1
0
  @Override
  public T getObject(MethodContext methodContext) {
    T fieldVal = null;

    if (!mapAcsr.isEmpty()) {
      Map<String, ? extends Object> fromMap = mapAcsr.get(methodContext);
      if (fromMap == null) {
        Debug.logWarning(
            "Map not found with name " + mapAcsr + ", not getting Object value, returning null.",
            module);
        return null;
      }
      fieldVal = fieldAcsr.get(fromMap, methodContext);
    } else {
      // no map name, try the env
      fieldVal = fieldAcsr.get(methodContext);
    }

    if (fieldVal == null) {
      if (Debug.infoOn())
        Debug.logInfo(
            "Field value not found with name "
                + fieldAcsr
                + " in Map with name "
                + mapAcsr
                + ", not getting Object value, returning null.",
            module);
      return null;
    }

    return fieldVal;
  }
Example #2
0
 @Override
 public Class<T> getTypeClass(ClassLoader loader) {
   try {
     return UtilGenerics.cast(ObjectType.loadClass(type, loader));
   } catch (ClassNotFoundException e) {
     Debug.logError(e, "Could not find class for type: " + type, module);
     return null;
   }
 }
Example #3
0
  @Override
  public boolean exec(MethodContext methodContext) {
    Object fieldVal = null;

    if (!mapAcsr.isEmpty()) {
      Map<String, ? extends Object> fromMap = mapAcsr.get(methodContext);

      if (fromMap == null) {
        if (Debug.infoOn())
          Debug.logInfo(
              "Map not found with name " + mapAcsr + ", not copying from this map", module);
        return true;
      }

      fieldVal = fieldAcsr.get(fromMap, methodContext);
    } else {
      // no map name, try the env
      fieldVal = fieldAcsr.get(methodContext);
    }

    if (fieldVal == null) {
      if (Debug.verboseOn())
        Debug.logVerbose(
            "Field value not found with name "
                + fieldAcsr
                + " in Map with name "
                + mapAcsr
                + ", not copying field",
            module);
      return true;
    }

    // note that going to an env field will only work if it came from an env
    // field because if not specified the to-map-name will be set to the map-name
    // to go from a map field to an env field, use the field-to-env operation
    Map<String, Object> toMap = null;

    if (!toMapAcsr.isEmpty()) {
      toMap = toMapAcsr.get(methodContext);
      if (toMap == null) {
        if (Debug.verboseOn())
          Debug.logVerbose("Map not found with name " + toMapAcsr + ", creating new map", module);
        toMap = FastMap.newInstance();
        toMapAcsr.put(methodContext, toMap);
      }
      toFieldAcsr.put(toMap, fieldVal, methodContext);
    } else {
      // no to-map, so put in env
      toFieldAcsr.put(methodContext, fieldVal);
    }

    return true;
  }
  public static void main(String[] args) {
    Debug.enableAll();
    String HEADER =
        "<HEADER>"
            + "<REQUEST value=\"LSR_ORDER\"/>"
            + "<SUB_REQUEST value=\"loop\"/>"
            + "<SUPPLIER value=\"VZE\"/>"
            + "</HEADER>";
    RequestHandlerClient sr = null;

    try {
      String xml = FileUtils.readFile(args[0]);
      MessageProcessorContext ctx = new MessageProcessorContext();
      ctx.set("NF_HEADER_LOCATION_PROP", HEADER);
      sr = new RequestHandlerClient();
      sr.serverName = "Nightfire.Router";
      NVPair[] result = sr.process(ctx, new MessageObject((Object) xml));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  /**
   * Make the actual CORBA call.
   *
   * @param serverName Name of the server as known in the COS Naming Service.
   * @param reload Flag indicating whether object reference should be refreshed (true) or any
   *     previously-cached version should be used (false).
   * @param header Header message to send.
   * @param message Body message to send.
   * @return Response that caller should return.
   * @exception Exception Thrown on any errors.
   */
  private String makeClientCall(String serverName, boolean reload, String header, String message)
      throws Exception {
    ORB orb = null;

    // If the alternate ip and port are provided
    if (StringUtils.hasValue(orbAgentAddr) && StringUtils.hasValue(orbAgentPort)) {
      // Key to store the orb in a static map for access the next time around
      String key = orbAgentAddr + ":" + orbAgentPort;

      synchronized (orbStore) {
        orb = (ORB) orbStore.get(key);

        if (orb == null) {
          Properties props = new Properties();
          props.put(ORB_AGENT_ADDR_PROP, orbAgentAddr);
          props.put(ORB_AGENT_PORT_PROP, orbAgentPort);
          orb = new CorbaPortabilityLayer(new String[0], props, null, serverName).getORB();

          orbStore.put(key, orb);
        } else {
          if (Debug.isLevelEnabled(Debug.IO_STATUS))
            Debug.log(
                Debug.IO_STATUS,
                "Using cached orb with properties "
                    + "ORBagentAddr = ["
                    + orbAgentAddr
                    + "] ORBagentPort = ["
                    + orbAgentPort
                    + "]");
        }
      }
    } else {
      if (Debug.isLevelEnabled(Debug.IO_STATUS))
        Debug.log(Debug.IO_STATUS, "Using the default orb ..");

      orb = Supervisor.getSupervisor().getCPL().getORB();
    }

    ObjectLocator ob_loc = new ObjectLocator(orb);

    if (reload) {
      ob_loc.removeFromCache(serverName);
      if (StringUtils.hasValue(orbAgentAddr) && StringUtils.hasValue(orbAgentPort))
        ob_loc.removeFromCache(serverName, orbAgentAddr, orbAgentPort);
    }

    RequestHandler rh = null;
    // The key corresponding to secondary install object references depends on host address and port
    // too.
    if (StringUtils.hasValue(orbAgentAddr) && StringUtils.hasValue(orbAgentPort))
      rh = RequestHandlerHelper.narrow(ob_loc.find(serverName, orbAgentAddr, orbAgentPort));
    else rh = RequestHandlerHelper.narrow(ob_loc.find(serverName));

    if (rh == null) {
      throw new Exception("Object named [" + serverName + "] is not of IDL type RequestHandler.");
    }

    // Make sure that the header contains any available customer context information.
    header = CustomerContext.getInstance().propagate(header);

    if (Debug.isLevelEnabled(Debug.IO_STATUS))
      Debug.log(Debug.IO_STATUS, "Header value:\n" + header);

    ThreadMonitor.ThreadInfo tmti =
        ThreadMonitor.start(
            "Message-processor ["
                + getName()
                + "] making CORBA client call with header:\n"
                + header);

    try {
      if (isAsync) {
        rh.processAsync(header, message);

        return (message);
      } else {
        org.omg.CORBA.StringHolder response = new org.omg.CORBA.StringHolder("");

        rh.processSync(header, message, response);

        return (response.value);
      }
    } finally {
      ThreadMonitor.stop(tmti);
    }
  }
  /**
   * If NF_HEADER_LOCATION_PROP exists in context use as the header to forward to Gateway. If
   * IS_ASYNCHRONOUS_PROP exists in context then use that value to call either processAsync or
   * processSync
   *
   * @param input MessageObject containing the value to be processed *
   * @param mpcontext The context
   * @return Optional NVPair containing a Destination name and a MessageObject, or null if none.
   * @exception ProcessingException Thrown if processing fails.
   * @exception MessageException Thrown if bad message.
   */
  public NVPair[] process(MessageProcessorContext ctx, MessageObject input)
      throws MessageException, ProcessingException {
    if (input == null) return null;

    try {
      serverName = getRequiredProperty(ctx, input, SERVER_NAME_PROP);
    } catch (MessageException me) {
      throw new ProcessingException(me.getMessage());
    }

    if (StringUtils.hasValue(headerLocation)) {
      try {
        header = getString(headerLocation, ctx, input);
      } catch (MessageException me) {
        throw new ProcessingException(me.getMessage());
      }
    }

    if (StringUtils.hasValue(isAsyncLocation)) {
      try {
        isAsync = StringUtils.getBoolean(getString(isAsyncLocation, ctx, input));
      } catch (FrameworkException fe) {
        throw new ProcessingException(
            "Value of " + IS_ASYNCHRONOUS_LOCATION_PROP + " is not TRUE/FALSE. " + fe.getMessage());
      }
    }

    // Fetch the alternate Orb Address, if one exists at the specified context location
    if (StringUtils.hasValue(orbAgentAddrLocation)) {
      try {
        if (exists(orbAgentAddrLocation, ctx, input, true)) {
          orbAgentAddr = getString(orbAgentAddrLocation, ctx, input);
          if (Debug.isLevelEnabled(Debug.MSG_STATUS))
            Debug.log(
                Debug.MSG_STATUS,
                "RequestHandlerClient:: alternate orb exists with orb agent address ["
                    + orbAgentAddr
                    + "]");
        }
      } catch (MessageException me) {
        throw new ProcessingException(me.getMessage());
      }
    }

    // Fetch the alternate Orb Port, if one exists at the specified context location
    if (StringUtils.hasValue(orbAgentPortLocation)) {
      try {
        if (exists(orbAgentPortLocation, ctx, input, true)) {
          orbAgentPort = getString(orbAgentPortLocation, ctx, input);
          if (Debug.isLevelEnabled(Debug.MSG_STATUS))
            Debug.log(
                Debug.MSG_STATUS,
                "RequestHandlerClient:: alternate orb exists with orb agent port ["
                    + orbAgentPort
                    + "]");
        }
      } catch (MessageException me) {
        throw new ProcessingException(me.getMessage());
      }
    }

    String msg = input.getString();

    try {
      try {
        return (formatNVPair(makeClientCall(serverName, false, header, msg)));
      } catch (Exception e) {
        // Any of the following exceptions indicate that the failure might be due to
        // a CORBA communications issue (stale object reference) that should be retried.
        if ((e instanceof org.omg.CORBA.OBJECT_NOT_EXIST)
            || (e instanceof org.omg.CORBA.TRANSIENT)
            || (e instanceof org.omg.CORBA.COMM_FAILURE)
            || (e instanceof org.omg.CORBA.INV_OBJREF)
            || (e instanceof org.omg.CORBA.UNKNOWN)) {
          Debug.warning(
              "Caught the following CORBA communication error, so retrying:\n"
                  + e.toString()
                  + "\n"
                  + Debug.getStackTrace(e));

          return (formatNVPair(makeClientCall(serverName, true, header, msg)));
        } else {
          // It's not a communication exception indicating that retry is recommended,
          // so just re-throw it.
          throw e;
        }
      }
    } catch (Exception e) {
      if (e instanceof InvalidDataException) {
        Debug.error(e.toString() + "\n" + Debug.getStackTrace(e));

        throw new MessageException(((InvalidDataException) e).errorMessage);
      } else {
        Debug.error(e.toString() + "\n" + Debug.getStackTrace(e));

        throw new ProcessingException(e.toString());
      }
    }
  }