コード例 #1
0
ファイル: AccountManagerImpl.java プロジェクト: mberionni/uni
  public void invoke(
      org.omg.CORBA.ServerRequest request) { // Ensure that the operation name is correct
    System.out.println("invocato metodo " + request.operation() + " in AccounManagerImpl");
    Float balance;
    String name = new String(_object_id());

    if (request.operation().equals("open")) {
      org.omg.CORBA.NVList params = orb.create_list(1);
      org.omg.CORBA.Any any = orb.create_any();
      any.insert_string(new String(""));
      params.add_value("nomeFile", any, org.omg.CORBA.ARG_IN.value);
      request.arguments(params);
      try {
        name = params.item(0).value().extract_string();
      } catch (Exception e) {
        System.out.println("ERRORE:");
        e.printStackTrace();
      }
      // Invoke the actual implementation and fill out the result
      org.omg.CORBA.Object account = open(name);
      org.omg.CORBA.Any result = orb.create_any();
      result.insert_Object(account);
      request.set_result(result);
    } else {
      System.out.println("Errore nell'ivocazione dinamica del metodo open");
      throw new org.omg.CORBA.BAD_PARAM();
    }
  }
コード例 #2
0
ファイル: CSIv2Util.java プロジェクト: GeekkeeG/wildfly
  /**
   * Return a top-level {@code IOP:TaggedComponent} to be stuffed into an IOR, containing a {@code
   * CSIIOP}. {@code CompoundSecMechList}, tagged as {@code TAG_CSI_SEC_MECH_LIST}. Only one such
   * component can exist inside an IOR.
   *
   * <p>Should be called with non-null metadata, in which case we probably don't want to include
   * security info in the IOR.
   *
   * @param metadata the metadata object that contains the CSIv2 security configuration info.
   * @param codec the {@code Codec} used to encode the CSIv2 security component.
   * @param sslPort an {@code int} representing the SSL port.
   * @param orb a reference to the running {@code ORB}.
   * @return a {@code TaggedComponent} representing the encoded CSIv2 security component.
   */
  public static TaggedComponent createSecurityTaggedComponent(
      IORSecurityConfigMetaData metadata, Codec codec, int sslPort, ORB orb) {
    if (metadata == null) {
      JacORBLogger.ROOT_LOGGER.createSecurityTaggedComponentWithNullMetaData();
      return null;
    }

    TaggedComponent tc;

    // get the the supported security mechanisms.
    CompoundSecMech[] mechList = createCompoundSecMechanisms(metadata, codec, sslPort, orb);

    // the above is wrapped into a CSIIOP.CompoundSecMechList structure, which is NOT a
    // CompoundSecMech[].
    // we don't support stateful/reusable security contexts (false).
    CompoundSecMechList csmList = new CompoundSecMechList(false, mechList);
    // finally, the CompoundSecMechList must be encoded as a TaggedComponent
    try {
      Any any = orb.create_any();
      CompoundSecMechListHelper.insert(any, csmList);
      byte[] b = codec.encode_value(any);
      tc = new TaggedComponent(TAG_CSI_SEC_MECH_LIST.value, b);
    } catch (InvalidTypeForEncoding e) {
      throw JacORBLogger.ROOT_LOGGER.unexpectedException(e);
    }
    return tc;
  }
コード例 #3
0
ファイル: KerberosServer.java プロジェクト: aabykov/JacORB
  public KerberosServer(String[] args) {
    try {
      // initialize the ORB and POA.
      orb = ORB.init(args, null);
      POA rootPOA = (POA) orb.resolve_initial_references("RootPOA");
      org.omg.CORBA.Policy[] policies = new org.omg.CORBA.Policy[3];
      policies[0] = rootPOA.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID);
      policies[1] = rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT);
      Any sasAny = orb.create_any();
      SASPolicyValuesHelper.insert(
          sasAny,
          new SASPolicyValues(EstablishTrustInClient.value, EstablishTrustInClient.value, true));
      policies[2] = orb.create_policy(SAS_POLICY_TYPE.value, sasAny);
      POA securePOA = rootPOA.create_POA("SecurePOA", rootPOA.the_POAManager(), policies);
      rootPOA.the_POAManager().activate();

      // create object and write out IOR
      securePOA.activate_object_with_id("SecureObject".getBytes(), this);
      org.omg.CORBA.Object demo = securePOA.servant_to_reference(this);
      PrintWriter pw = new PrintWriter(new FileWriter(args[0]));
      pw.println(orb.object_to_string(demo));
      pw.flush();
      pw.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #4
