Java Code Examples for org.apache.http.util.Args#notNull()

The following examples show how to use org.apache.http.util.Args#notNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractXmlUtil.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
/**
 * Execute XPath expression
 * @param expression - {@link String} expression for execute
 * @param document {@link Document} in which expression will execute
 * @return {@link NodeList} with result or null if can't execute expression.
 * @throws IllegalArgumentException if expression or document is null
 */
protected final NodeList executeExpression(String expression, Document document) {
    Args.notNull(expression, "expression");
    Args.notNull(document, "document");
    XPath xPath = XPathFactory.newInstance().newXPath();
    try {
        return (NodeList) xPath.compile(expression).evaluate(document, XPathConstants.NODESET);
    } catch (XPathExpressionException e) {
        LOG.warn("Can't execute search query: {},", expression , e);
    }
    return null;
}
 
Example 2
Source File: OMetadataUpdater.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
/**
 * Delete oArtifact from metadata.xml
 * @param oArtifact {@link OArtifact} for delete from metadata.xml
 * @throws IllegalArgumentException if oArtifact is null
 */
@SuppressWarnings("unchecked")
void delete(OArtifact oArtifact) {
    Args.notNull(oArtifact, "oArtifact");
    Document document = readDocumentFromFile(pathToMetadata);
    if (document == null) documentCannotReadException(pathToMetadata);
    NodeList nodeList = executeExpression(ALL_MODULES_EXP, document);

    if (nodeList != null) {
        Element root = document.getDocumentElement();
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element element = (Element) node;
                Element dependencyElement = (Element) element.getElementsByTagName(MetadataTag.DEPENDENCY.get()).item(0);
                if (isNecessaryElement(dependencyElement, oArtifact)) {
                    root.removeChild(element);
                    break;
                }
            }
        }
        saveDocument(document, pathToMetadata);
    }
}
 
Example 3
Source File: OMetadataTest.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
private static void testArtifact(OArtifact expected, OArtifact actual) {
    Args.notNull(expected, "expected");
    Args.notNull(actual, "actual");
    assertEquals("test artifact load", expected.isLoad(), actual.isLoad());
    assertEquals("test artifact trusted", expected.isTrusted(), actual.isTrusted());
    assertEquals("test artifact groupId", expected.getArtifactReference().getGroupId(),
            actual.getArtifactReference().getGroupId());
    assertEquals("test artifact artifactId", expected.getArtifactReference().getArtifactId(),
            actual.getArtifactReference().getArtifactId());
    assertEquals("test artifact version", expected.getArtifactReference().getVersion(),
            actual.getArtifactReference().getVersion());
    assertEquals("test artifact jar files", expected.getArtifactReference().getFile().getAbsoluteFile(),
            actual.getArtifactReference().getFile().getAbsoluteFile());
    assertEquals("test artifact descriptions", expected.getArtifactReference().getDescription(),
            actual.getArtifactReference().getDescription());
}
 
Example 4
Source File: JarUtils.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
/**
 * Search pom.xml if jar file
 * @param path {@link Path} of jar file
 * @return {@link Path} of pom.xml or Optional.absent() if pom.xml is not present
 * @throws IllegalArgumentException if path is null
 */
public Path getPomFromJar(Path path) {
    Args.notNull(path, "path");
    Path result = null;
    try {
        JarFile jarFile = new JarFile(path.toFile());
        Enumeration<JarEntry> entries = jarFile.entries();
        while (entries.hasMoreElements()) {
            JarEntry jarEntry = entries.nextElement();
            if (jarEntry.getName().endsWith("pom.xml")) {
                result = unarchivePomFile(jarFile, jarEntry);
                break;
            }
        }
        jarFile.close();
    } catch (IOException e) {
        if (LOG.isDebugEnabled()) {
            LOG.error("Cannot open file to read. File: " + path.toAbsolutePath(), e);
        }
    }
    return result;
}
 
Example 5
Source File: OMetadataUpdater.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
/**
 * Update metadata.xml.
 * oArtifacts will be write to metadata.xml or will be update its flag load or trusted.
 * @param oArtifacts list of {@link OArtifact} for update
 * @param updateJar true - jar will be update
 *                  false - jar will not be update
 * @throws IllegalArgumentException if oArtifacts is null
 */
