from io.micrometer.spring.web.servlet.WebMvcTags
486202
static String getPathInfo(RequestLog requestLog) {
    String uri = requestLog.path();
    if (!StringUtils.hasText(uri)) return "/";
    return uri.replaceAll("//+", "/")
      .replaceAll("/$", "");
  }
728918
public Collection<String> getAllTags() {
		return wrappedSubmit(new Callable<Collection<String>>() {

			@Override
			public Collection<String> call() throws Exception {
				Collection<String> allTags = new HashSet<String>();
				ObjectMapper mapper = new ObjectMapper();
				List<XmlTag> xmltags = new ArrayList<XmlTag>();
				try {xmltags = mapper.readValue(
										service.path(resourceTags)
										.accept(MediaType.APPLICATION_JSON)
										.get(String.class)	
									,new TypeReference<List<XmlTag>>(){});
				} catch (JsonParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (JsonMappingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ClientHandlerException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				for (XmlTag xmltag : xmltags) {
					allTags.add(xmltag.getName());
				}
				return allTags;
			}
		});
	}
94782
@SuppressWarnings ({"unchecked", "rawtypes"})
    private Tag readTagPayload(TagType type, String name, int depth) throws IOException {
        switch (type) {
            case TAG_END:
                if (depth == 0) {
                    throw new IOException("TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
                } else {
                    return new EndTag();
                }

            case TAG_BYTE:
                return new ByteTag(name, is.readByte());

            case TAG_SHORT:
                return new ShortTag(name, is.readShort());

            case TAG_INT:
                return new IntTag(name, is.readInt());

            case TAG_LONG:
                return new LongTag(name, is.readLong());

            case TAG_FLOAT:
                return new FloatTag(name, is.readFloat());

            case TAG_DOUBLE:
                return new DoubleTag(name, is.readDouble());

            case TAG_BYTE_ARRAY:
                int length = is.readInt();
                byte[] bytes = new byte[length];
                is.readFully(bytes);
                return new ByteArrayTag(name, bytes);

            case TAG_STRING:
                length = is.readShort();
                bytes = new byte[length];
                is.readFully(bytes);
                return new StringTag(name, new String(bytes, NBTConstants.CHARSET.name()));

            case TAG_LIST:
                TagType childType = TagType.getById(is.readByte());
                length = is.readInt();

                Class<? extends Tag> clazz = childType.getTagClass();
                List<Tag> tagList = new ArrayList<Tag>(length);
                for (int i = 0; i < length; i++) {
                    Tag tag = readTagPayload(childType, "", depth + 1);
                    if (tag instanceof EndTag) {
                        throw new IOException("TAG_End not permitted in a list.");
                    } else if (!clazz.isInstance(tag)) {
                        throw new IOException("Mixed tag types within a list.");
                    }
                    tagList.add(tag);
                }

                return new ListTag(name, clazz, tagList);

            case TAG_COMPOUND:
                CompoundMap compoundTagList = new CompoundMap();
                while (true) {
                    Tag tag = readTag(depth + 1);
                    if (tag instanceof EndTag) {
                        break;
                    } else {
                        compoundTagList.put(tag);
                    }
                }

                return new CompoundTag(name, compoundTagList);

            case TAG_INT_ARRAY:
                length = is.readInt();
                int[] ints = new int[length];
                for (int i = 0; i < length; i++) {
                    ints[i] = is.readInt();
                }
                return new IntArrayTag(name, ints);

            case TAG_SHORT_ARRAY:
                length = is.readInt();
                short[] shorts = new short[length];
                for (int i = 0; i < length; i++) {
                    shorts[i] = is.readShort();
                }
                return new ShortArrayTag(name, shorts);

            default:
                throw new IOException("Invalid tag type: " + type + ".");
        }
    }
1083766
public static WebRequestInterceptor[] lookupWebRequestInterceptors(ServletContext servletContext) {
        WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);

        final Collection<WebRequestInterceptor> webRequestInterceptors = wac.getBeansOfType(WebRequestInterceptor.class).values();
        return webRequestInterceptors.toArray(new WebRequestInterceptor[webRequestInterceptors.size()]);
    }
200910
public static Tag readTag(DataInput in) throws IOException {
        int id = in.readUnsignedByte();
        if(id == 0) {
            return null;
        }

        String name = in.readUTF();
        Tag tag;

        try {
            tag = TagRegistry.createInstance(id, name);
        } catch(TagCreateException e) {
            throw new IOException("Failed to create tag.", e);
        }

        tag.read(in);
        return tag;
    }
140380
private static void parseServlets(final ServletType servletType, final WebApp webApp) {
		final WebAppServlet servlet = new WebAppServlet();
		servlet.setServletName(servletType.getServletName().getValue());
		if (servletType.getServletClass() != null) {
			servlet.setServletClassName(servletType.getServletClass().getValue());
			webApp.addServlet(servlet);
		} else {
			String jspFile = servletType.getJspFile().getValue();
			if (jspFile != null) {
				WebAppJspServlet jspServlet = new WebAppJspServlet();
				jspServlet.setServletName(servletType.getServletName().getValue());
				jspServlet.setJspPath(jspFile);
				webApp.addServlet(jspServlet);
			}
		}
		servlet.setLoadOnStartup(servletType.getLoadOnStartup());
		if (servletType.getAsyncSupported() != null) {
			servlet.setAsyncSupported(servletType.getAsyncSupported().isValue());
		}

		MultipartConfigType multipartConfig = servletType.getMultipartConfig();
		if (multipartConfig != null) {
			String location;
			if (multipartConfig.getLocation() == null) {
				location = null;
			} else {
				location = multipartConfig.getLocation().getValue();
			}
			long maxFileSize;
			if (multipartConfig.getMaxFileSize() == null) {
				maxFileSize = -1L;
			} else {
				maxFileSize = multipartConfig.getMaxFileSize();
			}
			long maxRequestSize;
			if (multipartConfig.getMaxRequestSize() == null) {
				maxRequestSize = -1L;
			} else {
				maxRequestSize = multipartConfig.getMaxRequestSize();
			}
			int fileSizeThreshold;
			if (multipartConfig.getFileSizeThreshold() == null) {
				fileSizeThreshold = 0;
			} else {
				fileSizeThreshold = multipartConfig.getFileSizeThreshold().intValue();
			}
			MultipartConfigElement multipartConfigElement = new MultipartConfigElement(location, maxFileSize, maxRequestSize,
					fileSizeThreshold);
			servlet.setMultipartConfig(multipartConfigElement);
		}

		List<ParamValueType> servletInitParams = servletType.getInitParam();
		for (ParamValueType initParamElement : servletInitParams) {
			final WebAppInitParam initParam = new WebAppInitParam();
			initParam.setParamName(initParamElement.getParamName().getValue());
			initParam.setParamValue(initParamElement.getParamValue().getValue());
			servlet.addInitParam(initParam);
		}

	}
843572
@Override
  public String getTag() throws IOException {

    URLConnection urlConnection = url.openConnection();
    
    String tag = urlConnection.getHeaderField(ETAG);
    if(tag == null) {
    
      String key = url.toString() + "@" + urlConnection.getLastModified();
      
      tag = md5Cache.getIfPresent(key);

      if(tag == null) {
          
        try(InputStream urlStream = urlConnection.getInputStream()) {
      
          byte[] data = ByteStreams.toByteArray(urlConnection.getInputStream());
      
          tag = Hashing.md5().hashBytes(data).toString();
      
          md5Cache.put(key, tag);
        }
        
      }
      
    }
    
    return tag;
  }
756456
static byte[] payloadAndAuthTag(OmemoElement element, byte[] authTag) {
        if (!element.isMessageElement()) {
            throw new IllegalArgumentException("OmemoElement has no payload.");
        }

        byte[] payload = new byte[element.getPayload().length + authTag.length];
        System.arraycopy(element.getPayload(), 0, payload, 0, element.getPayload().length);
        System.arraycopy(authTag, 0, payload, element.getPayload().length, authTag.length);
        return payload;
    }
511945
@Override
	public void doTag() throws JspException, IOException {
		try {
			final PageContext pageContext = (PageContext)getJspContext();
			final ServletRequest request = pageContext.getRequest();
			final HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
			final JspWriter out = pageContext.getOut();

			final ThreadEncodingContext parentEncodingContext = ThreadEncodingContext.getCurrentContext(request);

			// Determine the container's content type
			MediaType containerContentType;
			if(parentEncodingContext != null) {
				// Use the output type of the parent
				containerContentType = parentEncodingContext.contentType;
			} else {
				// Use the content type of the response
				String responseContentType = response.getContentType();
				// Default to XHTML: TODO: Is there a better way since can't set content type early in response then reset again...
				if(responseContentType == null) responseContentType = MediaType.XHTML.getContentType();
				containerContentType = MediaType.getMediaTypeForContentType(responseContentType);
			}
			// Find the encoder
			final MediaType myContentType = getContentType();
			MediaEncoder mediaEncoder = MediaEncoder.getInstance(new HttpServletResponseEncodingContext(response), myContentType, containerContentType);
			if(mediaEncoder != null) {
				setMediaEncoderOptions(mediaEncoder);
				// Encode both our output and the content.  The encoder validates our input and guarantees valid output for our parent.
				MediaWriter mediaWriter = new MediaWriter(mediaEncoder, out);
				mediaWriter.writePrefix();
				try {
					ThreadEncodingContext.setCurrentContext(
						request,
						new ThreadEncodingContext(myContentType, mediaWriter)
					);
					try {
						doTag(mediaWriter);
					} finally {
						// Restore previous encoding context that is used for our output
						ThreadEncodingContext.setCurrentContext(request, parentEncodingContext);
					}
				} finally {
					mediaWriter.writeSuffix();
				}
			} else {
				// If parentValidMediaInput exists and is validating our output type, no additional validation is required
				if(
					parentEncodingContext != null
					&& parentEncodingContext.validMediaInput.isValidatingMediaInputType(myContentType)
				) {
					ThreadEncodingContext.setCurrentContext(
						request,
						new ThreadEncodingContext(myContentType, parentEncodingContext.validMediaInput)
					);
					try {
						doTag(out);
					} finally {
						ThreadEncodingContext.setCurrentContext(request, parentEncodingContext);
					}
				} else {
						// Not using an encoder and parent doesn't validate our output, validate our own output.
					MediaValidator validator = MediaValidator.getMediaValidator(myContentType, out);
					ThreadEncodingContext.setCurrentContext(
						request,
						new ThreadEncodingContext(myContentType, validator)
					);
					try {
						doTag(validator);
					} finally {
						ThreadEncodingContext.setCurrentContext(request, parentEncodingContext);
					}
				}
			}
		} catch(MediaException err) {
			throw new JspTagException(err);
		}
	}
130125
@RequestMapping(method = RequestMethod.GET)
  public ApplicationRegistry getMetrics(@RequestParam Map<String, String> filters)
    throws IOException {
    boolean all = filters.get("all") != null;
    String filterMeterNameRegex = filters.getOrDefault("meterNameRegex", "");
    String filterTagNameRegex = filters.getOrDefault("tagNameRegex", "");
    String filterTagValueRegex = filters.getOrDefault("tagValueRegex", "");
    TagMeasurementFilter queryFilter = new TagMeasurementFilter(
        filterMeterNameRegex, filterTagNameRegex, filterTagValueRegex);
    Predicate<Measurement> filter;
    if (all) {
      filter = queryFilter;
    } else {
      filter = queryFilter.and(getDefaultMeasurementFilter());
    }

    ApplicationRegistry response = new ApplicationRegistry();
    response.setApplicationName(applicationName);
    response.setApplicationVersion(applicationVersion);
    response.setMetrics(encodeRegistry(registry, filter));
    return response;
  }
503500
@Override
	protected RequestMapping parseRequestMapping(MethodDoc methodDoc) {
		ClassDoc controllerClass = methodDoc.containingClass();
		RequestMapping baseMapping = null;
		boolean controllerCustomizedMapping = false;
		boolean actionCustomizedMapping = false;
		Tag[] tags = controllerClass.tags(WRAPITaglet.NAME);
		if (tags.length > 0) {
			baseMapping = this.parseRequestMapping(tags[0]);
		}

		if (baseMapping == null) {
			AnnotationDesc[] baseAnnotations = controllerClass.annotations();
			baseMapping = this.parseRequestMapping(baseAnnotations);
			controllerCustomizedMapping = false;
		} else {
			controllerCustomizedMapping = true;
		}

		RequestMapping mapping = null;
		Tag[] methodTags = methodDoc.tags(WRAPITaglet.NAME);
		if (methodTags.length > 0) {
			mapping = this.parseRequestMapping(methodTags[0]);
		}
		if (mapping == null) {
			AnnotationDesc[] annotations = methodDoc.annotations();
			mapping = this.parseRequestMapping(annotations);
			actionCustomizedMapping = false;
		} else {
			actionCustomizedMapping = true;
		}
		RequestMapping result;
		if (baseMapping == null) {
			result = mapping;
		} else if (mapping == null) {
			result = baseMapping;
		} else {
			if(!actionCustomizedMapping || controllerCustomizedMapping) {
				mapping.setUrl(net.winroad.wrdoclet.utils.Util.urlConcat(
						baseMapping.getUrl(), mapping.getUrl()));
			}
			if (baseMapping.getMethodType() != null) {
				if (mapping.getMethodType() != null) {
					mapping.setMethodType(baseMapping.getMethodType() + ","
							+ mapping.getMethodType());
				} else {
					mapping.setMethodType(baseMapping.getMethodType());
				}
			}
			result = mapping;
		}
		if (result != null) {
			result.setTooltip(methodDoc.containingClass().simpleTypeName());
			result.setContainerName(methodDoc.containingClass()
					.simpleTypeName());
		}
		return result;
	}
711830
@Override
    public List<Class<?>> retrieveJAXWSHandlers(J2EEName j2eeName) {

        JaxWsModuleMetaData jaxWsModuleMetaData = JaxWsMetaDataManager.getJaxWsModuleMetaData();
        if (jaxWsModuleMetaData == null) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Unable to get the JaxWsModuleMetaData from current invocation context while querying EJBHandler");
            }
            return null;
        }

        JaxWsModuleInfo jaxWsModuleInfo = null;
        try {
            Container containerToAdapt = jaxWsModuleMetaData.getModuleContainer();
            jaxWsModuleInfo = containerToAdapt.adapt(JaxWsModuleInfo.class);
        } catch (UnableToAdaptException e) {
            throw new IllegalStateException(e);
        }

        if (jaxWsModuleInfo == null) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Unable to get the JaxWsModuleInfo from current module {0} while querying EJBHandler", jaxWsModuleMetaData.getModuleInfo().getName());
            }
            return null;
        }

        JaxWsServerMetaData jaxwsServerMetaData = jaxWsModuleMetaData.getServerMetaData();
        String endpointName = jaxwsServerMetaData.retrieveEndpointName(j2eeName);

        if (endpointName == null) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "No endpoint with j2eeName {0} exists in module {1}", j2eeName, jaxWsModuleMetaData.getModuleInfo().getName());
            }
            return null;
        }

        EndpointInfo endpointInfo = jaxWsModuleInfo.getEndpointInfo(endpointName);

        if (endpointInfo == null) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "No endpoint with endpoint name {0} exists in module {1}", endpointName, jaxWsModuleMetaData.getModuleInfo().getName());
            }
            return null;
        }

        ClassLoader appContextClassLoader = jaxWsModuleMetaData.getAppContextClassLoader();

        List<HandlerInfo> handlerInfos = endpointInfo.getHandlerChainsInfo().getAllHandlerInfos();
        List<Class<?>> handlerClasses = new ArrayList<Class<?>>(handlerInfos.size());
        for (HandlerInfo handlerInfo : handlerInfos) {
            String handlerClassName = handlerInfo.getHandlerClass();
            try {
                Class<?> handlerClass = appContextClassLoader.loadClass(handlerClassName);
                handlerClasses.add(handlerClass);
            } catch (ClassNotFoundException e) {
                Tr.warning(tc, "warn.could.not.find.handler", handlerClassName, e.getMessage());
            }
        }

        return handlerClasses;

    }
