Example usage for java.net URI equals

List of usage examples for java.net URI equals

Introduction

In this page you can find the example usage for java.net URI equals.

Prototype

public boolean equals(Object ob) 

Source Link

Document

Tests this URI for equality with another object.

Usage

From source file:net.javacrumbs.springws.test.simple.WsMockControl.java

/**
 * Expects given uri. If other URI is used, {@link WsTestException} is
 * thrown./*from  w  ww. j a  v a 2  s .co m*/
 * 
 * @param expectedUri
 * @return
 */
public WsMockControl expectUri(final URI expectedUri) {
    RequestProcessor validator = new RequestProcessor() {
        public WebServiceMessage processRequest(URI uri, WebServiceMessageFactory messageFactory,
                WebServiceMessage request) throws IOException {
            if (!uri.equals(expectedUri)) {
                throw new WsTestException("Expected uri " + expectedUri + " but got " + uri);
            }
            return null;
        }
    };
    addRequestProcessor(validator, "expectUri(\"" + expectedUri + "\")");
    return this;
}

From source file:at.bitfire.davdroid.resource.WebDavCollection.java

Resource.AssetDownloader getDownloader() {
    return new Resource.AssetDownloader() {
        @Override//from   ww  w .  j  av  a2  s.  co  m
        public byte[] download(URI uri) throws URISyntaxException, IOException, HttpException, DavException {
            if (!uri.isAbsolute())
                throw new URISyntaxException(uri.toString(), "URI referenced from entity must be absolute");

            // send credentials when asset has same URI authority as baseURI
            // we have to construct these helper URIs because
            // "https://server:443" is NOT equal to "https://server" otherwise
            URI baseUriAuthority = new URI(baseURI.getScheme(), null, baseURI.getHost(), baseURI.getPort(),
                    null, null, null),
                    assetUriAuthority = new URI(uri.getScheme(), null, uri.getHost(), baseURI.getPort(), null,
                            null, null);

            if (baseUriAuthority.equals(assetUriAuthority)) {
                Log.d(TAG, "Asset is on same server, sending credentials");
                WebDavResource file = new WebDavResource(collection, uri);
                file.get("image/*");
                return file.getContent();

            } else
                // resource is on an external server, don't send credentials
                return IOUtils.toByteArray(uri);
        }
    };
}

From source file:net.sf.taverna.t2.activities.wsdl.T2WSDLSOAPInvoker.java

public Map<String, Object> invoke(Map<String, Object> inputMap, JsonNode bean) throws Exception {

    EngineConfiguration wssEngineConfiguration = null;
    if (bean.has("securityProfile")) {
        URI securityProfile = new URI(bean.get("securityProfile").textValue());

        // If security settings require WS-Security and not just e.g. Basic HTTP
        // AuthN - configure the axis engine from the appropriate config strings
        if (securityProfile.equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_PLAINTEXTPASSWORD)) {
            wssEngineConfiguration = new XMLStringProvider(
                    SecurityProfiles.WSSECURITY_USERNAMETOKEN_PLAINTEXTPASSWORD_CONFIG);
        } else if (securityProfile.equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_DIGESTPASSWORD)) {
            wssEngineConfiguration = new XMLStringProvider(
                    SecurityProfiles.WSSECURITY_USERNAMETOKEN_DIGESTPASSWORD_CONFIG);
        } else if (securityProfile
                .equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_PLAINTEXTPASSWORD)) {
            wssEngineConfiguration = new XMLStringProvider(
                    SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_PLAINTETPASSWORD_CONFIG);
        } else if (securityProfile.equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_DIGESTPASSWORD)) {
            wssEngineConfiguration = new XMLStringProvider(
                    SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_DIGESTPASSWORD_CONFIG);
        }//w w w  .  j  a v  a 2  s  .  c o m
    }

    // This does not work
    //      ClassUtils.setClassLoader("net.sf.taverna.t2.activities.wsdl.security.TavernaAxisCustomSSLSocketFactory",TavernaAxisCustomSSLSocketFactory.class.getClassLoader());

    // Setting Axis property only works when we also set the Thread's classloader as below
    // (we do it from the net.sf.taverna.t2.workflowmodel.processor.dispatch.layers.Invoke.requestRun())
    //      Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    if (AxisProperties.getProperty("axis.socketSecureFactory") == null
            || !AxisProperties.getProperty("axis.socketSecureFactory")
                    .equals("net.sf.taverna.t2.activities.wsdl.security.TavernaAxisCustomSSLSocketFactory")) {
        AxisProperties.setProperty("axis.socketSecureFactory",
                "net.sf.taverna.t2.activities.wsdl.security.TavernaAxisCustomSSLSocketFactory");
        logger.info("Setting axis.socketSecureFactory property to "
                + AxisProperties.getProperty("axis.socketSecureFactory"));
    }

    // This also does not work
    //AxisProperties.setClassDefault(SecureSocketFactory.class, "net.sf.taverna.t2.activities.wsdl.security.TavernaAxisCustomSSLSocketFactory");

    Call call = super.getCall(wssEngineConfiguration);

    // Now that we have an axis Call object, configure any additional
    // security properties on it (or its message context or its Transport
    // handler),
    // such as WS-Security UsernameToken or HTTP Basic AuthN
    if (bean.has("securityProfile")) {
        configureSecurity(call, bean);
    }

    return invoke(inputMap, call);
}