@SuppressWarnings("unchecked")
void update(List<OArtifact> oArtifacts, boolean updateJar) {
    Args.notNull(oArtifacts, "oArtifacts");
    Document document = readDocumentFromFile(pathToMetadata);
    if (document == null) documentCannotReadException(pathToMetadata);

    NodeList nodeList = executeExpression(ALL_MODULES_EXP, document);
    List<OArtifact> updatedModules = Lists.newArrayList();
    if (nodeList != null) {
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node.getNodeType() == Element.ELEMENT_NODE) {
                Element element = (Element) node;
                Element dependencyElement = (Element) element.getElementsByTagName(MetadataTag.DEPENDENCY.get()).item(0);
                OArtifact oArtifact = containsInModulesConfigsList(dependencyElement, oArtifacts);
                if (oArtifact != null) {
                    if (updateJar) {
                        changeoArtifactsLoadAndJar(element, oArtifact);
                    } else changeArtifactElement(element, oArtifact);
                    updatedModules.add(oArtifact);
                }
            }
        }
    }
    if (updatedModules.size() != oArtifacts.size()) {
        addArtifacts(difference(updatedModules, oArtifacts), document);
    }
    saveDocument(document, pathToMetadata);
}
 
Example 6
Source File: OrienteerClassLoaderUtil.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
/**
 * Resolve artifacts. Download its dependencies
 * @param artifacts {@link Set} for resolve
 * @return {@link List} resolved dependencies of artifacts
 * @throws IllegalArgumentException if artifacts is null
 */
public static List<Artifact> resolveArtifacts(List<Artifact> artifacts) {
    Args.notNull(artifacts, "artifacts");
    List<Artifact> result = Lists.newArrayList();
    for (Artifact artifact : artifacts) {
        result.addAll(resolveAndGetArtifactDependencies(artifact));
    }
    return result;
}
 
Example 7
Source File: AbstractRoutePlanner.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public HttpRoute determineRoute(final HttpHost host, final HttpRequest request, final HttpContext context) throws HttpException {
  Args.notNull(request, "Request");
  if (host == null) {
    throw new ProtocolException("Target host is not specified");
  }
  final HttpClientContext clientContext = HttpClientContext.adapt(context);
  final RequestConfig config = clientContext.getRequestConfig();
  int remotePort;
  if (host.getPort() <= 0) {
    try {
      remotePort = schemePortResolver.resolve(host);
    } catch (final UnsupportedSchemeException e) {
      throw new HttpException(e.getMessage());
    }
  } else
    remotePort = host.getPort();

  final Tuple<Inet4Address, Inet6Address> remoteAddresses = IpAddressTools.getRandomAddressesFromHost(host);
  final Tuple<InetAddress, InetAddress> addresses = determineAddressPair(remoteAddresses);

  final HttpHost target = new HttpHost(addresses.r, host.getHostName(), remotePort, host.getSchemeName());
  final HttpHost proxy = config.getProxy();
  final boolean secure = target.getSchemeName().equalsIgnoreCase("https");
  clientContext.setAttribute(CHOSEN_IP_ATTRIBUTE, addresses.l);
  log.debug("Setting route context attribute to {}", addresses.l);
  if (proxy == null) {
    return new HttpRoute(target, addresses.l, secure);
  } else {
    return new HttpRoute(target, addresses.l, proxy, secure);
  }
}
 
Example 8
Source File: AetherUtils.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
/**
 * Download artifacts
 * @param artifacts {@link Set<Artifact>} artifacts for download
 * @return {@link List<Artifact>} of resolved artifact
 * @throws IllegalArgumentException if artifacts is null
 */
public List<Artifact> downloadArtifacts(Set<Artifact> artifacts) {
    Args.notNull(artifacts, "artifacts");
    Set<ArtifactRequest> artifactRequests = createArtifactRequests(artifacts);
    List<ArtifactResult> artifactResults = resolveArtifactRequests(artifactRequests);
    List<Artifact> result = Lists.newArrayList();
    for (ArtifactResult res : artifactResults) {
        result.add(res.getArtifact());
    }
    return result;
}
 
Example 9
Source File: NIdleConnectionEvictor.java    From httpclientutil with Apache License 2.0 4 votes vote down vote up
public NIdleConnectionEvictor setConnMgr(final NHttpClientConnectionManager connMgr){
    this.connMgr = Args.notNull(connMgr, "Connection manager");    	
    return this;
}
 
Example 10
Source File: Objects.java    From tokens with Apache License 2.0 4 votes vote down vote up
public static <T> T notNull(String name, T object) {
	return Args.notNull(object, name);
}
 