244655
@Override
    public final Collection<Metric> gatherMetrics(final ICommandLine cl) throws MetricGatheringException {
        List<Metric> metrics = new ArrayList<Metric>();
        String hostname = cl.getOptionValue("hostname");
        if (hostname == null) {
            throw new MetricGatheringException("No hostname specified.", Status.WARNING, null);
        }

        String port = cl.getOptionValue("port", DEFAULT_PORT);
        String path = cl.getOptionValue("url", DEFAULT_PATH);
        String method = cl.getOptionValue("method", DEFAULT_METHOD);

        int timeout = DEFAULT_TIMEOUT;
        if (cl.hasOption("post")) {
            method = "POST";
        }
        boolean ssl = false;
        if (cl.hasOption("ssl") || cl.getOptionValue("certificate") != null) {
            port = cl.getOptionValue("ssl", DEFAULT_SSL_PORT);
            ssl = true;
        }

        if (cl.hasOption("timeout")) {
            try {
                timeout = Integer.parseInt(cl.getOptionValue("timeout"));
            } catch (NumberFormatException e) {
                throw new MetricGatheringException("Invalid numeric value for timeout.", Status.CRITICAL, e);
            }
        }
        if (!path.startsWith("/")) {
            path = "/" + path;
        }
        if (hostname.endsWith("/")) {
            hostname = hostname.substring(0, hostname.length() - 1);
        }

        long then = System.currentTimeMillis();

        String response = getHttpResponse(cl, hostname, port, method, path, timeout, ssl, metrics);
        int elapsed = (int) Utils.milliToSec(System.currentTimeMillis() - then);
        if (response != null) {
            metrics.addAll(analyzeResponse(cl, response, elapsed));
        }
        return metrics;
    }