From source file:com.bt.sdk.callcontrol.demo.standup.StandupBeanImpl.java

public void runStandup(List<URI> participants) {
    print(String.format("Trying to run standup with %d participants", participants.size()));
    final String confId = conferenceBean.createConference();
    conferenceId = confId;//from w  w  w . j  av a 2s  .  c  o  m
    URI inboundParticipant = getInboundParticipantAtRandom(participants);
    for (final URI participant : participants) {
        final String participantDialogId = outboundCallLegBean.createCallLeg(fromURI, participant);

        Runnable participantThread = null;
        if (participant.equals(inboundParticipant)) {
            participantThread = new Runnable() {
                public void run() {
                    try {
                        processParticipantInformInbound(confId, participantDialogId);
                    } catch (Exception e) {
                        log.error(String.format("Error when processing participant %s: %s",
                                participant.toString(), e.getMessage()));
                    }
                }
            };
        } else {
            participantThread = new Runnable() {
                public void run() {
                    try {
                        processParticipant(confId, participantDialogId);
                    } catch (Exception e) {
                        log.error(String.format("Error when processing participant %s: %s",
                                participant.toString(), e.getMessage()));
                    }
                }
            };
        }
        new Thread(participantThread).start();
    }
}

From source file:com.unboundid.scim2.client.ScimService.java

/**
 * Resolve a URL (relative or absolute) to a web target.
 *
 * @param url The URL to resolve./*from  ww w. jav a 2  s .  c o  m*/
 * @return The WebTarget.
 */
private WebTarget resolveWebTarget(final URI url) {
    URI relativePath;
    if (url.isAbsolute()) {
        relativePath = baseTarget.getUri().relativize(url);
        if (relativePath.equals(url)) {
            // The given resource's location is from another service provider
            throw new IllegalArgumentException("Given resource's location " + url
                    + " is not under this service's " + "base path " + baseTarget.getUri());
        }
    } else {
        relativePath = url;
    }

    return baseTarget.path(relativePath.getRawPath());
}

From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceImpl.java

private OwncloudRestResourceExtension createOwncloudResourceFrom(DavResource davResource,
        OwncloudResourceConversionProperties conversionProperties) {
    log.debug("Create OwncloudResource based on DavResource {}", davResource.getHref());
    MediaType mediaType = MediaType.valueOf(davResource.getContentType());
    URI rootPath = conversionProperties.getRootPath();
    URI href = rootPath.resolve(davResource.getHref());
    String name = davResource.getName();
    if (davResource.isDirectory() && href.equals(rootPath)) {
        name = SLASH;/*from   ww w .ja  va 2  s . co m*/
    }
    LocalDateTime lastModifiedAt = LocalDateTime.ofInstant(davResource.getModified().toInstant(),
            ZoneId.systemDefault());
    href = rootPath.relativize(href);
    href = URI.create(SLASH).resolve(href).normalize(); // prepend "/" to the href
    OwncloudRestResourceExtension owncloudResource = OwncloudRestResourceImpl.builder().href(href).name(name)
            .lastModifiedAt(lastModifiedAt).mediaType(mediaType)
            .eTag(StringUtils.strip(davResource.getEtag(), QUOTE)).build();
    if (davResource.isDirectory()) {
        return owncloudResource;
    }
    return OwncloudRestFileResourceImpl.fileBuilder().owncloudResource(owncloudResource)
            .contentLength(davResource.getContentLength()).build();
}

From source file:org.sakaiproject.kernel.component.core.Maven2ArtifactResolver.java

