diff --git a/testify/src/main/java/testify/annotation/ClassSource.java b/testify/src/main/java/testify/annotation/ClassSource.java index ac2966325..261aa02c1 100644 --- a/testify/src/main/java/testify/annotation/ClassSource.java +++ b/testify/src/main/java/testify/annotation/ClassSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 IBM Corporation and others. + * Copyright 2024 IBM Corporation and others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ @Documented @ArgumentsSource(ClassSource.Provider.class) public @interface ClassSource { - Class[] value(); + Class[] value(); class Provider implements ArgumentsProvider, AnnotationConsumer { private static final String ANNO_NAME = '@' + ClassSource.class.getSimpleName(); Class[] classes; diff --git a/yoko-core/src/main/java/org/apache/yoko/orb/OB/GIOPConnection.java b/yoko-core/src/main/java/org/apache/yoko/orb/OB/GIOPConnection.java index e45a7f72b..3e0acc311 100644 --- a/yoko-core/src/main/java/org/apache/yoko/orb/OB/GIOPConnection.java +++ b/yoko-core/src/main/java/org/apache/yoko/orb/OB/GIOPConnection.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 IBM Corporation and others. + * Copyright 2024 IBM Corporation and others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -549,7 +549,7 @@ private synchronized void processLocateReply(GIOPIncomingMessage msg) { try { IOR ior = IORHelper.read(in); down.setLocationForward(ior, false); - if (REQ_OUT_LOG.isLoggable(FINE)) REQ_OUT_LOG.fine("Locate request forwarded to " + IORDump.PrintObjref(orbInstance_.getORB(), ior)); + if (REQ_OUT_LOG.isLoggable(FINE)) REQ_OUT_LOG.fine("Locate request forwarded to " + IORDump.describeIor(orbInstance_.getORB(), ior)); } catch (SystemException ex) { warned(REQ_OUT_LOG, ex, "An error occurred while reading a locate reply, possibly indicating " @@ -563,7 +563,7 @@ private synchronized void processLocateReply(GIOPIncomingMessage msg) { try { IOR ior = IORHelper.read(in); down.setLocationForward(ior, true); - if (REQ_OUT_LOG.isLoggable(FINE)) REQ_OUT_LOG.fine("Locate request forwarded to " + IORDump.PrintObjref(orbInstance_.getORB(), ior)); + if (REQ_OUT_LOG.isLoggable(FINE)) REQ_OUT_LOG.fine("Locate request forwarded to " + IORDump.describeIor(orbInstance_.getORB(), ior)); } catch (SystemException ex) { warned(REQ_OUT_LOG, ex,"An error occurred while reading a locate reply, possibly indicating " + "an interoperability problem. You may need to set the LocateRequestPolicy to false."); @@ -885,7 +885,7 @@ public void upcallForward(Upcall upcall, IOR ior, boolean perm, ServiceContexts ReplyStatusType_1_2 status = perm ? ReplyStatusType_1_2.LOCATION_FORWARD_PERM : ReplyStatusType_1_2.LOCATION_FORWARD; try { outgoing.writeReplyHeader(reqId, status, contexts); - if (REQ_IN_LOG.isLoggable(FINE)) REQ_IN_LOG.fine("Sending forward reply to " + IORDump.PrintObjref(orbInstance_.getORB(), ior)); + if (REQ_IN_LOG.isLoggable(FINE)) REQ_IN_LOG.fine("Sending forward reply to " + IORDump.describeIor(orbInstance_.getORB(), ior)); IORHelper.write(out, ior); } catch (SystemException ex) { // Nothing may go wrong here, otherwise we might have a diff --git a/yoko-core/src/main/java/org/apache/yoko/orb/OB/IORDump.java b/yoko-core/src/main/java/org/apache/yoko/orb/OB/IORDump.java index 09663ee0f..fed19e220 100644 --- a/yoko-core/src/main/java/org/apache/yoko/orb/OB/IORDump.java +++ b/yoko-core/src/main/java/org/apache/yoko/orb/OB/IORDump.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 IBM Corporation and others. + * Copyright 2024 IBM Corporation and others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,21 @@ */ package org.apache.yoko.orb.OB; +import static org.apache.yoko.util.Hex.formatHexPara; + +import java.io.IOError; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Optional; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Stream; + import org.apache.yoko.orb.CORBA.InputStream; import org.apache.yoko.orb.OCI.ConFactory; import org.apache.yoko.orb.OCI.ConFactoryRegistry; @@ -25,32 +40,30 @@ import org.apache.yoko.util.HexConverter; import org.omg.CORBA.BAD_PARAM; import org.omg.CORBA.ORB; -import org.omg.CORBA.ORBPackage.InvalidName; import org.omg.CORBA.UserException; +import org.omg.CORBA.ORBPackage.InvalidName; import org.omg.IOP.IOR; import org.omg.IOP.IORHelper; import org.omg.IOP.TAG_MULTIPLE_COMPONENTS; import org.omg.IOP.TaggedComponent; import org.omg.IOP.TaggedComponentHelper; - -import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Properties; - -import static org.apache.yoko.util.Hex.formatHexPara; +import org.omg.IOP.TaggedProfile; public class IORDump { - public static String PrintObjref(ORB orb, IOR ior) { - StringBuilder sb = new StringBuilder(); - PrintObjref(orb, sb, ior); - return sb.toString(); + public static String describeIor(ORB orb, IOR ior) { + try { + return describeIor(new StringBuilder(), orb, ior).toString(); + } catch (Throwable t) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + pw.println(t); + t.printStackTrace(pw); + return sw.toString(); + } } - static public void PrintObjref(ORB orb, StringBuilder sb, IOR ior) { + private static StringBuilder describeIor(StringBuilder sb, ORB orb, IOR ior) { sb.append("type_id: ").append(ior.type_id).append('\n'); ConFactoryRegistry conFactoryRegistry = null; @@ -60,81 +73,71 @@ static public void PrintObjref(ORB orb, StringBuilder sb, IOR ior) { } catch (InvalidName ex) { throw Assert.fail(ex); } + ConFactory[] factories = conFactoryRegistry.get_factories(); - for (int i = 0; i < ior.profiles.length; i++) { - sb.append("Profile #" + (i + 1) + ": "); - if (ior.profiles[i].tag == TAG_MULTIPLE_COMPONENTS.value) { - sb.append("multiple components"); + int count = 1; + for (TaggedProfile p: ior.profiles) { + describeProfile(sb, factories, p, count++); + } + return sb; + } - InputStream in = new InputStream(ior.profiles[i].profile_data); - in._OB_readEndian(); + private static void describeProfile(StringBuilder sb, ConFactory[] factories, TaggedProfile p, int index) { + sb.append("Profile #").append(index).append(": "); + if (p.tag == TAG_MULTIPLE_COMPONENTS.value) { + sb.append("multiple components"); - int cnt = in.read_ulong(); - if (cnt == 0) sb.append('\n'); - else { - for (int j = 0; j < cnt; j++) { - TaggedComponent comp = TaggedComponentHelper.read(in); - IORUtil.describe_component(comp, sb); - } - } - } else { - int j; - for (j = 0; j < factories.length; j++) { - if (factories[j].tag() == ior.profiles[i].tag) { - sb.append(factories[j].id()).append('\n'); - String desc = factories[j].describe_profile(ior.profiles[i]); - sb.append(desc); - break; - } - } + InputStream in = new InputStream(p.profile_data); + in._OB_readEndian(); - if (j >= factories.length) { - sb.append("unknown profile tag ").append(ior.profiles[i].tag).append('\n'); - sb.append("profile_data: (").append(ior.profiles[i].profile_data.length ).append(")\n"); - formatHexPara(ior.profiles[i].profile_data, sb); + int cnt = in.read_ulong(); + if (cnt == 0) { + sb.append('\n'); + } else { + for (int j = 0; j < cnt; j++) { + TaggedComponent comp = TaggedComponentHelper.read(in); + IORUtil.describe_component(comp, sb); } } + } else { + Optional factory = Arrays.stream(factories) + .filter(f -> f.tag() == p.tag) + .findAny(); + if (factory.isPresent()) { + ConFactory f = factory.get(); + sb.append(f.id()).append('\n'); + String desc = f.describe_profile(p); + sb.append(desc); + } else { + sb.append("unknown profile tag ").append(p.tag).append('\n'); + sb.append("profile_data: (").append(p.profile_data.length ).append(")\n"); + formatHexPara(p.profile_data, sb); + } } } - static public void DumpIOR(ORB orb, String ref, boolean hasEndian) { - StringBuilder sb = new StringBuilder(); - DumpIOR(orb, ref, hasEndian, sb); - PrintWriter pw = new PrintWriter(System.out); - pw.write(sb.toString()); - pw.flush(); - } - - static public String DumpIORToString(ORB orb, String ref, boolean hasEndian) { - StringBuilder sb = new StringBuilder(); - DumpIOR(orb, ref, hasEndian, sb); - return sb.toString(); - } - - static public void DumpIOR(ORB orb, String ref, boolean hasEndian, StringBuilder sb) { - if (!ref.startsWith("IOR:")) { - sb.append("IOR is invalid\n"); - return; - } - + private static String describeIorString(ORB orb, String ref, boolean describeByteOrder) { + if (!ref.startsWith("IOR:")) return "IOR is invalid\n"; byte[] data = HexConverter.asciiToOctets(ref, 4); InputStream in = new InputStream(data); - boolean endian = in.read_boolean(); - in._OB_swap(endian); - - IOR ior = IORHelper.read(in); - - sb.append("byteorder: "); - if (hasEndian) sb.append((endian ? "little" : "big") + " endian\n"); - else sb.append("n/a\n"); - - PrintObjref(orb, sb, ior); + StringBuilder sb = new StringBuilder(); + // If this IOR is not encoded to string by this VM, the byte order might be of interest + if (describeByteOrder) { + sb.append("byteorder: "); + boolean endian = in.read_boolean(); + in._OB_swap(endian); + sb.append((endian ? "little" : "big") + " endian\n"); + } else { + in._OB_readEndian(); + } + describeIor(sb, orb, IORHelper.read(in)); + return sb.toString(); } - static void usage() { + private static void usage() { System.err.println("Usage:"); System.err.println("org.apache.yoko.orb.OB.IORDump [options] [-f FILE ... | IOR ...]\n" + "\n" @@ -145,23 +148,27 @@ static void usage() { + " command line."); } - public static int run(ORB orb, String[] args) throws UserException { + private static int run(ORB orb, String[] args) throws UserException { // Get options boolean files = false; int i; for (i = 0; i < args.length && args[i].charAt(0) == '-'; i++) { - if (args[i].equals("--help") || args[i].equals("-h")) { - usage(); - return 0; - } else if (args[i].equals("--version") || args[i].equals("-v")) { - System.out.println("Yoko " + Version.getVersion()); - return 0; - } else if (args[i].equals("-f")) { - files = true; - } else { - System.err.println("IORDump: unknown option `" + args[i] + "'"); - usage(); - return 1; + switch (args[i]) { + case "--help" : + case "-h" : + usage(); + return 0; + case "--version" : + case "-v" : + System.out.println("Yoko " + Version.getVersion()); + return 0; + case "-f" : + files = true; + break; + default : + System.err.println("IORDump: unknown option `" + args[i] + "'"); + usage(); + return 1; } } @@ -172,80 +179,42 @@ public static int run(ORB orb, String[] args) throws UserException { return 1; } - if (!files) { - if (!args[i].startsWith("IOR:") && !args[i].startsWith("corbaloc:") - && !args[i].startsWith("corbaname:") - && !args[i].startsWith("file:") - && !args[i].startsWith("relfile:")) { - System.err.println("[No valid IOR found on the command " - + "line, assuming -f]"); - files = true; - } - } + AtomicInteger count = new AtomicInteger(1); + Stream remainingArgs = Arrays.stream(args).skip(i); + if (files) remainingArgs.map(Paths::get).flatMap(IORDump::lines).forEach(line -> printIorString(orb, line, count.getAndIncrement())); + else remainingArgs.forEach(arg -> printIorString(orb, arg, count.getAndIncrement())); - if (!files) { - // Dump all IORs given as arguments - int count = 0; - for (; i < args.length; i++) { - if (count > 0) - System.out.println(); - System.out.println("IOR #" + (++count) + ':'); + return 0; + } - try { - // The byte order can only be preserved for IOR: URLs - if (args[i].startsWith("IOR:")) - DumpIOR(orb, args[i], true); - else { - // Let string_to_object do the dirty work - org.omg.CORBA.Object obj = orb.string_to_object(args[i]); - String s = orb.object_to_string(obj); - DumpIOR(orb, s, false); - } - } catch (BAD_PARAM ex) { - System.err.println("IOR is invalid"); - } - } - } else { - // Dump all IORs from the specified files - int count = 0; - for (; i < args.length; i++) { - try { - FileReader fin = new FileReader(args[i]); - BufferedReader in = new BufferedReader(fin); - String line; - while ((line = in.readLine()) != null) { - if (line.length() > 0) { - if (count > 0) - System.out.println(); - System.out.println("IOR #" + (++count) + ':'); - // The byte order can only be preserved for - // IOR: URLs - if (line.startsWith("IOR:")) - DumpIOR(orb, line, true); - else { - // Let string_to_object do the dirty work - org.omg.CORBA.Object obj = orb.string_to_object(line); - String s = orb.object_to_string(obj); - DumpIOR(orb, s, false); - } - } - } - } catch (FileNotFoundException ex) { - System.err.println("IORDump: can't open `" + args[i] - + "': " + ex); - return 1; - } catch (IOException ex) { - System.err.println("IORDump: can't read `" + args[i] - + "': " + ex); - return 1; - } - } + static Stream lines(Path p) { + try { + return Files.lines(p); + } catch (IOException e) { + System.err.println("IORDump: can't open '" + p + "': " + e); + throw new IOError(e); } + } - return 0; + private static void printIorString(ORB orb, String ior, int index) { + if (index > 1) System.out.println(); + System.out.println("IOR #" + index + ':'); + try { + // The byte order can only be preserved for IOR: URLs + if (ior.startsWith("IOR:")) + System.out.println(describeIorString(orb, ior, true)); + else { + // Let string_to_object do the dirty work + org.omg.CORBA.Object obj = orb.string_to_object(ior); + String s = orb.object_to_string(obj); + System.out.println(describeIorString(orb, s, false)); + } + } catch (BAD_PARAM ex) { + System.err.println("IOR is invalid: " + ior); + } } - public static void main(String[] args) { + public static void main(String... args) { Properties props = new Properties(); props.putAll(System.getProperties()); props.put("org.omg.CORBA.ORBClass", "org.apache.yoko.orb.CORBA.ORB"); diff --git a/yoko-core/src/main/java/org/apache/yoko/orb/OB/IORUtil.java b/yoko-core/src/main/java/org/apache/yoko/orb/OB/IORUtil.java index e958fea1b..3d809a58e 100644 --- a/yoko-core/src/main/java/org/apache/yoko/orb/OB/IORUtil.java +++ b/yoko-core/src/main/java/org/apache/yoko/orb/OB/IORUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 IBM Corporation and others. + * Copyright 2024 IBM Corporation and others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,9 +76,17 @@ import org.omg.IOP.TAG_SSL_SEC_TRANS; import org.omg.IOP.TaggedComponent; +import static java.lang.Integer.toHexString; import static org.apache.yoko.util.Hex.formatHexLine; import static org.apache.yoko.util.Hex.formatHexPara; +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.function.BiConsumer; + public final class IORUtil { private static void describeCSISecMechList(TaggedComponent component, StringBuilder sb) { InputStream in = new InputStream(component.component_data); @@ -126,78 +134,37 @@ private static void describeCSISecMechList(TaggedComponent component, StringBuil } } } - - - private static void describeTransportFlags(int flag, StringBuilder sb) { - if ((NoProtection.value & flag) != 0) { - sb.append("NoProtection "); - } - if ((Integrity.value & flag) != 0) { - sb.append("Integrity "); - } - if ((Confidentiality.value & flag) != 0) { - sb.append("Confidentiality "); - } - if ((DetectReplay.value & flag) != 0) { - sb.append("DetectReplay "); - } - if ((DetectMisordering.value & flag) != 0) { - sb.append("DetectMisordering "); - } - if ((EstablishTrustInTarget.value & flag) != 0) { - sb.append("EstablishTrustInTarget "); - } - if ((EstablishTrustInClient.value & flag) != 0) { - sb.append("EstablishTrustInClient "); - } - if ((NoDelegation.value & flag) != 0) { - sb.append("NoDelegation "); - } - if ((SimpleDelegation.value & flag) != 0) { - sb.append("SimpleDelegation "); - } - if ((CompositeDelegation.value & flag) != 0) { - sb.append("CompositeDelegation "); - } - if ((IdentityAssertion.value & flag) != 0) { - sb.append("IdentityAssertion "); - } - if ((DelegationByClient.value & flag) != 0) { - sb.append("DelegationByClient "); - } - + private static void describeTransportFlags(int flag, StringBuilder sb) { + if ((NoProtection.value & flag) != 0) sb.append("NoProtection "); + if ((Integrity.value & flag) != 0) sb.append("Integrity "); + if ((Confidentiality.value & flag) != 0) sb.append("Confidentiality "); + if ((DetectReplay.value & flag) != 0) sb.append("DetectReplay "); + if ((DetectMisordering.value & flag) != 0) sb.append("DetectMisordering "); + if ((EstablishTrustInTarget.value & flag) != 0) sb.append("EstablishTrustInTarget "); + if ((EstablishTrustInClient.value & flag) != 0) sb.append("EstablishTrustInClient "); + if ((NoDelegation.value & flag) != 0) sb.append("NoDelegation "); + if ((SimpleDelegation.value & flag) != 0) sb.append("SimpleDelegation "); + if ((CompositeDelegation.value & flag) != 0) sb.append("CompositeDelegation "); + if ((IdentityAssertion.value & flag) != 0) sb.append("IdentityAssertion "); + if ((DelegationByClient.value & flag) != 0) sb.append("DelegationByClient "); } - - + private static void describeIdentityToken(int flag, StringBuilder sb) { - if (flag == ITTAbsent.value) { sb.append("Absent"); return; } - - - if ((ITTAnonymous.value & flag) != 0) { - sb.append("Anonymous "); - } - if ((ITTPrincipalName.value & flag) != 0) { - sb.append("PrincipalName "); - } - if ((ITTX509CertChain.value & flag) != 0) { - sb.append("X509CertChain "); - } - if ((ITTDistinguishedName.value & flag) != 0) { - sb.append("DistinguishedName "); - } - + if ((ITTAnonymous.value & flag) != 0) sb.append("Anonymous "); + if ((ITTPrincipalName.value & flag) != 0) sb.append("PrincipalName "); + if ((ITTX509CertChain.value & flag) != 0) sb.append("X509CertChain "); + if ((ITTDistinguishedName.value & flag) != 0) sb.append("DistinguishedName "); } - + private static void describeTLS_SEC_TRANS(TaggedComponent component, StringBuilder sb) { InputStream in = new InputStream(component.component_data); in._OB_readEndian(); TLS_SEC_TRANS info = TLS_SEC_TRANSHelper.read(in); - sb.append(" TLS_SEC_TRANS component:\n"); sb.append(" target_supports: "); describeTransportFlags(info.target_supports, sb); sb.append("\n"); sb.append(" target_requires: "); describeTransportFlags(info.target_requires, sb); sb.append("\n"); @@ -206,14 +173,12 @@ private static void describeTLS_SEC_TRANS(TaggedComponent component, StringBuild sb.append(" host_name: ").append(address.host_name).append("\n"); sb.append(" port: ").append(address.port).append("\n"); } - } - + private static void describeSECIOP_SEC_TRANS(TaggedComponent component, StringBuilder sb) { InputStream in = new InputStream(component.component_data); in._OB_readEndian(); SECIOP_SEC_TRANS info = SECIOP_SEC_TRANSHelper.read(in); - sb.append(" SECIOP_SEC_TRANS component:\n"); sb.append(" target_supports: "); describeTransportFlags(info.target_supports, sb); sb.append("\n"); sb.append(" target_requires: "); describeTransportFlags(info.target_requires, sb); sb.append("\n"); @@ -224,50 +189,31 @@ private static void describeSECIOP_SEC_TRANS(TaggedComponent component, StringBu sb.append(" host_name: ").append(address.host_name).append("\n"); sb.append(" port: ").append(address.port).append("\n"); } - } - - - + private static void describeCodeSets(TaggedComponent component, StringBuilder sb) { InputStream in = new InputStream(component.component_data); in._OB_readEndian(); - CodeSetComponentInfo info = CodeSetComponentInfoHelper - .read(in); - + CodeSetComponentInfo info = CodeSetComponentInfoHelper.read(in); CodeSetInfo charInfo; - // - // Print char codeset information - // sb.append("Native char codeset: \n"); charInfo = CodeSetInfo.forRegistryId(info.ForCharData.native_code_set); - if (charInfo != null) { - sb.append(" \""); - sb.append(charInfo.description); - sb.append("\"\n"); - } else if (info.ForCharData.native_code_set == 0) + if (charInfo != null) + sb.append(" \"").append(charInfo.description).append("\"\n"); + else if (info.ForCharData.native_code_set == 0) sb.append(" [No codeset information]\n"); - else { - sb.append(" [Unknown codeset id: "); - sb.append(info.ForCharData.native_code_set); - sb.append("]\n"); - } + else + sb.append(" [Unknown codeset id: ").append(info.ForCharData.native_code_set).append("]\n"); for (int i = 0; i < info.ForCharData.conversion_code_sets.length; i++) { + charInfo = CodeSetInfo.forRegistryId(info.ForCharData.conversion_code_sets[i]); if (i == 0) sb.append("Char conversion codesets:\n"); - - charInfo = CodeSetInfo.forRegistryId(info.ForCharData.conversion_code_sets[i]); - if (charInfo != null) { - sb.append(" \""); - sb.append(charInfo.description); - sb.append("\"\n"); - } else { - sb.append(" [Unknown codeset id: "); - sb.append(info.ForCharData.conversion_code_sets[i]); - sb.append("]\n"); - } + if (charInfo != null) + sb.append(" \"").append(charInfo.description).append("\"\n"); + else + sb.append(" [Unknown codeset id: ").append(info.ForCharData.conversion_code_sets[i]).append("]\n"); } // @@ -275,17 +221,12 @@ private static void describeCodeSets(TaggedComponent component, StringBuilder sb // sb.append("Native wchar codeset: \n"); charInfo = CodeSetInfo.forRegistryId(info.ForWcharData.native_code_set); - if (charInfo != null) { - sb.append(" \""); - sb.append(charInfo.description); - sb.append("\"\n"); - } else if (info.ForWcharData.native_code_set == 0) + if (charInfo != null) + sb.append(" \"").append(charInfo.description).append("\"\n"); + else if (info.ForWcharData.native_code_set == 0) sb.append(" [No codeset information]\n"); - else { - sb.append(" [Unknown codeset id: "); - sb.append(info.ForWcharData.native_code_set); - sb.append("]\n"); - } + else + sb.append(" [Unknown codeset id: ").append(info.ForWcharData.native_code_set).append("]\n"); for (int i = 0; i < info.ForWcharData.conversion_code_sets.length; i++) { if (i == 0) @@ -293,193 +234,125 @@ private static void describeCodeSets(TaggedComponent component, StringBuilder sb charInfo = CodeSetInfo .forRegistryId(info.ForWcharData.conversion_code_sets[i]); - if (charInfo != null) { - sb.append(" \""); - sb.append(charInfo.description); - sb.append("\"\n"); - } else { - sb.append(" [Unknown codeset id: "); - sb.append(info.ForWcharData.conversion_code_sets[i]); - sb.append("]\n"); - } + if (charInfo != null) + sb.append(" \"").append(charInfo.description).append("\"\n"); + else + sb.append(" [Unknown codeset id: ").append(info.ForWcharData.conversion_code_sets[i]).append("]\n"); } - } - private static void describeGenericComponent( - TaggedComponent component, String name, StringBuilder sb) { - sb.append("Component: "); - sb.append(name); - sb.append('\n'); - sb.append("Component data: ("); - sb.append(component.component_data.length); - sb.append(")\n"); - formatHexPara(component.component_data, 0, - component.component_data.length, sb); + private static void describeGenericComponent(TaggedComponent component, String name, StringBuilder sb) { + sb.append("Component: ").append(name).append('\n'); + sb.append("Component data: (").append(component.component_data.length).append(")\n"); + formatHexPara(component.component_data, 0, component.component_data.length, sb).append('\n'); } - // - // Produce a human-friendly description of an IOR tagged component - // - public static void describe_component(TaggedComponent component, StringBuilder sb) { - - switch (component.tag) { - case TAG_ORB_TYPE.value: { - InputStream in = new InputStream(component.component_data); - in._OB_readEndian(); - int id = in.read_ulong(); - sb.append("Component: TAG_ORB_TYPE = "); - sb.append("0x"); - sb.append(Integer.toHexString(id)); - sb.append('\n'); - break; - } - - case TAG_CODE_SETS.value: - describeCodeSets(component, sb); - break; - - case TAG_POLICIES.value: - describeGenericComponent(component, "TAG_POLICIES", sb); - break; - - case TAG_ALTERNATE_IIOP_ADDRESS.value: { - InputStream in = new InputStream(component.component_data); - in._OB_readEndian(); - String host = in.read_string(); - short port = in.read_ushort(); - sb.append("Alternate IIOP address:\n"); - sb.append(" host: "); - sb.append(host); - sb.append('\n'); - sb.append(" port: "); - sb.append(port < 0 ? 0xffff + (int) port + 1 : port); - sb.append('\n'); - break; - } - - case TAG_ASSOCIATION_OPTIONS.value: - describeGenericComponent(component, - "TAG_ASSOCIATION_OPTIONS", sb); - break; - - case TAG_SEC_NAME.value: - describeGenericComponent(component, "TAG_SEC_NAME", sb); - break; - - case TAG_SPKM_1_SEC_MECH.value: - describeGenericComponent(component, "TAG_SPKM_1_SEC_MECH", sb); - break; - - case TAG_SPKM_2_SEC_MECH.value: - describeGenericComponent(component, "TAG_SPKM_2_SEC_MECH", sb); - break; - - case TAG_KerberosV5_SEC_MECH.value: - describeGenericComponent(component, - "TAG_KerberosV5_SEC_MECH", sb); - break; - - case TAG_CSI_ECMA_Secret_SEC_MECH.value: - describeGenericComponent(component, - "TAG_CSI_ECMA_Secret_SEC_MECH", sb); - break; - - case TAG_CSI_ECMA_Hybrid_SEC_MECH.value: - describeGenericComponent(component, - "TAG_CSI_ECMA_Hybrid_SEC_MECH", sb); - break; - - case TAG_CSI_SEC_MECH_LIST.value: - describeCSISecMechList(component, sb); - break; - - case TAG_OTS_POLICY.value: - describeGenericComponent(component, - "TAG_OTS_POLICY", sb); - break; - - case TAG_INV_POLICY.value: - describeGenericComponent(component, - "TAG_INV_POLICY", sb); - break; - - case TAG_SECIOP_SEC_TRANS.value: - describeGenericComponent(component, - "TAG_SECIOP_SEC_TRANS", sb); - break; - - case TAG_NULL_TAG.value: - describeGenericComponent(component, - "TAG_NULL_TAG", sb); - break; - - case TAG_TLS_SEC_TRANS.value: - describeGenericComponent(component, - "TAG_TLS_SEC_TRANS", sb); - break; + private static void describeJavaCodebase(TaggedComponent component, StringBuilder sb) { + InputStream in = new InputStream(component.component_data); + in._OB_readEndian(); + String codebase = in.read_string(); + sb.append("Component: TAG_JAVA_CODEBASE = '").append(codebase).append("'\n"); + } - case TAG_SSL_SEC_TRANS.value: - describeGenericComponent(component, "TAG_SSL_SEC_TRANS", sb); - break; + private static void describeAlternateIiop(TaggedComponent component, StringBuilder sb) { + InputStream in = new InputStream(component.component_data); + in._OB_readEndian(); + String host = in.read_string(); + int port = 0xFFFF & in.read_ushort(); + sb.append("Alternate IIOP address:\n"); + sb.append(" host: ").append(host).append('\n'); + sb.append(" port: ").append(port).append('\n'); + } - case TAG_CSI_ECMA_Public_SEC_MECH.value: - describeGenericComponent(component, - "TAG_CSI_ECMA_Public_SEC_MECH", sb); - break; + private static void describeOrbType(TaggedComponent component, StringBuilder sb) { + InputStream in = new InputStream(component.component_data); + in._OB_readEndian(); + sb.append("Component: TAG_ORB_TYPE = 0x").append(toHexString(in.read_ulong())).append('\n'); + } - case TAG_GENERIC_SEC_MECH.value: - describeGenericComponent(component, "TAG_GENERIC_SEC_MECH", sb); - break; + private static void describeUnknown(TaggedComponent component, StringBuilder sb) { + describeGenericComponent(component, String.format("unknown (tag = 0x%x)", component.tag), sb); + } - case TAG_JAVA_CODEBASE.value: { - InputStream in = new InputStream(component.component_data); - in._OB_readEndian(); - String codebase = in.read_string(); - sb.append("Component: TAG_JAVA_CODEBASE = `"); - sb.append(codebase); - sb.append("'\n"); - break; + private enum TagComp { + _TAG_POLICIES, + _TAG_ASSOCIATION_OPTIONS, + _TAG_SEC_NAME, + _TAG_SPKM_1_SEC_MECH, + _TAG_SPKM_2_SEC_MECH, + _TAG_KerberosV5_SEC_MECH, + _TAG_CSI_ECMA_Secret_SEC_MECH, + _TAG_CSI_ECMA_Hybrid_SEC_MECH, + _TAG_OTS_POLICY, + _TAG_INV_POLICY, + _TAG_SECIOP_SEC_TRANS, + _TAG_NULL_TAG, + _TAG_TLS_SEC_TRANS, + _TAG_SSL_SEC_TRANS, + _TAG_CSI_ECMA_Public_SEC_MECH, + _TAG_GENERIC_SEC_MECH, + _TAG_COMPLETE_OBJECT_KEY, + _TAG_ENDPOINT_ID_POSITION, + _TAG_LOCATION_POLICY, + _TAG_DCE_STRING_BINDING, + _TAG_DCE_BINDING_NAME, + _TAG_DCE_NO_PIPES, + _TAG_DCE_SEC_MECH, + _TAG_CODE_SETS(IORUtil::describeCodeSets), + _TAG_ORB_TYPE(IORUtil::describeOrbType), + _TAG_ALTERNATE_IIOP_ADDRESS(IORUtil::describeAlternateIiop), + _TAG_CSI_SEC_MECH_LIST(IORUtil::describeCSISecMechList), + _TAG_JAVA_CODEBASE(IORUtil::describeJavaCodebase), + _UNKNOWN(IORUtil::describeUnknown); + final BiConsumer describer; + TagComp(BiConsumer describer) { this.describer = describer; } + TagComp() { this(null); } + void describe(TaggedComponent component, StringBuilder sb) { + if (null == describer) describeGenericComponent(component, this.toString(), sb); + else describer.accept(component, sb); } - - case TAG_COMPLETE_OBJECT_KEY.value: - describeGenericComponent(component, - "TAG_COMPLETE_OBJECT_KEY", sb); - break; - - case TAG_ENDPOINT_ID_POSITION.value: - describeGenericComponent(component, - "TAG_ENDPOINT_ID_POSITION", sb); - break; - - case TAG_LOCATION_POLICY.value: - describeGenericComponent(component, "TAG_LOCATION_POLICY", sb); - break; - - case TAG_DCE_STRING_BINDING.value: - describeGenericComponent(component, - "TAG_DCE_STRING_BINDING", sb); - break; - - case TAG_DCE_BINDING_NAME.value: - describeGenericComponent(component, "TAG_DCE_BINDING_NAME", sb); - break; - - case TAG_DCE_NO_PIPES.value: - describeGenericComponent(component, "TAG_DCE_NO_PIPES", sb); - break; - - case TAG_DCE_SEC_MECH.value: - describeGenericComponent(component, "TAG_DCE_SEC_MECH", sb); - break; - - default: { - String name = "unknown (tag = "; - name += component.tag; - name += ")"; - describeGenericComponent(component, name, sb); - break; + @Override + public String toString() { + return super.toString().substring(1); } + + static TagComp findById(int id) { + switch (id) { + case TAG_POLICIES.value: return _TAG_POLICIES; + case TAG_ASSOCIATION_OPTIONS.value: return _TAG_ASSOCIATION_OPTIONS; + case TAG_SEC_NAME.value: return _TAG_SEC_NAME; + case TAG_SPKM_1_SEC_MECH.value: return _TAG_SPKM_1_SEC_MECH; + case TAG_SPKM_2_SEC_MECH.value: return _TAG_SPKM_2_SEC_MECH; + case TAG_KerberosV5_SEC_MECH.value: return _TAG_KerberosV5_SEC_MECH; + case TAG_CSI_ECMA_Secret_SEC_MECH.value: return _TAG_CSI_ECMA_Secret_SEC_MECH; + case TAG_CSI_ECMA_Hybrid_SEC_MECH.value: return _TAG_CSI_ECMA_Hybrid_SEC_MECH; + case TAG_OTS_POLICY.value: return _TAG_OTS_POLICY; + case TAG_INV_POLICY.value: return _TAG_INV_POLICY; + case TAG_SECIOP_SEC_TRANS.value: return _TAG_SECIOP_SEC_TRANS; + case TAG_NULL_TAG.value: return _TAG_NULL_TAG; + case TAG_TLS_SEC_TRANS.value: return _TAG_TLS_SEC_TRANS; + case TAG_SSL_SEC_TRANS.value: return _TAG_SSL_SEC_TRANS; + case TAG_CSI_ECMA_Public_SEC_MECH.value: return _TAG_CSI_ECMA_Public_SEC_MECH; + case TAG_GENERIC_SEC_MECH.value: return _TAG_GENERIC_SEC_MECH; + case TAG_COMPLETE_OBJECT_KEY.value: return _TAG_COMPLETE_OBJECT_KEY; + case TAG_ENDPOINT_ID_POSITION.value: return _TAG_ENDPOINT_ID_POSITION; + case TAG_LOCATION_POLICY.value: return _TAG_LOCATION_POLICY; + case TAG_DCE_STRING_BINDING.value: return _TAG_DCE_STRING_BINDING; + case TAG_DCE_BINDING_NAME.value: return _TAG_DCE_BINDING_NAME; + case TAG_DCE_NO_PIPES.value: return _TAG_DCE_NO_PIPES; + case TAG_DCE_SEC_MECH.value: return _TAG_DCE_SEC_MECH; + case TAG_CODE_SETS.value: return _TAG_CODE_SETS; + case TAG_ORB_TYPE.value: return _TAG_ORB_TYPE; + case TAG_ALTERNATE_IIOP_ADDRESS.value: return _TAG_ALTERNATE_IIOP_ADDRESS; + case TAG_CSI_SEC_MECH_LIST.value: return _TAG_CSI_SEC_MECH_LIST; + case TAG_JAVA_CODEBASE.value: return _TAG_JAVA_CODEBASE; + default: return _UNKNOWN; + } } } + + public static void describe_component(TaggedComponent component, StringBuilder sb) { + TagComp.findById(component.tag).describe(component, sb); + } } + diff --git a/yoko-core/src/main/java/org/apache/yoko/orb/OBPortableServer/POAManager_impl.java b/yoko-core/src/main/java/org/apache/yoko/orb/OBPortableServer/POAManager_impl.java index 7caa131f9..50c1abee5 100644 --- a/yoko-core/src/main/java/org/apache/yoko/orb/OBPortableServer/POAManager_impl.java +++ b/yoko-core/src/main/java/org/apache/yoko/orb/OBPortableServer/POAManager_impl.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 IBM Corporation and others. + * Copyright 2024 IBM Corporation and others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,16 @@ */ package org.apache.yoko.orb.OBPortableServer; +import static org.apache.yoko.orb.OB.ObjectKey.ParseObjectKey; +import static org.apache.yoko.orb.OB.Server.Blocking; +import static org.apache.yoko.orb.OB.Server.Threaded; +import static org.omg.CORBA.CompletionStatus.COMPLETED_NO; + +import java.util.Hashtable; +import java.util.Optional; +import java.util.Properties; +import java.util.logging.Logger; + import org.apache.yoko.orb.CORBA.Delegate; import org.apache.yoko.orb.OB.BootManager_impl; import org.apache.yoko.orb.OB.CollocatedServer; @@ -37,11 +47,11 @@ import org.omg.CORBA.INITIALIZE; import org.omg.CORBA.LocalObject; import org.omg.CORBA.OBJECT_NOT_EXIST; -import org.omg.CORBA.ORBPackage.InvalidName; import org.omg.CORBA.Object; import org.omg.CORBA.Policy; import org.omg.CORBA.PolicyError; import org.omg.CORBA.TRANSIENT; +import org.omg.CORBA.ORBPackage.InvalidName; import org.omg.CORBA.portable.ObjectImpl; import org.omg.GIOP.Version; import org.omg.IOP.IOR; @@ -53,18 +63,6 @@ import org.omg.PortableServer.POAManagerPackage.AdapterInactive; import org.omg.PortableServer.POAManagerPackage.State; -import java.util.Hashtable; -import java.util.Optional; -import java.util.Properties; -import java.util.logging.Logger; - -import static java.util.Arrays.asList; -import static java.util.Collections.unmodifiableList; -import static org.apache.yoko.orb.OB.ObjectKey.ParseObjectKey; -import static org.apache.yoko.orb.OB.Server.Blocking; -import static org.apache.yoko.orb.OB.Server.Threaded; -import static org.omg.CORBA.CompletionStatus.COMPLETED_NO; - final public class POAManager_impl extends LocalObject implements POAManager { static final Logger logger = Logger.getLogger(POAManager_impl.class.getName()); private final ORBInstance orbInstance; diff --git a/yoko-core/src/main/java/org/apache/yoko/orb/OCI/IIOP/ConFactory_impl.java b/yoko-core/src/main/java/org/apache/yoko/orb/OCI/IIOP/ConFactory_impl.java index f1da04590..be7322799 100644 --- a/yoko-core/src/main/java/org/apache/yoko/orb/OCI/IIOP/ConFactory_impl.java +++ b/yoko-core/src/main/java/org/apache/yoko/orb/OCI/IIOP/ConFactory_impl.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 IBM Corporation and others. + * Copyright 2024 IBM Corporation and others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -105,7 +105,7 @@ public String describe_profile(TaggedProfile profile) { final int port = ((char)body.port); result.append("port: " + port + '\n'); result.append("object_key: (" + body.object_key.length + ")\n"); - formatHexPara(body.object_key, 0, body.object_key.length, result); + formatHexPara(body.object_key, 0, body.object_key.length, result).append('\n'); // // Print IIOP 1.1 information (components) @@ -127,7 +127,7 @@ public String describe_profile(TaggedProfile profile) { public Connector[] create_connectors(IOR ior, Policy[] policies) { if (logger.isLoggable(Level.FINEST)) { - logger.finest("Creating connection for ior: " + IORDump.PrintObjref(orb_, ior)); + logger.finest("Creating connection for ior: " + IORDump.describeIor(orb_, ior)); } // diff --git a/yoko-osgi/src/main/java/org/apache/yoko/osgi/locator/ServiceProvider.java b/yoko-osgi/src/main/java/org/apache/yoko/osgi/locator/ServiceProvider.java index 48eef9bda..c2f9c422b 100644 --- a/yoko-osgi/src/main/java/org/apache/yoko/osgi/locator/ServiceProvider.java +++ b/yoko-osgi/src/main/java/org/apache/yoko/osgi/locator/ServiceProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 IBM Corporation and others. + * Copyright 2024 IBM Corporation and others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,10 +64,12 @@ public int getPriority() { return priority; } + @SuppressWarnings("unchecked") public Class getServiceClass() throws ClassNotFoundException { return (Class) localFactory.forName(className); } + @SuppressWarnings("unchecked") public T getServiceInstance() throws ClassNotFoundException, InstantiationException, IllegalAccessException { return (T) localFactory.newInstance(getServiceClass()); } diff --git a/yoko-util/src/main/java/org/apache/yoko/io/Buffer.java b/yoko-util/src/main/java/org/apache/yoko/io/Buffer.java index bf4b9d2f4..9cc4c9e02 100644 --- a/yoko-util/src/main/java/org/apache/yoko/io/Buffer.java +++ b/yoko-util/src/main/java/org/apache/yoko/io/Buffer.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 IBM Corporation and others. + * Copyright 2024 IBM Corporation and others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ * @param the concrete child class */ @SuppressWarnings("unchecked") -public abstract class Buffer implements Cloneable { +public abstract class Buffer> implements Cloneable { public static ReadBuffer createReadBuffer(byte[] data) { return new ReadBuffer(new Core(data)); } public static WriteBuffer createWriteBuffer() { return new WriteBuffer(new Core()); } public static WriteBuffer createWriteBuffer(int initialBufferSize) { return new WriteBuffer(new Core(initialBufferSize)); }