Example 11
Source File: NIdleConnectionEvictor.java    From httpclientutil with Apache License 2.0 4 votes vote down vote up
public void start() {
	Args.notNull(connMgr, "Connection manager");
    thread.start();
}
 
Example 12
Source File: MultipartEntityBuilder.java    From iaf with Apache License 2.0 4 votes vote down vote up
public MultipartEntityBuilder addPart(String name, ContentBody contentBody) {
	Args.notNull(name, "Name");
	Args.notNull(contentBody, "Content body");
	return addPart(FormBodyPartBuilder.create(name, contentBody).build());
}
 
Example 13
Source File: BasicAuthCacheAlias.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
@Substitute
@Override
public AuthScheme get(final HttpHost host) {
    Args.notNull(host, "HTTP host");
    return this.map.get(getKey(host));
}
 
Example 14
Source File: OrienteerClassLoaderUtil.java    From Orienteer with Apache License 2.0 2 votes vote down vote up
/**
 * Download artifacts
 * @param artifacts {@link Set} for download
 * @return {@link List} of downloaded artifacts
 * @throws IllegalArgumentException if artifacts is null
 */
public static List<Artifact> downloadArtifacts(Set<Artifact> artifacts) {
    Args.notNull(artifacts, "artifacts");
    return aetherUtils.downloadArtifacts(artifacts);
}
 
Example 15
Source File: OrienteerClassLoaderUtil.java    From Orienteer with Apache License 2.0 2 votes vote down vote up
/**
 * Update or create oArtifacts in metadata.xml
 * @param oArtifacts {@link List} for update or create in metadata.xml
 * @throws IllegalArgumentException if oArtifacts is null
 */
public static void updateOArtifactsInMetadata(List<OArtifact> oArtifacts) {
    Args.notNull(oArtifacts, "oArtifacts");
    metadataUtil.updateOArtifactsMetadata(oArtifacts);
}
 
Example 16
Source File: OrienteerClassLoaderUtil.java    From Orienteer with Apache License 2.0 2 votes vote down vote up
/**
 * Create {@link OArtifact} from jar file
 * @param pathToJar {@link Path} of jar file
 * @return {@link OArtifact} of artifact or Optional.absent() if artifact is not present in jar file
 * @throws IllegalArgumentException if pathToJar is null
 */
public static OArtifact getOArtifactFromJar(Path pathToJar) {
    Args.notNull(pathToJar, "pathToJar");
    return MavenResolver.get().getOArtifact(pathToJar);
}
 
Example 17
Source File: OMetadataUpdater.java    From Orienteer with Apache License 2.0 2 votes vote down vote up
/**
 * Update jar for oArtifact in metadata.xml
 * @param oArtifact {@link OArtifact} for update
 * @param updateJar true - jar will be update
 *                  false - jar will not be update
 * @throws IllegalArgumentException if oArtifact is null
 */
void update(OArtifact oArtifact, boolean updateJar) {
    Args.notNull(oArtifact, "oArtifact");
    update(Lists.newArrayList(oArtifact), updateJar);
}
 
Example 18
Source File: OrienteerClassLoaderUtil.java    From Orienteer with Apache License 2.0 2 votes vote down vote up
/**
 * Search pom.xml in jar file
 * @param pathToJar {@link Path} of jar file
 * @return {@link Path} of pom.xml or Optional.absent() if pom.xml is not present in jar file
 * @throws IllegalArgumentException if pathToJar is null
 */
public static Path getPomFromJar(Path pathToJar) {
    Args.notNull(pathToJar, "pathToJar");
    return jarUtils.getPomFromJar(pathToJar);
}
 
Example 19
Source File: OMetadataReader.java    From Orienteer with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor
 * @param pathToMetadata {@link Path} of metadata.xml
 * @throws IllegalArgumentException if pathToMetadata is null
 */
OMetadataReader(Path pathToMetadata) {
    Args.notNull(pathToMetadata, "pathToMetadata");
    this.pathToMetadata = pathToMetadata;
}
 
Example 20
Source File: OMetadataUpdater.java    From Orienteer with Apache License 2.0 2 votes vote down vote up
/**
 * Update metadata.xml
 * @param oArtifact - {@link OArtifact} for update in metadata.xml
 * @throws IllegalArgumentException if oArtifact is null
 */
void update(OArtifact oArtifact) {
    Args.notNull(oArtifact, "oArtifact");
    update(oArtifact, false);
}