org.apache.http.util.Args Java Examples

The following examples show how to use org.apache.http.util.Args. 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: OrienteerClassLoaderUtil.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
/**
 * Delete artifact jar file
 * @param oArtifact {@link OArtifact} artifact which jar file will be delete
 * @throws IllegalArgumentException if oArtifact is null
 */
public static boolean deleteOArtifactFile(OArtifact oArtifact) {
    Args.notNull(oArtifact, "oArtifact");
    boolean deleted = false;
    try {
        File file = oArtifact.getArtifactReference().getFile();
        if (file != null && file.exists()) {
            File artifactMavenDir = getOArtifactMavenDir(oArtifact);
            if (artifactMavenDir != null) {
                FileUtils.deleteDirectory(artifactMavenDir);
                deleted = true;
                LOG.info("Delete directory in maven repository: {}", artifactMavenDir);
            } else {
                Files.delete(file.toPath());
                deleted = true;
                LOG.info("Delete jar file: {}", file);
            }
        }
    } catch (IOException e) {
        LOG.error("Can't delete jar file of Orienteer module: {}", oArtifact, e);
    }
    return deleted;
}
 
Example #2
Source File: SSLSessionStrategyFactory.java    From apiman with Apache License 2.0 6 votes vote down vote up
private static SSLContextBuilder loadKeyMaterial(SSLContextBuilder builder, File file, char[] ksp,
        char[] kp, PrivateKeyStrategy privateKeyStrategy) throws NoSuchAlgorithmException,
                KeyStoreException, UnrecoverableKeyException, CertificateException, IOException {
    Args.notNull(file, "Keystore file"); //$NON-NLS-1$
    final KeyStore identityStore = KeyStore.getInstance(KeyStore.getDefaultType());
    final FileInputStream instream = new FileInputStream(file);
    try {
        identityStore.load(instream, ksp);
    } finally {
        instream.close();
    }
    return builder.loadKeyMaterial(identityStore, kp, privateKeyStrategy);
}
 
Example #3
Source File: HtmlUnitDomainHandler.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
@Override
public void parse(final SetCookie cookie, final String value)
        throws MalformedCookieException {
    Args.notNull(cookie, HttpHeader.COOKIE);
    if (TextUtils.isBlank(value)) {
        throw new MalformedCookieException("Blank or null value for domain attribute");
    }
    // Ignore domain attributes ending with '.' per RFC 6265, 4.1.2.3
    if (value.endsWith(".")) {
        return;
    }
    String domain = value;
    domain = domain.toLowerCase(Locale.ROOT);

    final int dotIndex = domain.indexOf('.');
    if (browserVersion_.hasFeature(HTTP_COOKIE_REMOVE_DOT_FROM_ROOT_DOMAINS)
            && dotIndex == 0 && domain.length() > 1 && domain.indexOf('.', 1) == -1) {
        domain = domain.toLowerCase(Locale.ROOT);
        domain = domain.substring(1);
    }
    if (dotIndex > 0) {
        domain = '.' + domain;
    }

    cookie.setDomain(domain);
}
 
Example #4
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 #5
Source File: ONotificationTransportFactory.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
public IONotificationTransport create(ODocument document) {
  Args.notNull(document, "document");
  IONotificationTransport transport = null;

  switch (document.getSchemaClass().getName()) {
    case IOMailNotificationTransport.CLASS_NAME:
      transport = DAO.create(IOMailNotificationTransport.class);
      break;
    case IOSmsNotificationTransport.CLASS_NAME:
      transport = DAO.create(IOSmsNotificationTransport.class);
      break;
  }

  if (transport != null) {
    transport.fromStream(document);
  }

  return transport;
}
 
Example #6
Source File: SimpleRedirectStrategy.java    From gerbil with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public boolean isRedirected(final HttpRequest request, final HttpResponse response, final HttpContext context)
        throws ProtocolException {
    Args.notNull(request, "HTTP request");
    Args.notNull(response, "HTTP response");

    final int statusCode = response.getStatusLine().getStatusCode();
    final String method = request.getRequestLine().getMethod();
    final Header locationHeader = response.getFirstHeader("location");
    switch (statusCode) {
    case HttpStatus.SC_MOVED_TEMPORARILY:
        return isRedirectable(method) && locationHeader != null;
    case HttpStatus.SC_MOVED_PERMANENTLY:
    case HttpStatus.SC_TEMPORARY_REDIRECT:
    case 308: // Ensure that HTTP 308 is redirected as well
        return isRedirectable(method);
    case HttpStatus.SC_SEE_OTHER:
        return true;
    default:
        return false;
    } // end of switch
}
 