1205824
@Override
	public WebMvcLinkBuilder linkTo(Object invocationValue) {

		Function<String, UriComponentsBuilder> builderFactory = mapping -> UriComponentsBuilderFactory.getBuilder()
				.path(mapping);

		return WebHandler.linkTo(invocationValue, WebMvcLinkBuilder::new, (builder, invocation) -> {

			MethodParameters parameters = MethodParameters.of(invocation.getMethod());
			Iterator<Object> parameterValues = Arrays.asList(invocation.getArguments()).iterator();

			for (MethodParameter parameter : parameters.getParameters()) {

				Object parameterValue = parameterValues.next();

				uriComponentsContributors.stream() //
						.filter(it -> it.supportsParameter(parameter)) //
						.forEach(it -> it.enhance(builder, parameter, parameterValue));
			}

			return builder;

		}).apply(builderFactory);
	}
764277
public static List<byte[]> getTagPairsFromTSUID(final byte[] tsuid) {
    if (tsuid == null) {
      throw new IllegalArgumentException("Missing TSUID");
    }
    if (tsuid.length <= TSDB.metrics_width()) {
      throw new IllegalArgumentException(
          "TSUID is too short, may be missing tags");
    }
     
    final List<byte[]> tags = new ArrayList<byte[]>();
    final int pair_width = TSDB.tagk_width() + TSDB.tagv_width();
    
    // start after the metric then iterate over each tagk/tagv pair
    for (int i = TSDB.metrics_width(); i < tsuid.length; i+= pair_width) {
      if (i + pair_width > tsuid.length){
        throw new IllegalArgumentException(
            "The TSUID appears to be malformed, improper tag width");
      }
      tags.add(Arrays.copyOfRange(tsuid, i, i + pair_width));
    }
    return tags;
  }