0
ファイル: CSIv2Util.java プロジェクト: jmcarrascal/jboss-as
  /**
   * Return a top-level {@code IOP:TaggedComponent} to be stuffed into an IOR, containing a {@code
   * CSIIOP}. {@code CompoundSecMechList}, tagged as {@code TAG_CSI_SEC_MECH_LIST}. Only one such
   * component can exist inside an IOR.
   *
   * <p>Should be called with non-null metadata, in which case we probably don't want to include
   * security info in the IOR.
   *
   * @param metadata the metadata object that contains the CSIv2 security configuration info.
   * @param codec the {@code Codec} used to encode the CSIv2 security component.
   * @param sslPort an {@code int} representing the SSL port.
   * @param orb a reference to the running {@code ORB}.
   * @return a {@code TaggedComponent} representing the encoded CSIv2 security component.
   */
  public static TaggedComponent createSecurityTaggedComponent(
      IORSecurityConfigMetadata metadata, Codec codec, int sslPort, ORB orb) {
    if (metadata == null) {
      log.debugf("createSecurityTaggedComponent() called with null metadata");
      return null;
    }

    TaggedComponent tc;

    // get the the supported security mechanisms.
    CompoundSecMech[] mechList = createCompoundSecMechanisms(metadata, codec, sslPort, orb);

    // the above is wrapped into a CSIIOP.CompoundSecMechList structure, which is NOT a
    // CompoundSecMech[].
    // we don't support stateful/reusable security contexts (false).
    CompoundSecMechList csmList = new CompoundSecMechList(false, mechList);
    // finally, the CompoundSecMechList must be encoded as a TaggedComponent
    try {
      Any any = orb.create_any();
      CompoundSecMechListHelper.insert(any, csmList);
      byte[] b = codec.encode_value(any);
      tc = new TaggedComponent(TAG_CSI_SEC_MECH_LIST.value, b);
    } catch (InvalidTypeForEncoding e) {
      log.warn("Caught unexcepted exception while encoding CompoundSecMechList", e);
      throw new RuntimeException(e);
    }
    return tc;
  }
コード例 #5
0
 @Override
 public Any toAny() {
   ORB orb = ORB.init();
   if (numbers.length == 2) {
     complexDouble value = toCFType();
     Any any = orb.create_any();
     complexDoubleHelper.insert(any, value);
     return any;
   } else {
     Any retVal = orb.create_any();
     Any[] value = new Any[numbers.length];
     for (int i = 0; i < numbers.length; i++) {
       value[i] = orb.create_any();
       value[i].insert_double(numbers[i]);
     }
     AnySeqHelper.insert(retVal, value);
     return retVal;
   }
 }