Example #7
Source File: InputStreamEntity.java    From knox with Apache License 2.0 6 votes vote down vote up
/**
 * Writes bytes from the {@code InputStream} this entity was constructed
 * with to an {@code OutputStream}.  The content length
 * determines how many bytes are written.  If the length is unknown ({@code -1}), the
 * stream will be completely consumed (to the end of the stream).
 */
@Override
public void writeTo(final OutputStream outstream ) throws IOException {
  Args.notNull( outstream, "Output stream" );
  try (InputStream instream = this.content) {
    final byte[] buffer = new byte[OUTPUT_BUFFER_SIZE];
    int l;
    if (this.length < 0) {
      // consume until EOF
      while ((l = instream.read(buffer)) != -1) {
        outstream.write(buffer, 0, l);
      }
    } else {
      // consume no more than length
      long remaining = this.length;
      while (remaining > 0) {
        l = instream.read(buffer, 0, (int) Math.min(OUTPUT_BUFFER_SIZE, remaining));
        if (l == -1) {
          break;
        }
        outstream.write(buffer, 0, l);
        remaining -= l;
      }
    }
  }
}
 
Example #8
Source File: OMetadataUpdater.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
/**
 * Delete list of {@link OArtifact} from metadata.xml
 * @param oArtifacts list of {@link OArtifact} for delete from metadata.xml
 * @throws IllegalArgumentException if oArtifacts is null
 */
@SuppressWarnings("unchecked")
void delete(List<OArtifact> oArtifacts) {
    Args.notNull(oArtifacts, "oArtifacts");
    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);
                OArtifact metadata = containsInModulesConfigsList(dependencyElement, oArtifacts);
                if (metadata != null) {
                    root.removeChild(element);
                }
            }
        }
        saveDocument(document, pathToMetadata);
    }
}
 
Example #9
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 #10
Source File: PomXmlUtils.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
/**
 * Read maven group, artifact, version in xml node <parent></parent>
 * @param pomXml pom.xml for read
 * @return {@link Artifact} with parent's group, artifact, version
 */
Artifact readParentGAVInPomXml(Path pomXml) {
    Args.notNull(pomXml, "pomXml");
    Document doc = readDocumentFromFile(pomXml);
    String expression = String.format("/%s/%s", PROJECT, PARENT);
    NodeList nodeList = executeExpression(expression, doc);
    if (nodeList != null && nodeList.getLength() > 0) {
        Element element = (Element) nodeList.item(0);
        String groupId = element.getElementsByTagName(GROUP).item(0).getTextContent();
        String artifactId = element.getElementsByTagName(ARTIFACT).item(0).getTextContent();
        String version = element.getElementsByTagName(VERSION).item(0).getTextContent();
        if (groupId != null && artifactId != null && version != null)
            return (Artifact) new DefaultArtifact(getGAV(groupId, artifactId, version));
    }

    return null;
}
 
Example #11
Source File: AbstractXmlUtil.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
/**
 * Save {@link Document} document in file system with {@link Path} xml
 * @param document - {@link Document} for save
 * @param xml - {@link Path} for saving document
 * @throws IllegalArgumentException if document or xml is null
 */
protected final void saveDocument(Document document, Path xml) {
    Args.notNull(document, "document");
    Args.notNull(xml, "xml");
    TransformerFactory factory = TransformerFactory.newInstance();
    try {
        Transformer transformer = factory.newTransformer();
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        DOMSource source = new DOMSource(document);
        StreamResult result = new StreamResult(xml.toFile());
        transformer.transform(source, result);
    } catch (TransformerException e) {
        LOG.error("Cannot save document!", e);
    }
}
 
Example #12
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 #13
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 #14
Source File: OMetadataUpdater.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
/**
 * Replace artifactForReplace in metadata.xml by newArtifact
 * @param artifactForReplace - artifact for replace
 * @param newArtifact - new artifact
 * @throws IllegalArgumentException if artifactForReplace or newArtifact is null
 */