/**
 * {@inheritDoc}//ww  w.  j  a v  a  2 s .co  m
 *
 * @throws ComponentSpecificationException
 *
 * @see org.sakaiproject.kernel.api.ArtifactResolverService#resolve(java.net.URL[],
 *      org.sakaiproject.kernel.api.Artifact)
 */
public URL resolve(URL[] urls, Artifact classpathDependency) throws ComponentSpecificationException {
    String groupId = classpathDependency.getGroupId().replace('.', File.separatorChar);
    String artifactId = classpathDependency.getArtifactId();
    String version = classpathDependency.getVersion();
    if (version == null || version.trim().length() == 0 || groupId == null || groupId.trim().length() == 0
            || artifactId == null || artifactId.trim().length() == 0) {
        throw new ComponentSpecificationException("GroupId, ArtifactId and Version must all be specified on "
                + "dependencies that are resolved GroupId=" + groupId + " Artifact=" + artifactId + " Version="
                + version);
    }
    groupId = groupId.trim();
    artifactId = artifactId.trim();
    version = version.trim();
    String type = classpathDependency.getType();
    if (type == null || type.trim().length() == 0) {
        type = "jar";
    }
    type = type.trim();

    String classifier = classpathDependency.getClassifier();
    if (classifier != null && classifier.trim().length() > 0) {
        classifier = "-" + classifier.trim();
    } else {
        classifier = "";
    }

    File resource = new File(new File(new File(groupId, artifactId), version),
            artifactId + "-" + version + classifier + "." + type);
    File localResource = new File(repo, resource.getPath());
    if (!localResource.exists()) {
        throw new ComponentSpecificationException("Resource does not exist locally " + classpathDependency
                + " resloved as " + localResource.getAbsolutePath());
    }

    URI ui = localResource.toURI();
    if ((urls != null) && (ui != null)) {
        URI cui = null;
        for (URL clu : urls) {
            try {
                cui = clu.toURI();
            } catch (URISyntaxException e) {
                throw new ComponentSpecificationException("Unable to create URI for  " + clu.toString()
                        + " in urls while resolving " + classpathDependency, e);
            }
            if (ui.equals(cui)) {
                return null;
            }
        }
    }

    URL u = null;
    try {
        u = ui.toURL();
    } catch (MalformedURLException e) {
        throw new ComponentSpecificationException("Unable to create URL for  " + classpathDependency, e);
    }
    return u;
}

From source file:org.xwiki.contrib.oidc.provider.internal.store.OIDCStore.java

public OIDCConsent getConsent(DocumentReference userReference, ClientID clientID, URI redirectURI)
        throws XWikiException {
    XWikiContext xcontext = this.xcontextProvider.get();

    XWikiDocument userDocument = xcontext.getWiki().getDocument(userReference, xcontext);
    for (OIDCConsent consent : (List<OIDCConsent>) (List) userDocument.getXObjects(OIDCConsent.REFERENCE)) {
        if (consent != null) {
            if (clientID.equals(consent.getClientID())
                    && (redirectURI == null || redirectURI.equals(consent.getRedirectURI()))) {
                return consent;
            }// w  w  w .  j  a v  a2 s.  c  om
        }
    }

    return null;
}

From source file:org.objectweb.proactive.core.remoteobject.RemoteObjectSet.java

private void writeObject(ObjectOutputStream out) throws IOException {
    // Almost same as in term of speed UniqueID.getCurrentVMID() but more readable
    this.vmid = ProActiveRuntimeImpl.getProActiveRuntime().getVMInformation().getVMID();
    out.defaultWriteObject();/*from w  w w . java2  s .  c o  m*/
    out.writeInt(rros.size());

    // write the default protocol
    writeProtocol(out, defaultURI, defaultRO);

    // write all other protocols
    for (URI uri : initialorder) {
        if (!uri.equals(defaultURI)) {
            writeProtocol(out, uri, rros.get(uri));
        }
    }
}

From source file:org.entrystore.harvesting.oaipmh.jobs.ListRecordsJob.java