コード例 #6
0
ファイル: CSIv2Util.java プロジェクト: jmcarrascal/jboss-as
  /**
   * Create a transport mechanism {@code TaggedComponent} to be stuffed into a {@code
   * CompoundSecMech}.
   *
   * <p>If no {@code TransportConfig} metadata is specified, or ssl port is negative, or the
   * specified metadata indicates that transport config is not supported, then a {@code
   * TAG_NULL_TAG} (empty) {@code TaggedComponent} will be returned.
   *
   * <p>Otherwise a {@code CSIIOP.TLS_SEC_TRANS}, tagged as {@code TAG_TLS_SEC_TRANS} will be
   * returned, indicating support for TLS/SSL as a CSIv2 transport mechanism.
   *
   * <p>Multiple {@code TransportAddress} may be included in the SSL info (host/port pairs), but we
   * only include one.
   *
   * @param tconfig the transport configuration metadata.
   * @param codec the {@code Codec} used to encode the transport configuration.
   * @param sslPort an {@code int} representing the SSL port.
   * @param orb a reference to the running {@code ORB}.
   * @return the constructed {@code TaggedComponent}.
   */
  public static TaggedComponent createTransportMech(
      TransportConfig tconfig, Codec codec, int sslPort, ORB orb) {

    TaggedComponent tc;

    // what we support and require as a target.
    int support = 0;
    int require = 0;

    if (tconfig != null) {
      require = createTargetRequires(tconfig);
      support = createTargetSupports(tconfig);
    }

    if (tconfig == null || support == 0 || sslPort < 0) {
      // no support for transport security.
      tc = new TaggedComponent(TAG_NULL_TAG.value, new byte[0]);
    } else {
      // my ip address.
      String host;
      try {
        host = InetAddress.getLocalHost().getHostAddress();
      } catch (java.net.UnknownHostException e) {
        host = "127.0.0.1";
      }

      // this will create only one transport address.
      TransportAddress[] taList = createTransportAddress(host, sslPort);
      TLS_SEC_TRANS tst = new TLS_SEC_TRANS((short) support, (short) require, taList);

      // The tricky part, we must encode TLS_SEC_TRANS into an octet sequence.
      try {
        Any any = orb.create_any();
        TLS_SEC_TRANSHelper.insert(any, tst);
        byte[] b = codec.encode_value(any);
        tc = new TaggedComponent(TAG_TLS_SEC_TRANS.value, b);
      } catch (InvalidTypeForEncoding e) {
        log.warn("Caught unexcepted exception while encoding TLS_SEC_TRANS", e);
        throw new RuntimeException(e);
      }
    }

    return tc;
  }
コード例 #7
0
ファイル: CSIv2Util.java プロジェクト: GeekkeeG/wildfly
  /**
   * Return a top-level {@code IOP::TaggedComponent} to be stuffed into an IOR, containing a
   * structure {@code SSLIOP::SSL}, tagged as {@code TAG_SSL_SEC_TRANS}.
   *
   * <p>Should be called with non-null metadata, in which case we probably don't want to include
   * security info in the IOR.
   *
   * @param metadata the metadata object that contains the SSL configuration info.
   * @param codec the {@code Codec} used to encode the SSL component.
   * @param sslPort an {@code int} representing the SSL port.
   * @param orb a reference to the running {@code ORB}.
   * @return a {@code TaggedComponent} representing the encoded SSL component.
   */
  public static TaggedComponent createSSLTaggedComponent(
      IORSecurityConfigMetaData metadata, Codec codec, int sslPort, ORB orb) {
    if (metadata == null) {
      JacORBLogger.ROOT_LOGGER.createSSLTaggedComponentWithNullMetaData();
      return null;
    }

    TaggedComponent tc;
    try {
      int supports = createTargetSupports(metadata.getTransportConfig());
      int requires = createTargetRequires(metadata.getTransportConfig());
      SSL ssl = new SSL((short) supports, (short) requires, (short) sslPort);
      Any any = orb.create_any();
      SSLHelper.insert(any, ssl);
      byte[] componentData = codec.encode_value(any);
      tc = new TaggedComponent(TAG_SSL_SEC_TRANS.value, componentData);
    } catch (InvalidTypeForEncoding e) {
      throw JacORBLogger.ROOT_LOGGER.unexpectedException(e);
    }
    return tc;
  }
