Example #1
0
  public void receive_request_service_contexts(ServerRequestInfo ri) {
    ServiceContext ctx;
    try {
      ctx = ri.get_request_service_context(SERVICE_ID);
    } catch (org.omg.CORBA.BAD_PARAM e) {
      logger.debug(
          "tid=" + Thread.currentThread().getName() + "," + "**Service context was not specified");
      return;
    }

    if (null == ctx) {
      logger.debug("tid=" + Thread.currentThread().getName() + "," + "**Service context is null");
      return;
    }

    try {
      Any slotDataAsAny = codec.decode(ctx.context_data);

      // Get the slot data as a string
      String slotDataAsStr;
      if (null == (slotDataAsStr = slotDataAsAny.extract_string())) {
        logger.debug("slotDataAsStr=<null>");
      } else {
        logger.debug("slotDataAsStr=" + slotDataAsStr);
      }

      slotDataAsStr += ":receive_request_service_contexts";

      slotDataAsAny.insert_string(slotDataAsStr);

      ri.set_slot(slot_id, slotDataAsAny);
    } catch (Exception e) {
      throw new INTERNAL("Caught " + e);
    }
  }
Example #2
0
  private void addStringToSlotId(String methodName, ServerRequestInfo ri) {
    try {
      Any slotDataAsAny = ri.get_slot(slot_id);

      // Get the slot data as a string
      String s = null;
      String slotDataAsStr = "<no_slot_data>";
      if (slotDataAsAny.type().kind().value() != org.omg.CORBA.TCKind._tk_null
          && null != (s = slotDataAsAny.extract_string())) {
        slotDataAsStr = s;
      }

      slotDataAsStr += ":" + methodName;

      slotDataAsAny.insert_string(slotDataAsStr);

      ri.set_slot(slot_id, slotDataAsAny);
    } catch (Exception e) {
      throw new INTERNAL("Caught " + e);
    }
  }
  public void receive_request_service_contexts(ServerRequestInfo ri) {
    try {
      //
      // Test: get operation name
      //
      String op = ri.operation();

      boolean oneway = (op.equals("noargs_oneway"));

      //
      // Test: Arguments should not be available
      //
      try {
        org.omg.Dynamic.Parameter[] args = ri.arguments();
        TEST(false);
      } catch (BAD_INV_ORDER ex) {
        // Expected
      }

      // TODO: test operation_context

      //
      // Test: result is not available
      //
      try {
        Any result = ri.result();
        TEST(false);
      } catch (BAD_INV_ORDER ex) {
        // Expected
      }

      //
      // Test: exceptions
      //
      try {
        TypeCode[] exceptions = ri.exceptions();
        TEST(false);
      } catch (BAD_INV_ORDER ex) {
        // Expected
      }

      //
      // Test: response expected and oneway should be equivalent
      //
      TEST((oneway && !ri.response_expected()) || (!oneway && ri.response_expected()));

      // TODO: test sync scope

      //
      // Test: reply status is not available
      //
      try {
        ri.reply_status();
        TEST(false);
      } catch (BAD_INV_ORDER ex) {
        // Expected
      }

      //
      // Test: forward reference is not available
      //
      try {
        org.omg.CORBA.Object ior = ri.forward_reference();
        TEST(false);
      } catch (BAD_INV_ORDER ex) {
        // Expected
      }

      //
      // Test: object id is not available
      //
      try {
        byte[] id = ri.object_id();
        TEST(false);
      } catch (BAD_INV_ORDER ex) {
        // Expected
      }

      //
      // Test: adapter id is not available
      //
      try {
        byte[] id = ri.adapter_id();
        TEST(false);
      } catch (BAD_INV_ORDER ex) {
        // Expected
      }

      //
      // Test: servant_most_derived_interface is not available
      //
      try {
        String mdi = ri.target_most_derived_interface();
        TEST(false);
      } catch (BAD_INV_ORDER ex) {
        // Expected
      }

      //
      // Test: server id is not available
      //
      try {
        String id = ri.server_id();
        TEST(false);
      } catch (BAD_INV_ORDER ex) {
        // Expected
      }

      //
      // Test: orb id is not available
      //
      try {
        String id = ri.orb_id();
        TEST(false);
      } catch (BAD_INV_ORDER ex) {
        // Expected
      }

      //
      // Test: adapter name is not available
      //
      try {
        String[] name = ri.adapter_name();
        TEST(false);
      } catch (BAD_INV_ORDER ex) {
        // Expected
      }

      //
      // Test: servant_is_a is not available
      //
      try {
        ri.target_is_a("");
        TEST(false);
      } catch (BAD_INV_ORDER ex) {
        // Expected
      }

      if (op.equals("test_service_context")) {
        //
        // Test: get_request_service_context
        //
        try {
          org.omg.IOP.ServiceContext sc = ri.get_request_service_context(REQUEST_CONTEXT_ID.value);
          TEST(sc.context_id == REQUEST_CONTEXT_ID.value);
          byte[] data = new byte[sc.context_data.length];
          System.arraycopy(sc.context_data, 0, data, 0, sc.context_data.length);

          Any any = null;
          try {
            any = cdrCodec_.decode_value(data, RequestContextHelper.type());
          } catch (org.omg.IOP.CodecPackage.FormatMismatch ex) {
            TEST(false);
          } catch (org.omg.IOP.CodecPackage.TypeMismatch ex) {
            TEST(false);
          }
          RequestContext context = RequestContextHelper.extract(any);
          TEST(context.data.equals("request"));
          TEST(context.val == 10);

          //
          // Test: PortableInterceptor::Current
          //
          Any slotData = orb_.create_any();
          slotData.insert_long(context.val);
          try {
            ri.set_slot(0, slotData);
          } catch (InvalidSlot ex) {
            TEST(false);
          }
        } catch (BAD_PARAM ex) {
          TEST(false);
        }

        //
        // Test: add_reply_service_context
        //
        ReplyContext context = new ReplyContext();
        context.data = "reply1";
        context.val = 101;
        Any any = orb_.create_any();
        ReplyContextHelper.insert(any, context);
        byte[] data = null;
        try {
          data = cdrCodec_.encode_value(any);
        } catch (org.omg.IOP.CodecPackage.InvalidTypeForEncoding ex) {
          TEST(false);
        }

        org.omg.IOP.ServiceContext sc = new org.omg.IOP.ServiceContext();
        sc.context_id = REPLY_CONTEXT_1_ID.value;
        sc.context_data = new byte[data.length];
        System.arraycopy(data, 0, sc.context_data, 0, data.length);

        try {
          ri.add_reply_service_context(sc, false);
        } catch (BAD_INV_ORDER ex) {
          TEST(false);
        }

        //
        // Test: add same context again (no replace)
        //
        try {
          ri.add_reply_service_context(sc, false);
          TEST(false);
        } catch (BAD_INV_ORDER ex) {
          // Expected
        }

        //
        // Test: add same context again (replace)
        //
        try {
          ri.add_reply_service_context(sc, true);
        } catch (BAD_INV_ORDER ex) {
          TEST(false);
        }

        //
        // Test: add second context
        //
        context.data = "reply4";
        context.val = 104;
        ReplyContextHelper.insert(any, context);
        try {
          data = cdrCodec_.encode_value(any);
        } catch (org.omg.IOP.CodecPackage.InvalidTypeForEncoding ex) {
          TEST(false);
        }

        sc.context_id = REPLY_CONTEXT_4_ID.value;
        sc.context_data = new byte[data.length];
        System.arraycopy(data, 0, sc.context_data, 0, data.length);

        // try
        // {
        ri.add_reply_service_context(sc, false);
        // }
        // catch(BAD_INV_ORDER ex)
        // {
        // TEST(false);
        // }
      } else {
        //
        // Test: get_request_service_context
        //
        try {
          org.omg.IOP.ServiceContext sc = ri.get_request_service_context(REQUEST_CONTEXT_ID.value);
          TEST(false);
        } catch (BAD_PARAM ex) {
          // Expected
        }
      }

      //
      // Test: get_reply_service_context
      //
      try {
        org.omg.IOP.ServiceContext sc = ri.get_reply_service_context(REPLY_CONTEXT_1_ID.value);
        TEST(false);
      } catch (BAD_INV_ORDER ex) {
        // Expected
      }

      //
      // Test: sending exception is not available
      //
      try {
        Any any = ri.sending_exception();
        TEST(false);
      } catch (BAD_INV_ORDER ex) {
        // Expected
      }

      //
      // Test: get_server_policy
      //
      Policy policy = ri.get_server_policy(MY_SERVER_POLICY_ID.value);
      MyServerPolicy myServerPolicy = MyServerPolicyHelper.narrow(policy);
      TEST(myServerPolicy != null);
      TEST(myServerPolicy.value() == 10);

      try {
        policy = ri.get_server_policy(1013);
        TEST(false);
      } catch (INV_POLICY ex) {
        // Expected
      }
    } catch (test.common.TestException ex) {
      ex.printStackTrace();
      throw ex;
    }
  }