public void createEntry(Context context, Element recordElement, String target, String metadataType)
        throws XPathExpressionException {
    String identifier = getIdentifier(recordElement);
    String datestamp = getDatestamp(recordElement);

    if (identifier == null) {
        return;/* w  w  w .j  a v a2s. com*/
    }

    // workaround for bad installations not using oai_lom
    if ("lom".equalsIgnoreCase(metadataType)) {
        metadataType = "oai_lom";
    }

    // We use OpenRDF URI and Java URI, they do different validity checks,
    // and we need it to work in both.
    // We can create a Reference without a resource URI, but not without a
    // metadata URI, therefore we return only in the case of an invalid
    // metadata URI.
    //
    // Before you touch any of the code down there, think twice!

    org.openrdf.model.URI openrdfEntryResourceURI = null;
    try {
        String resourceIdentifier = getResourceIdentifier(recordElement, metadataType);
        if (resourceIdentifier == null) {
            log.warn("Resource identifier is null, skipping resource");
            return;
        }
        openrdfEntryResourceURI = vf.createURI(resourceIdentifier);
    } catch (IllegalArgumentException e) {
        log.error("Skipping this record, no proper resource URI found: " + e.getMessage());
        return;
    }
    org.openrdf.model.URI openrdfEntryMetadataURI = null;
    try {
        openrdfEntryMetadataURI = vf.createURI(
                target + "?verb=GetRecord&identifier=" + identifier + "&metadataPrefix=" + metadataType);
    } catch (IllegalArgumentException e) {
        log.error("Illegal external metadata URI, not creating entry: " + e.getMessage());
        return;
    }

    URI entryResourceURI = null;
    if (openrdfEntryResourceURI != null) {
        try {
            entryResourceURI = new URI(openrdfEntryResourceURI.toString());
        } catch (URISyntaxException e) {
            log.error(e.getMessage());
        }
    }
    URI entryMetadataURI = null;
    if (openrdfEntryMetadataURI != null) {
        try {
            entryMetadataURI = new URI(openrdfEntryMetadataURI.toString());
        } catch (URISyntaxException e) {
            log.error("Illegal external metadata URI, not creating entry: " + e.getMessage());
            return;
        }
    } else {
        log.error("Illegal external metadata URI, not creating entry");
        return;
    }

    Set<Entry> entries = context.getByExternalMdURI(entryMetadataURI);

    // if there are no old entries
    if (entries.isEmpty()) {
        Graph g = getExternalMetadataGraphFromXML(recordElement, metadataType, entryResourceURI);
        if (g != null) {
            Entry entry = context.createReference(null, entryResourceURI, entryMetadataURI, null);
            setCachedMetadataGraph(entry, g);
            log.info("Added entry " + entry.getEntryURI() + " with resource " + entryResourceURI
                    + " and metadata " + entryMetadataURI);
        } else {
            log.error("Unable to extract metadata from XML for " + entryMetadataURI);
        }
    } else {
        if (!replaceMetadata) {
            log.info("Cached metadata exists, but harvester is configured to not replace it");
        } else {
            // update old cached external metadata when reharvesting
            Iterator<Entry> eIt = entries.iterator();
            if (eIt.hasNext()) {
                Entry entry = eIt.next();
                if (!entry.getResourceURI().equals(entryResourceURI)) {
                    log.info(entry.getEntryURI() + ": setting new resource URI: " + entryResourceURI);
                    if (entryResourceURI != null) {
                        entry.setResourceURI(entryResourceURI);
                    } else {
                        log.warn("New resource URI is null, no changes applied");
                    }
                }

                URI extMdURI = entry.getExternalMetadataURI();
                if (!extMdURI.equals(entryMetadataURI)) {
                    log.warn(
                            "New external metadata URI for " + entry.getEntryURI() + " is " + entryMetadataURI);
                    if (entryMetadataURI != null) {
                        entry.setExternalMetadataURI(entryMetadataURI);
                    }
                }
                log.info("Setting new cached external metadata on " + entry.getEntryURI());
                setCachedMetadataGraph(entry,
                        getExternalMetadataGraphFromXML(recordElement, metadataType, entry.getResourceURI()));
            }
        }

        //         Iterator<Entry> iter = entries.iterator();
        //         while(iter.hasNext()) {
        //            entry = iter.next(); 
        //            String entryURIString = entry.getEntryURI().toString();
        //            int indexDateStamp = entryURIString.lastIndexOf("=");
        //            String datestampOld = entryURIString.substring(indexDateStamp+1); 
        //            if (datestamp.equals(datestampOld)) {
        //               // just update modified in the entry since the metadata is the same.
        //               entry.getCachedExternalMetadata().setGraph(entry.getCachedExternalMetadata().getGraph());
        //            } else {
        //               // new metadata must be harvested and cached.
        //               // setCachedMetadataGraph(entry, recordElement, metadataType);
        //            }
        //         }
    }
}