コード例 #8
0
ファイル: CSIv2Util.java プロジェクト: jmcarrascal/jboss-as
  /**
   * Return a top-level {@code IOP::TaggedComponent} to be stuffed into an IOR, containing an
   * structure {@code SSLIOP::SSL}, tagged as {@code TAG_SSL_SEC_TRANS}.
   *
   * <p>Should be called with non-null metadata, in which case we probably don't want to include
   * security info in the IOR.
   *
   * @param metadata the metadata object that contains the SSL configuration info.
   * @param codec the {@code Codec} used to encode the SSL component.
   * @param sslPort an {@code int} representing the SSL port.
   * @param orb a reference to the running {@code ORB}.
   * @return a {@code TaggedComponent} representing the encoded SSL component.
   */
  public static TaggedComponent createSSLTaggedComponent(
      IORSecurityConfigMetadata metadata, Codec codec, int sslPort, ORB orb) {
    if (metadata == null) {
      log.debugf("createSSLTaggedComponent() called with null metadata");
      return null;
    }

    TaggedComponent tc;
    try {
      int supports = createTargetSupports(metadata.getTransportConfig());
      int requires = createTargetRequires(metadata.getTransportConfig());
      SSL ssl = new SSL((short) supports, (short) requires, (short) sslPort);
      Any any = orb.create_any();
      SSLHelper.insert(any, ssl);
      byte[] componentData = codec.encode_value(any);
      tc = new TaggedComponent(TAG_SSL_SEC_TRANS.value, componentData);
    } catch (InvalidTypeForEncoding e) {
      log.warn("Caught unexcepted exception while encoding SSL component", e);
      throw new RuntimeException(e);
    }
    return tc;
  }
コード例 #9
0
ファイル: CSIv2Util.java プロジェクト: GeekkeeG/wildfly
  /**
   * Create a transport mechanism {@code TaggedComponent} to be stuffed into a {@code
   * CompoundSecMech}.
   *
   * <p>If no {@code TransportConfig} metadata is specified, or ssl port is negative, or the
   * specified metadata indicates that transport config is not supported, then a {@code
   * TAG_NULL_TAG} (empty) {@code TaggedComponent} will be returned.
   *
   * <p>Otherwise a {@code CSIIOP.TLS_SEC_TRANS}, tagged as {@code TAG_TLS_SEC_TRANS} will be
   * returned, indicating support for TLS/SSL as a CSIv2 transport mechanism.
   *
   * <p>Multiple {@code TransportAddress} may be included in the SSL info (host/port pairs), but we
   * only include one.
   *
   * @param tconfig the transport configuration metadata.
   * @param codec the {@code Codec} used to encode the transport configuration.
   * @param sslPort an {@code int} representing the SSL port.
   * @param orb a reference to the running {@code ORB}.
   * @return the constructed {@code TaggedComponent}.
   */
  public static TaggedComponent createTransportMech(
      IORTransportConfigMetaData tconfig, Codec codec, int sslPort, ORB orb) {

    TaggedComponent tc;

    // what we support and require as a target.
    int support = 0;
    int require = 0;

    if (tconfig != null) {
      require = createTargetRequires(tconfig);
      support = createTargetSupports(tconfig);
    }

    if (tconfig == null || support == 0 || sslPort < 0) {
      // no support for transport security.
      tc = new TaggedComponent(TAG_NULL_TAG.value, new byte[0]);
    } else {
      // my ip address.
      String host = CorbaORBService.getORBProperty(JacORBSubsystemConstants.ORB_ADDRESS);

      // this will create only one transport address.
      TransportAddress[] taList = createTransportAddress(host, sslPort);
      TLS_SEC_TRANS tst = new TLS_SEC_TRANS((short) support, (short) require, taList);

      // The tricky part, we must encode TLS_SEC_TRANS into an octet sequence.
      try {
        Any any = orb.create_any();
        TLS_SEC_TRANSHelper.insert(any, tst);
        byte[] b = codec.encode_value(any);
        tc = new TaggedComponent(TAG_TLS_SEC_TRANS.value, b);
      } catch (InvalidTypeForEncoding e) {
        throw JacORBLogger.ROOT_LOGGER.unexpectedException(e);
      }
    }

    return tc;
  }