@SuppressWarnings("unchecked")
void update(OArtifact artifactForReplace, OArtifact newArtifact) {
    Args.notNull(artifactForReplace, "artifactForUpdate");
    Args.notNull(newArtifact, "newArtifact");
    Document document = readDocumentFromFile(pathToMetadata);
    if (document == null) documentCannotReadException(pathToMetadata);
    NodeList nodeList = executeExpression(ALL_MODULES_EXP, document);
    if (nodeList != null) {
        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);
                OArtifact module = containsInModulesConfigsList(dependencyElement, Lists.newArrayList(artifactForReplace));
                if (module != null) {
                    changeArtifactElement(element, newArtifact);
                    break;
                }
            }
        }
        saveDocument(document, pathToMetadata);
    }
}
 
Example #15
Source File: MetadataUtil.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
/**
 * Update metadata.xml.
 * Search artifactForUpdate in metadata.xml and replace by newArtifact.
 * @param artifactForUpdate {@link OArtifact} for replace.
 * @param newArtifact new {@link OArtifact}.
 * @throws IllegalArgumentException if artifactForUpdate or newArtifact is null.
 */
public void updateOArtifactMetadata(OArtifact artifactForUpdate, OArtifact newArtifact) {
    Args.notNull(artifactForUpdate, "artifactForUpdate");
    Args.notNull(newArtifact, "newArtifactConfig");
    if (!metadataExists()) {
        return;
    }

    OMetadataUpdater updater = new OMetadataUpdater(metadataPath);
    updater.update(artifactForUpdate, newArtifact);
}
 
Example #16
Source File: AetherUtils.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
/**
 * Download artifacts
 * @param artifact {@link Artifact} artifact for download
 * @return {@link Artifact} of downloaded artifact or Optional.absent() if can't download artifact
 * @throws IllegalArgumentException if artifact is null
 */
public Artifact downloadArtifact(Artifact artifact) {
    Args.notNull(artifact, "artifact");
    ArtifactRequest artifactRequest = createArtifactRequest(artifact);
    ArtifactResult result = resolveArtifactRequest(artifactRequest);
    return result != null ? result.getArtifact() : null;
}
 
Example #17
Source File: SSLSessionStrategyFactory.java    From apiman with Apache License 2.0 5 votes vote down vote up
private static SSLContextBuilder loadTrustMaterial(SSLContextBuilder builder, final File file,
        final char[] tsp, final TrustStrategy trustStrategy)
                throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
    Args.notNull(file, "Truststore file"); //$NON-NLS-1$
    final KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
    final FileInputStream instream = new FileInputStream(file);
    try {
        trustStore.load(instream, tsp);
    } finally {
        instream.close();
    }
    return builder.loadTrustMaterial(trustStore, trustStrategy);
}
 
Example #18
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 #19
Source File: GeneratorMode.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public GeneratorMode(String name, Class<? extends IGeneratorStrategy> strategyClass) {
    Args.notEmpty(name, "name");
    Args.notNull(strategyClass, "strategyClass");

    this.name = name;
    this.strategyClass = strategyClass;
}
 
Example #20
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 #21
Source File: OArchitectOProperty.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public OArchitectOProperty(String name, OType type, boolean subClassProperty, String linkedClass) {
    Args.notEmpty(name, "name");
    this.name = name;
    this.type = type;
    this.subClassProperty = subClassProperty;
    this.linkedClass = linkedClass;
}
 
Example #22
Source File: OpenModalWindowEvent.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public OpenModalWindowEvent(AjaxRequestTarget target,
                            IModel<String> titleModel,
                            SerializableFunction<String, Component> contentGenerator
) {
    super(target);
    Args.notNull(titleModel, "titleModel");
    Args.notNull(contentGenerator, "contentGenerator");
    this.titleModel = titleModel;
    this.contentGenerator = contentGenerator;
}
 
Example #23
Source File: HttpProtocol.java    From storm-crawler with Apache License 2.0 5 votes vote down vote up
private static final byte[] toByteArray(final HttpEntity entity,
        int maxContent, MutableBoolean trimmed) throws IOException {

    if (entity == null)
        return new byte[] {};

    final InputStream instream = entity.getContent();
    if (instream == null) {
        return null;
    }
    Args.check(entity.getContentLength() <= Integer.MAX_VALUE,
            "HTTP entity too large to be buffered in memory");
    int reportedLength = (int) entity.getContentLength();
    // set default size for buffer: 100 KB
    int bufferInitSize = 102400;
    if (reportedLength != -1) {
        bufferInitSize = reportedLength;
    }
    // avoid init of too large a buffer when we will trim anyway
    if (maxContent != -1 && bufferInitSize > maxContent) {
        bufferInitSize = maxContent;
    }
    final ByteArrayBuffer buffer = new ByteArrayBuffer(bufferInitSize);
    final byte[] tmp = new byte[4096];
    int lengthRead;
    while ((lengthRead = instream.read(tmp)) != -1) {
        // check whether we need to trim
        if (maxContent != -1 && buffer.length() + lengthRead > maxContent) {
            buffer.append(tmp, 0, maxContent - buffer.length());
            trimmed.setValue(true);
            break;
        }
        buffer.append(tmp, 0, lengthRead);
    }
    return buffer.toByteArray();
}
 