949540
@Override
    public MIMETypedStream getExternalContent(ContentManagerParams params)
            throws GeneralException, HttpServiceNotFoundException, RangeNotSatisfiableException {
        logger.debug("in getExternalContent(), url={}", params.getUrl());
        try {
            if(params.getProtocol().equals("file")){
                return getFromFilesystem(params);
            }
            if (params.getProtocol().equals("http") || params.getProtocol().equals("https")){
                return getFromWeb(params);
            }
            throw new GeneralException("protocol for retrieval of external content not supported. URL: " + params.getUrl());
        }
        catch (RangeNotSatisfiableException re) {
        	throw re;
        } catch (Exception ex) {
            // catch anything but generalexception
            ex.printStackTrace();
            throw new HttpServiceNotFoundException("[" + this.getClass().getSimpleName() + "] "
                    + "returned an error.  The underlying error was a "
                    + ex.getClass().getName()
                    + "  The message "
                    + "was  \""
                    + ex.getMessage() + "\"  .  ",ex);
        }
    }
177610
@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        try {
            int mode = MeasureSpec.getMode(heightMeasureSpec);

            if (mode == MeasureSpec.UNSPECIFIED || mode == MeasureSpec.AT_MOST) {
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                int height = 0;
                for (int i = 0; i < getChildCount(); i++) {
                    View child = getChildAt(i);
                    if (child != null) {
                        child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
                        int h = child.getMeasuredHeight();
                        if (h > height) {
                            height = h;
                        }
                    }
                }
                heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
            }

            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        } catch (RuntimeException e) {
            Log.e(TAG, "Exception during WrapContentViewPager onMeasure " + e.toString());
        }
    }