コード例 #10
0
  public void receive_request(ServerRequestInfo ri) {
    try {
      //
      // Test: get operation name
      //
      String op = ri.operation();

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

      //
      // Test: Examine arguments
      //
      testArgs(ri, false);

      // 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();
        if (op.equals("userexception")) {
          TEST(exceptions.length == 1);
          TEST(exceptions[0].equal(userHelper.type()));
        } else {
          TEST(exceptions.length == 0);
        }
      } catch (NO_RESOURCES ex) {
        // Expected (if servant is DSI)
      }

      //
      // 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
      }

      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);
        } catch (BAD_PARAM ex) {
          TEST(false);
        }

        //
        // Test: add_reply_service_context
        //
        ReplyContext context = new ReplyContext();
        context.data = "reply2";
        context.val = 102;
        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_2_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: replace context added in
        // receive_request_service_context
        //
        context.data = "reply4";
        context.val = 114;
        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, true);
        } 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: object id is correct
      //
      byte[] oid = ri.object_id();
      TEST(
          (oid.length == 4 && (new String(oid)).equals("test"))
              || (oid.length == 7 && (new String(oid)).equals("testDSI")));

      //
      // Test: adapter id is correct (this is a tough one to test)
      //
      byte[] adapterId = ri.adapter_id();
      TEST(adapterId.length != 0);

      //
      // Test: servant most derived interface is correct
      //
      String mdi = ri.target_most_derived_interface();
      TEST(mdi.equals("IDL:TestInterface:1.0"));

      //
      // Test: server id is correct
      //
      String serverId = ri.server_id();
      TEST(serverId.equals(""));

      //
      // Test: orb id is correct
      //
      String orbId = ri.orb_id();
      TEST(orbId.equals("myORB"));

      //
      // Test: adapter name is correct
      //
      String[] adapterName = ri.adapter_name();
      TEST(adapterName.length == 1 && adapterName[0].equals("persistent"));

      //
      // Test: servant is a is correct
      //
      TEST(ri.target_is_a("IDL:TestInterface:1.0"));

      //
      // 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;
    }
  }
コード例 #11
0
  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;
    }
  }
コード例 #12
0
  private void testServiceContext(String op, ServerRequestInfo ri, boolean addContext) {
    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);
      } catch (BAD_PARAM ex) {
        TEST(false);
      }

      //
      // Test: get_reply_service_context
      //
      org.omg.IOP.ServiceContext sc = null;
      try {
        sc = ri.get_reply_service_context(REPLY_CONTEXT_4_ID.value);
      } catch (BAD_INV_ORDER ex) {
        TEST(false);
      }
      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, ReplyContextHelper.type());
      } catch (org.omg.IOP.CodecPackage.FormatMismatch ex) {
        TEST(false);
      } catch (org.omg.IOP.CodecPackage.TypeMismatch ex) {
        TEST(false);
      }
      ReplyContext context = ReplyContextHelper.extract(any);
      TEST(context.data.equals("reply4"));
      TEST(context.val == 114);

      if (addContext) {
        //
        // Test: add_reply_service_context
        //
        context.data = "reply3";
        context.val = 103;
        any = orb_.create_any();
        ReplyContextHelper.insert(any, context);
        try {
          data = cdrCodec_.encode_value(any);
        } catch (org.omg.IOP.CodecPackage.InvalidTypeForEncoding ex) {
          TEST(false);
        }

        sc.context_id = REPLY_CONTEXT_3_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: replace context added in receive_request
        //
        context.data = "reply4";
        context.val = 124;
        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, true);
        } catch (BAD_INV_ORDER ex) {
          TEST(false);
        }
      }
    } else {
      try {
        org.omg.IOP.ServiceContext sc = ri.get_request_service_context(REQUEST_CONTEXT_ID.value);
        TEST(false);
      } catch (BAD_PARAM ex) {
        // Expected
      }
      try {
        org.omg.IOP.ServiceContext sc = ri.get_reply_service_context(REPLY_CONTEXT_1_ID.value);
        TEST(false);
      } catch (BAD_PARAM ex) {
        // Expected
      }
    }
  }