Example #24
Source File: AetherUtils.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
/**
 * Resolve artifact
 * @param artifact {@link Artifact} for resolve its dependencies
 * @return {@link List<ArtifactResult>} of resolved artifact
 * @throws IllegalArgumentException if artifact is null
 */
public List<ArtifactResult> resolveArtifact(Artifact artifact) {
    Args.notNull(artifact, "artifact");
    ArtifactDescriptorRequest descriptorRequest = createArtifactDescriptionRequest(artifact);
    ArtifactDescriptorResult descriptorResult = null;
    try {
        descriptorResult = system.readArtifactDescriptor(session, descriptorRequest);
    } catch (ArtifactDescriptorException e) {
        if (LOG.isDebugEnabled()) LOG.debug(e.getMessage(), e);
    }
    Set<ArtifactRequest> requests = createArtifactRequests(descriptorResult);
    return resolveArtifactRequests(requests);
}
 
Example #25
Source File: Substitute_RestClient.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public void put(final HttpHost host, final AuthScheme authScheme) {
    Args.notNull(host, "HTTP host");
    if (authScheme == null) {
        return;
    }
    this.map.put(getKey(host), authScheme);
}
 
Example #26
Source File: JarUtils.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
/**
 * Search jars in folder
 * @param folder {@link Path} in which will be search
 * @return list of {@link Path} with jars or empty list if jars don't present in folder
 * @throws IllegalArgumentException if folder is null
 */
public List<Path> searchJarsInFolder(Path folder) {
    Args.notNull(folder, "folder");
    return searchJarsInFolder(folder, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".jar");
        }
    });
}
 
Example #27
Source File: AbstractXmlUtil.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
/**
 * Create {@link Document} from {@link Path}
 * @param xml - xml file
 * @return - created {@link Document} or null if can't create {@link Document}
 * @throws IllegalArgumentException if xml is null
 */
protected final Document readDocumentFromFile(Path xml) {
    Args.notNull(xml, "xml");
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
        return factory.newDocumentBuilder().parse(xml.toFile());
    } catch (SAXException | ParserConfigurationException | IOException e) {
        LOG.warn("Can't create document xml! Path: {}", xml.toAbsolutePath(), e);
    }
    return null;
}
 
Example #28
Source File: OMetadataUpdater.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
/**
 * Create new metadata.xml with oArtifacts
 * @param oArtifacts list of {@link OArtifact} for write in metadata.xml
 * @throws IllegalArgumentException if oArtifacts is null
 */
void create(List<OArtifact> oArtifacts) {
    Args.notNull(oArtifacts, "oArtifacts");
    Document document = createNewDocument();
    if (document == null) documentCannotCreateException(pathToMetadata);

    Element root = document.createElement(MetadataTag.METADATA.get());
    document.appendChild(root);
    addArtifacts(oArtifacts, document);
    saveDocument(document, pathToMetadata);
}
 
Example #29
Source File: ReadLogString.java    From docker-java-api with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Check that content length less then Integer.MAX_VALUE.
 * Try to get content length from entity
 * If length less then zero return 4096
 *
 * @param entity HttpEntity for get capacity.
 * @return Capacity.
 */
private int getCapacity(final HttpEntity entity) {
    Args.check(entity.getContentLength() <= Integer.MAX_VALUE,
            "HTTP entity too large to be buffered in memory");
    int capacity = (int) entity.getContentLength();
    if (capacity < 0) {
        capacity = 4096;
    }
    return capacity;
}
 
Example #30
Source File: HttpFluentService.java    From AthenaServing with Apache License 2.0 5 votes vote down vote up
private String executeGet(String url, String hostName, Integer port, String schemeName, Map<String, String> paramMap) {
    Args.notNull(url, "url");

    url = buildGetParam(url, paramMap);
    Request request = Request.Get(url);
    request = buildProxy(request, hostName, port, schemeName);
    try {
        return request.execute().returnContent().asString(Consts.UTF_8);
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e.toString());
    }
    return null;
}