/*
(non-Javadoc)
@see org.jdiameter.client.api.controller.IRealmTable#getRealm(java.lang.String, org.jdiameter.api.ApplicationId)
977305
@Override
  public Realm getRealm(String realmName, ApplicationId applicationId) {
    RealmSet rs = this.realmNameToRealmSet.get(realmName);
    return rs == null ? null : rs.getRealm(applicationId);
  }
417631
protected void createRealmDataObject(Root inputRootObject, String inputRealm) {
        // use the root DataGraph to create a Context DataGraph
        List<Context> contexts = inputRootObject.getContexts();
        if (contexts != null) {
            Context ctx = new Context();
            // set "WIM.Realm" in the Context DataGraph to the realm
            ctx.setKey(Service.VALUE_CONTEXT_REALM_KEY);
            ctx.setValue(inputRealm);
            contexts.add(ctx);
        }

    }
107079
@Override
    public AuthenticationRequest setRealm(String realm) {
        if (hasLegacyPath()) {
            Log.w(TAG, "Not setting the 'realm' parameter as the request is using a Legacy Authorization API endpoint that doesn't support it.");
            return this;
        }
        addParameter(REALM_KEY, realm);
        return this;
    }
1217569
public String getRealPath(String path, boolean checkDocRoot)
  {
      if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && logger.isLoggable(Level.FINE))
          logger.entering(CLASS_NAME, "getRealPath", new Object[]{path, checkDocRoot});
      
      //if (webAppInfo != null)
      //{
          // return "bundleresource:";
      //}
       
    String basePath = null;

    if (path == null || path.equals("")) {
        path = "/";
    }
      
    if(container != null){
        
        boolean pathIsBackslash = false;
        if (path.contains("\\")) {
            if (path.equals("\\")) {
                pathIsBackslash = true;
            }
            path=path.replace("\\", "/");
        }
        
        if (path.equals("/")) {
            String physicalPath = container.getPhysicalPath();
            
            if (physicalPath == null) { // loose app might return null here
                return null;
            }        

            File file = new File(physicalPath);
            if (!file.exists() || !file.isDirectory()){ //might be a xxx.war, so return null if it is an archive
                return null;
            }
            
            if(pathIsBackslash == true){
                // add backslash back on to the end so there will be a \ at the end.
                // Need to do this to maintain compatibility with twas
                // PM70146
                physicalPath = physicalPath + "\\"; 
                return physicalPath;
            }          
            
            //getAbsolutePath always return a file path without slash in the end, even the file is a directory.
            return file.getAbsolutePath();
        }
        
        try {
            Entry entry = container.getEntry(path);
            if(entry != null){
                String s = entry.getPhysicalPath();
                // if passed in path ends in separator, then make sure return value does also
                if ( (s != null) && (path.length()>1 && path.endsWith("/") &&(s.charAt(s.length() - 1) != File.separatorChar)) ) {
                    s = s + File.separator;
                }
                return s;

            } else {
                if (checkDocRoot == false) {
                    return null;
                }
                
                DocumentRootUtils dru = getDocumentRootUtils(path);
                
                if (dru != null) {
                    if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && logger.isLoggable(Level.FINE))
                        logger.logp(Level.FINE, CLASS_NAME, "getRealPath", "obtained dru");
                    
                    dru.handleDocumentRoots(path, WCCustomProperties.CHECK_EDR_IN_GET_REAL_PATH);
                    EntryResource er = dru.getMatchedEntryResource();

                    if (er != null) {
                        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && logger.isLoggable(Level.FINE))
                            logger.logp(Level.FINE, CLASS_NAME, "getRealPath", "obtained er: " + er);
                        Entry ety = er.getEntry();
                        if (ety != null) {
                            if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && logger.isLoggable(Level.FINE))
                                logger.logp(Level.FINE, CLASS_NAME, "getRealPath", "obtained entry: " + ety);
                            
                            String s = ety.getPhysicalPath();
                            if ((s != null) && (s.length()> 0)) {
                                if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && logger.isLoggable(Level.FINE))
                                    logger.logp(Level.FINE, CLASS_NAME, "getRealPath", "getPhysicalPath() is: " + s);
                                // if passed in path ends in separator, then make sure return value does also
                                if (  (path.endsWith("/"))
                                    &&(s.charAt(s.length() - 1) != File.separatorChar)) {
                                    s = s + File.separator;
                                }
                                return s;
                            } else {
                                // to be TWAS compliant, return container path if we are not checking EDRs and can't find the real path
                                //if the app was extracted, we could return the physical path
                                if (WCCustomProperties.CHECK_EDR_IN_GET_REAL_PATH == false) {
                                    basePath = container.getPhysicalPath();
                                }
                            }
                        }
                    }
                    else{
                        File matchedFile = dru.getMatchedFile();
                        if (matchedFile != null){
                            if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && logger.isLoggable(Level.FINE))
                                logger.logp(Level.FINE, CLASS_NAME, "getRealPath", "obtained file [" + matchedFile.getAbsolutePath() +"]"); 
                            return matchedFile.getAbsolutePath();
                        }
                    }
                }
            }
        } catch(IllegalArgumentException e){
            logger.logp(Level.FINE, CLASS_NAME, "getRealPath", "caught IllegalArgument Exception. path: " + path + "  Exception: " + e);
            return null;
        } catch(IOException e){
            logger.logp(Level.FINE, CLASS_NAME, "getRealPath", "caught IOException processing document root getReadPath: " + path + "  Exception: " + e);

            // to be TWAS compliant, return container path if we are not checking EDRs and can't find the real path
            // but return null if we are checking EDRs and can't find the real path
            if (WCCustomProperties.CHECK_EDR_IN_GET_REAL_PATH) {
                 return null;
            }
            //if the app was extracted, we could return this...
            basePath = container.getPhysicalPath();
         }
        
    }
    
    if (basePath == null) {
        return null;
    }

    basePath = basePath.replace('\\', '/');
    
    if (File.separatorChar!='/') {
        basePath = basePath.replace('/', File.separatorChar);
        path = path.replace('/', File.separatorChar);
    }

    String realPath = "";
    
    if (path.charAt(0) == File.separatorChar) { 
        realPath = basePath + path;
    } else {
        realPath = basePath + File.separatorChar + path;
    }
    
    return realPath;
  }
741916
protected Realm matchRealm(IMessage message, String realm) {
    if (realmExists(realm)) {
      ApplicationId singleId = message.getSingleApplicationId();
      // check on single app id, than we iterate.
      Realm r = getRealm(realm, singleId);
      if (r == null) {
        List<ApplicationId> appIds = message.getApplicationIdAvps();
        for (int index = 0; index < appIds.size(); index++) {
          r = getRealm(realm, appIds.get(index));
          if (r != null) {
            break;
          }
        }
      }

      return r;
    }
    return null;
  }
970824
public static String getVMIP(String hostIpPort, String id) throws TargetException {

		//TODO Expecting more interoperable implem... /compute/urn:uuid:ID for Scalair, /ID for CA !
		if(! hostIpPort.endsWith("/compute") && id.startsWith("urn:uuid:")) id = id.substring(9);
		String vmIp = null;
		URL url = null;
		try {
			CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
			url = new URL("http://" + hostIpPort + "/" + id);
		} catch (MalformedURLException e) {
			throw new TargetException(e);
		}

		HttpURLConnection httpURLConnection = null;
		DataInputStream in = null;
		try {
			httpURLConnection = (HttpURLConnection) url.openConnection();
			httpURLConnection.setRequestMethod("GET");
			httpURLConnection.setRequestProperty("Accept", "application/json");

			in = new DataInputStream(httpURLConnection.getInputStream());
			ByteArrayOutputStream out = new ByteArrayOutputStream();
			Utils.copyStreamSafely(in, out);

			// Parse JSON response to extract VM IP
			ObjectMapper objectMapper = new ObjectMapper();
			JsonResponse rsp = objectMapper.readValue(out.toString( "UTF-8" ), JsonResponse.class);
			vmIp = rsp.getHostsystemname();
			if(Utils.isEmptyOrWhitespaces(vmIp)) vmIp = rsp.getHostname();
			if(Utils.isEmptyOrWhitespaces(vmIp) && rsp.getAttributes() != null)
				vmIp = rsp.getAttributes().getHostname();

		} catch (IOException e) {
			throw new TargetException(e);

		}  finally {
			Utils.closeQuietly(in);
			if (httpURLConnection != null) {
				httpURLConnection.disconnect();
			}
		}

		return vmIp;
	}
1160944
public int getRenderIndexFromRealIdx(final int realIdx) {
        if (columnMapping == null || realIdx == -1) {
            return realIdx;
        }

        for (final Entry<Integer, Integer> entry : columnMapping.entrySet()) {
            if (entry.getValue().equals(realIdx)) {
                return entry.getKey();
            }
        }

        return realIdx;
    }
1124989
public static Set<String> getSpecifiedRealms(Root root) {
        Set<String> result = new HashSet<String>();
        List<Context> contexts = root.getContexts();
        for (Context context : contexts) {
            String key = context.getKey();
            if (key != null && key.equals(SchemaConstants.PROP_REALM)) {
                String value = (String) context.getValue();
                result.add(value);
            }
        }
        return result;
    }
627802
private String getRealmName(WSCredential cred) {
        String realmName = null;
        if (cred != null) {
            try {
                realmName = cred.getRealmName();
            } catch (Exception e) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Caught exception getting the realm name: " + e);
                }
            }
        }
        return realmName;
    }
881492
public UserRealm addRealm(UserRealm realm)
    {
        return (UserRealm)_realmMap.put(realm.getName(),realm);
    }
598676
public ClassLoader getRealAppClassLoader(Application application) {
        try {
            List<CDIArchive> moduleArchives = new ArrayList<CDIArchive>(application.getModuleArchives());
            if (moduleArchives.isEmpty()) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, Util.identity(this), "Application {0} has no modules so no thread context class loader will be set, this is expected for an OSGI app.",
                             application);
                }
                return null;
            }
            if (moduleArchives.size() == 1 && ArchiveType.WEB_MODULE == moduleArchives.get(0).getType()) {
                return moduleArchives.get(0).getClassLoader();
            }

            return application.getClassLoader();
        } catch (CDIException e) {
            return null;
        }
    }
421054
private String executeScriptGetValueRequest(String openCpuSessionKey) throws IOException {
    URI scriptGetValueResponseUri = getScriptGetValueResponseUri(openCpuSessionKey);
    HttpGet httpGet = new HttpGet(scriptGetValueResponseUri);
    String responseValue;
    try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
      int statusCode = response.getStatusLine().getStatusCode();
      if (statusCode >= 200 && statusCode < 300) {
        HttpEntity entity = response.getEntity();
        responseValue = EntityUtils.toString(entity);
        EntityUtils.consume(entity);
      } else {
        throw new ClientProtocolException(format(FORMAT_UNEXPECTED_RESPONSE_STATUS, statusCode));
      }
    }
    return responseValue;
  }
150024
public EntityManagerFactory getEMF(String applicationToken)
    {
        if (emfMap == null)
        {
            return null;
        }
        else
        {
            return emfMap.get(applicationToken);
        }
    }
177702
@Path("version")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response version() {
        try {
            InputStream is = getClass().getResourceAsStream("/application.properties");
            Properties props = new Properties();
            props.load(is);
            String version = props.get("version").toString();
            String buildNumber = props.get("buildNumber").toString();
            return Response.ok().entity(
                "{\"version\":\"" + version +
                "\",\"build\":\"" + buildNumber + "\"}").build();
        } catch (IOException e) {
            //should never happen
            throw new RuntimeException(e);
        }
    }
687983
public static Application get(final BandwidthClient client, final String id) throws Exception {
        assert(id != null);
        final String applicationUri = client.getUserResourceInstanceUri(BandwidthConstants.APPLICATIONS_URI_PATH, id);
        final JSONObject applicationObj = toJSONObject( client.get(applicationUri, null) );
        
        final Application application = new Application(client, applicationObj);
        return application;
    }
329501
public static String getRealm(String accessId) {
        Matcher m = matcher(accessId);
        if (m != null) {
            return m.group(2);
        }
        return null;
    }
1153306
public function getRealValue()
    {
        if(Coroutine::isIn())
        {
            return RequestContext::getBean($this->name, ...$this->args);
        }
        else
        {
            return App::getBean($this->name, ...$this->args);
        }
    }