问:
Deploying Maven dependencies to S3: No connector available
I'm trying to use Amazon S3 to host my Maven artifacts. I've added the following to my pom.xml:

<distributionManagement>
    <repository>
        <id>maven.xxx.com-release</id>
        <name>AWS S3 Release Repository</name>
        <url>s3://maven.xxx.com/release</url>
    </repository>
    <snapshotRepository>
        <id>maven.xxx.com-snapshot</id>
        <name>AWS S3 Snapshot Repository</name>
        <url>s3://maven.xxx.com/snapshot</url>
    </snapshotRepository>
</distributionManagement>

<build>
    <extensions>
        <extension>
            <groupId>org.springframework.build</groupId>
            <artifactId>aws-maven</artifactId>
            <version>5.0.0.RELEASE</version>
        </extension>
    </extensions>
</build>
```

<p>This is working fine and my snapshot is stored on S3. Now I'm trying to reference the artifact in another project:</p>

<pre class="lang-xml prettyprint-override"><code><repositories>
    <repository>
        <id>maven.xxx.com-release</id>
        <name>AWS S3 Release Repository</name>
        <url>s3://maven.xxx.com/release</url>
    </repository>
    <repository>
        <id>maven.xxx.com-snapshot</id>
        <name>AWS S3 Snapshot Repository</name>
        <url>s3://maven.xxx.com/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

<build>
    <extensions>
        <extension>
            <groupId>org.springframework.build</groupId>
            <artifactId>aws-maven</artifactId>
            <version>5.0.0.RELEASE</version>
        </extension>
    </extensions>
</build>
</code>```

When I run $ mvn deploy -X, I get the following error:

Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T15:51:42+02:00)
Maven home: /usr/local/Cellar/maven/3.2.2/libexec
Java version: 1.8.0_11, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.4", arch: "x86_64", family: "mac"
[INFO] Error stacktraces are turned on.
[DEBUG] Reading global settings from /usr/local/Cellar/maven/3.2.2/libexec/conf/settings.xml
[DEBUG] Reading user settings from /Users/philipp/.m2/settings.xml
[DEBUG] Using local repository at /Users/philipp/.m2/repository
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for /Users/philipp/.m2/repository
[INFO] Scanning for projects...
[DEBUG] Skipped remote update check for com.xxx:parent-pom:1.4.11-SNAPSHOT/maven-metadata.xml, locally installed metadata up-to-date.
[DEBUG] Skipped remote update check for com.xxx:parent-pom:1.4.11-SNAPSHOT/maven-metadata.xml, locally installed metadata up-to-date.
[DEBUG] Skipped remote update check for com.xxx:parent-pom:1.4.11-SNAPSHOT/maven-metadata.xml, locally installed metadata up-to-date.
[DEBUG] java.util.NoSuchElementException
      role: org.apache.maven.wagon.Wagon
  roleHint: s3
org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException
      role: org.apache.maven.wagon.Wagon
  roleHint: s3
    at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:264)
    at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:252)
    at org.eclipse.aether.internal.connector.wagon.PlexusWagonProvider.lookup(PlexusWagonProvider.java:33)
    at org.eclipse.aether.connector.wagon.WagonRepositoryConnector.lookupWagon(WagonRepositoryConnector.java:337)
    at org.eclipse.aether.connector.wagon.WagonRepositoryConnector.<init>(WagonRepositoryConnector.java:157)
    at org.eclipse.aether.connector.wagon.WagonRepositoryConnectorFactory.newInstance(WagonRepositoryConnectorFactory.java:159)
    at org.eclipse.aether.internal.impl.DefaultRepositoryConnectorProvider.newRepositoryConnector(DefaultRepositoryConnectorProvider.java:139)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:531)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:436)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:262)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:239)
    at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveArtifact(DefaultRepositorySystem.java:295)
    at org.apache.maven.project.ProjectModelResolver.resolveModel(ProjectModelResolver.java:171)
    at org.apache.maven.project.ProjectModelResolver.resolveModel(ProjectModelResolver.java:224)
    at org.apache.maven.model.building.DefaultModelBuilder.readParentExternally(DefaultModelBuilder.java:903)
    at org.apache.maven.model.building.DefaultModelBuilder.readParent(DefaultModelBuilder.java:755)
    at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:309)
    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:452)
    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:421)
    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:385)
    at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:663)
    at org.apache.maven.DefaultMaven.getProjectsForMavenReactor(DefaultMaven.java:654)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:243)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.util.NoSuchElementException
    at org.eclipse.sisu.plexus.RealmFilter$FilteredItr.next(RealmFilter.java:118)
    at org.eclipse.sisu.plexus.RealmFilter$FilteredItr.next(RealmFilter.java:1)
    at org.eclipse.sisu.plexus.DefaultPlexusBeans$Itr.next(DefaultPlexusBeans.java:76)
    at org.eclipse.sisu.plexus.DefaultPlexusBeans$Itr.next(DefaultPlexusBeans.java:1)
    at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:260)
    ... 34 more
[DEBUG] Writing tracking file /Users/philipp/.m2/repository/com/xxx/parent-pom/1.4.11-SNAPSHOT/parent-pom-1.4.11-20140722.193312-1.pom.lastUpdated
[ERROR] The build could not read 1 project -> [Help 1]
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM com.xxx:parent-pom:1.4.11-SNAPSHOT: Could not transfer artifact com.xxx:parent-pom:pom:1.4.11-20140722.193312-1 from/to maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot): No connector available to access repository maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot) of type default using the available factories WagonRepositoryConnectorFactory and 'parent.relativePath' points at wrong local POM @ line 9, column 10

    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:405)
    at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:663)
    at org.apache.maven.DefaultMaven.getProjectsForMavenReactor(DefaultMaven.java:654)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:243)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[ERROR]
[ERROR]   The project com.xxx:base:1.3.2-SNAPSHOT (/Users/philipp/Documents/IntelliJ/base/pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM com.xxx:parent-pom:1.4.11-SNAPSHOT: Could not transfer artifact com.xxx:parent-pom:pom:1.4.11-20140722.193312-1 from/to maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot): No connector available to access repository maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot) of type default using the available factories WagonRepositoryConnectorFactory and 'parent.relativePath' points at wrong local POM @ line 9, column 10 -> [Help 2]
org.apache.maven.model.resolution.UnresolvableModelException: Could not transfer artifact com.xxx:parent-pom:pom:1.4.11-20140722.193312-1 from/to maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot): No connector available to access repository maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot) of type default using the available factories WagonRepositoryConnectorFactory
    at org.apache.maven.project.ProjectModelResolver.resolveModel(ProjectModelResolver.java:175)
    at org.apache.maven.project.ProjectModelResolver.resolveModel(ProjectModelResolver.java:224)
    at org.apache.maven.model.building.DefaultModelBuilder.readParentExternally(DefaultModelBuilder.java:903)
    at org.apache.maven.model.building.DefaultModelBuilder.readParent(DefaultModelBuilder.java:755)
    at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:309)
    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:452)
    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:421)
    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:385)
    at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:663)
    at org.apache.maven.DefaultMaven.getProjectsForMavenReactor(DefaultMaven.java:654)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:243)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Could not transfer artifact com.xxx:parent-pom:pom:1.4.11-20140722.193312-1 from/to maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot): No connector available to access repository maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot) of type default using the available factories WagonRepositoryConnectorFactory
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:459)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:262)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:239)
    at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveArtifact(DefaultRepositorySystem.java:295)
    at org.apache.maven.project.ProjectModelResolver.resolveModel(ProjectModelResolver.java:171)
    ... 22 more
Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact com.xxx:parent-pom:pom:1.4.11-20140722.193312-1 from/to maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot): No connector available to access repository maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot) of type default using the available factories WagonRepositoryConnectorFactory
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:546)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:436)
    ... 26 more
Caused by: org.eclipse.aether.transfer.NoRepositoryConnectorException: No connector available to access repository maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot) of type default using the available factories WagonRepositoryConnectorFactory
    at org.eclipse.aether.internal.impl.DefaultRepositoryConnectorProvider.newRepositoryConnector(DefaultRepositoryConnectorProvider.java:193)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:531)
    ... 27 more
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
```

Could not transfer artifact com.xxx:parent-pom:pom:1.4.11-20140722.193312-1 from/to maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot): No connector available to access repository maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot) of type default using the available factories WagonRepositoryConnectorFactory and 'parent.relativePath' points at wrong local POM

So I can write artifacts (the credentials are obviously correct) but not read them? I must be overlooking something simple, but I can't really find it.

答:
If like me you're getting this message due to using a remote parent POM and Maven trying to load it before adding extensions (and therefore not being able to read s3://), see https://github.com/spring-projects/aws-maven/issues/25#issuecomment-112031441.

Doing this fixes it for me and allows me to keep parent remote and have maven still resolve it via s3 url and IAM permissions.

Body:
I'm trying to use Amazon S3 to host my Maven artifacts. I've added the following to my pom.xml:

<distributionManagement>
    <repository>
        <id>maven.xxx.com-release</id>
        <name>AWS S3 Release Repository</name>
        <url>s3://maven.xxx.com/release</url>
    </repository>
    <snapshotRepository>
        <id>maven.xxx.com-snapshot</id>
        <name>AWS S3 Snapshot Repository</name>
        <url>s3://maven.xxx.com/snapshot</url>
    </snapshotRepository>
</distributionManagement>

<build>
    <extensions>
        <extension>
            <groupId>org.springframework.build</groupId>
            <artifactId>aws-maven</artifactId>
            <version>5.0.0.RELEASE</version>
        </extension>
    </extensions>
</build>

This is working fine and my snapshot is stored on S3. Now I'm trying to reference the artifact in another project:

<repositories>
    <repository>
        <id>maven.xxx.com-release</id>
        <name>AWS S3 Release Repository</name>
        <url>s3://maven.xxx.com/release</url>
    </repository>
    <repository>
        <id>maven.xxx.com-snapshot</id>
        <name>AWS S3 Snapshot Repository</name>
        <url>s3://maven.xxx.com/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

<build>
    <extensions>
        <extension>
            <groupId>org.springframework.build</groupId>
            <artifactId>aws-maven</artifactId>
            <version>5.0.0.RELEASE</version>
        </extension>
    </extensions>
</build>

When I run $ mvn deploy -X, I get the following error:

Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T15:51:42+02:00)
Maven home: /usr/local/Cellar/maven/3.2.2/libexec
Java version: 1.8.0_11, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.4", arch: "x86_64", family: "mac"
[INFO] Error stacktraces are turned on.
[DEBUG] Reading global settings from /usr/local/Cellar/maven/3.2.2/libexec/conf/settings.xml
[DEBUG] Reading user settings from /Users/philipp/.m2/settings.xml
[DEBUG] Using local repository at /Users/philipp/.m2/repository
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for /Users/philipp/.m2/repository
[INFO] Scanning for projects...
[DEBUG] Skipped remote update check for com.xxx:parent-pom:1.4.11-SNAPSHOT/maven-metadata.xml, locally installed metadata up-to-date.
[DEBUG] Skipped remote update check for com.xxx:parent-pom:1.4.11-SNAPSHOT/maven-metadata.xml, locally installed metadata up-to-date.
[DEBUG] Skipped remote update check for com.xxx:parent-pom:1.4.11-SNAPSHOT/maven-metadata.xml, locally installed metadata up-to-date.
[DEBUG] java.util.NoSuchElementException
      role: org.apache.maven.wagon.Wagon
  roleHint: s3
org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException
      role: org.apache.maven.wagon.Wagon
  roleHint: s3
    at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:264)
    at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:252)
    at org.eclipse.aether.internal.connector.wagon.PlexusWagonProvider.lookup(PlexusWagonProvider.java:33)
    at org.eclipse.aether.connector.wagon.WagonRepositoryConnector.lookupWagon(WagonRepositoryConnector.java:337)
    at org.eclipse.aether.connector.wagon.WagonRepositoryConnector.<init>(WagonRepositoryConnector.java:157)
    at org.eclipse.aether.connector.wagon.WagonRepositoryConnectorFactory.newInstance(WagonRepositoryConnectorFactory.java:159)
    at org.eclipse.aether.internal.impl.DefaultRepositoryConnectorProvider.newRepositoryConnector(DefaultRepositoryConnectorProvider.java:139)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:531)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:436)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:262)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:239)
    at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveArtifact(DefaultRepositorySystem.java:295)
    at org.apache.maven.project.ProjectModelResolver.resolveModel(ProjectModelResolver.java:171)
    at org.apache.maven.project.ProjectModelResolver.resolveModel(ProjectModelResolver.java:224)
    at org.apache.maven.model.building.DefaultModelBuilder.readParentExternally(DefaultModelBuilder.java:903)
    at org.apache.maven.model.building.DefaultModelBuilder.readParent(DefaultModelBuilder.java:755)
    at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:309)
    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:452)
    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:421)
    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:385)
    at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:663)
    at org.apache.maven.DefaultMaven.getProjectsForMavenReactor(DefaultMaven.java:654)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:243)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.util.NoSuchElementException
    at org.eclipse.sisu.plexus.RealmFilter$FilteredItr.next(RealmFilter.java:118)
    at org.eclipse.sisu.plexus.RealmFilter$FilteredItr.next(RealmFilter.java:1)
    at org.eclipse.sisu.plexus.DefaultPlexusBeans$Itr.next(DefaultPlexusBeans.java:76)
    at org.eclipse.sisu.plexus.DefaultPlexusBeans$Itr.next(DefaultPlexusBeans.java:1)
    at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:260)
    ... 34 more
[DEBUG] Writing tracking file /Users/philipp/.m2/repository/com/xxx/parent-pom/1.4.11-SNAPSHOT/parent-pom-1.4.11-20140722.193312-1.pom.lastUpdated
[ERROR] The build could not read 1 project -> [Help 1]
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM com.xxx:parent-pom:1.4.11-SNAPSHOT: Could not transfer artifact com.xxx:parent-pom:pom:1.4.11-20140722.193312-1 from/to maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot): No connector available to access repository maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot) of type default using the available factories WagonRepositoryConnectorFactory and 'parent.relativePath' points at wrong local POM @ line 9, column 10

    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:405)
    at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:663)
    at org.apache.maven.DefaultMaven.getProjectsForMavenReactor(DefaultMaven.java:654)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:243)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[ERROR]
[ERROR]   The project com.xxx:base:1.3.2-SNAPSHOT (/Users/philipp/Documents/IntelliJ/base/pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM com.xxx:parent-pom:1.4.11-SNAPSHOT: Could not transfer artifact com.xxx:parent-pom:pom:1.4.11-20140722.193312-1 from/to maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot): No connector available to access repository maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot) of type default using the available factories WagonRepositoryConnectorFactory and 'parent.relativePath' points at wrong local POM @ line 9, column 10 -> [Help 2]
org.apache.maven.model.resolution.UnresolvableModelException: Could not transfer artifact com.xxx:parent-pom:pom:1.4.11-20140722.193312-1 from/to maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot): No connector available to access repository maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot) of type default using the available factories WagonRepositoryConnectorFactory
    at org.apache.maven.project.ProjectModelResolver.resolveModel(ProjectModelResolver.java:175)
    at org.apache.maven.project.ProjectModelResolver.resolveModel(ProjectModelResolver.java:224)
    at org.apache.maven.model.building.DefaultModelBuilder.readParentExternally(DefaultModelBuilder.java:903)
    at org.apache.maven.model.building.DefaultModelBuilder.readParent(DefaultModelBuilder.java:755)
    at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:309)
    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:452)
    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:421)
    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:385)
    at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:663)
    at org.apache.maven.DefaultMaven.getProjectsForMavenReactor(DefaultMaven.java:654)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:243)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Could not transfer artifact com.xxx:parent-pom:pom:1.4.11-20140722.193312-1 from/to maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot): No connector available to access repository maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot) of type default using the available factories WagonRepositoryConnectorFactory
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:459)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:262)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:239)
    at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveArtifact(DefaultRepositorySystem.java:295)
    at org.apache.maven.project.ProjectModelResolver.resolveModel(ProjectModelResolver.java:171)
    ... 22 more
Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact com.xxx:parent-pom:pom:1.4.11-20140722.193312-1 from/to maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot): No connector available to access repository maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot) of type default using the available factories WagonRepositoryConnectorFactory
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:546)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:436)
    ... 26 more
Caused by: org.eclipse.aether.transfer.NoRepositoryConnectorException: No connector available to access repository maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot) of type default using the available factories WagonRepositoryConnectorFactory
    at org.eclipse.aether.internal.impl.DefaultRepositoryConnectorProvider.newRepositoryConnector(DefaultRepositoryConnectorProvider.java:193)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:531)
    ... 27 more
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

Could not transfer artifact com.xxx:parent-pom:pom:1.4.11-20140722.193312-1 from/to maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot): No connector available to access repository maven.xxx.com-snapshot (s3://maven.xxx.com/snapshot) of type default using the available factories WagonRepositoryConnectorFactory and 'parent.relativePath' points at wrong local POM

So I can write artifacts (the credentials are obviously correct) but not read them? I must be overlooking something simple, but I can't really find it.


来源: stackexchange

问:
Display HTML code in text box
I am having a text box which I am filling from the Json response as below

```<code> <div class="gadget-body" style="height:100px">
    <label>{{ textData}}</label>
  </div>
</code>```

But now my Json is returning html code with
 and
 tags. I am binding the response, but it is displaying with
 and
 tags instead of applying it.

答:
The simple and easiest way is use innerhtml tag</p>

```<code><div class="gadget-body" >
   <div [innerHTML]="textData">
</div>
  </div>
</code>```

ContentLicense: CC BY-SA 3.0

Title: Display HTML code in text box

Body:
I am having a text box which I am filling from the Json response as below

    {{ textData}}

But now my Json is returning html code with
 and
 tags. I am binding the response, but it is displaying with
 and
 tags instead of applying it.

Body:
The simple and easiest way is use innerhtml tag

<div class="gadget-body" >
   <div [innerHTML]="textData">
</div>
  </div>


问:
choose n largest elements in two vector
I have two vectors, each contains n unsorted elements, how can I get n largest elements in these two vectors?

my solution is merge two vector into one with 2n elements, and then use std::nth_element algorithm, but I found that's not quite efficient, so anyone has more efficient solution. Really appreciate.

答:
Assuming that n is far smaller than N this is quite efficient. Getting minElem is cheap and sorted inserting in L cheaper than sorting of the two vectors if n << N. </p>

```<code>L := SortedList()
For Each element in any of the vectors do
{
  minElem := smallest element in L
  if( element >= minElem or if size of L < n)
  {
    add element to L
    if( size of L > n )
    {
      remove smallest element from L
    }
  }
}
</code>```

ContentLicense: CC BY-SA 2.5

Title: choose n largest elements in two vector

Body:
Assuming that n is far smaller than N this is quite efficient. Getting minElem is cheap and sorted inserting in L cheaper than sorting of the two vectors if n << N.

L := SortedList()
For Each element in any of the vectors do
{
  minElem := smallest element in L
  if( element >= minElem or if size of L < n)
  {
    add element to L
    if( size of L > n )
    {
      remove smallest element from L
    }
  }
}


问:
How to start rserve automatically from java in windows
I have created a java application in eclipse. The application used Rserve package to connect to R and run r scripts. Before running my application, i have to start rserve from within Rstudio like this:

```<code>library(Rserve)
Rserve()
</code>```

This Java code would be bundled as an executable file, so is there a way that Rserve() is invoked automatically(in windows) as soon as the code is run so that I can skip this manual step of starting Rserve using through RStudio?

答:
I'm not sure if there's a cleaner way to do this, but the way I've solved this is by starting it up console style from within my java program. For this to work, you have to put the path to the R executables in your systems path:</p>

```<code>public Process rserve = null;

public static void startRServer() throws InterruptedException, IOException {
    // check the runtime environment to see if there's an active Rserve running
    String existingRserve = "";
    try {
        Process p = Runtime.getRuntime().exec("tasklist /FI \"IMAGENAME eq Rserve.exe\"");
        p.waitFor();
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        existingRserve = in.readLine();
    } catch(IOException e){}

    if(rserve == null || existingRserve.contains("No tasks are running")) {
        // start and rserve if we don't have one for this run yet,
        // or if it has unexpectedly failed since we last used it
        try {
            rserve = Runtime.getRuntime().exec("Rscript -e \"library(Rserve); Rserve()\"");
            rserve.waitFor();
        } catch (IOException e) {
            System.out.print("*** R Error: Unable to start the R server ***");
        }
    }
}
</code>```

Body:
I have created a java application in eclipse. The application used Rserve package to connect to R and run r scripts. Before running my application, i have to start rserve from within Rstudio like this:

library(Rserve)
Rserve()

This Java code would be bundled as an executable file, so is there a way that Rserve() is invoked automatically(in windows) as soon as the code is run so that I can skip this manual step of starting Rserve using through RStudio?

Body:
I'm not sure if there's a cleaner way to do this, but the way I've solved this is by starting it up console style from within my java program. For this to work, you have to put the path to the R executables in your systems path:

public Process rserve = null;

public static void startRServer() throws InterruptedException, IOException {
    // check the runtime environment to see if there's an active Rserve running
    String existingRserve = "";
    try {
        Process p = Runtime.getRuntime().exec("tasklist /FI \"IMAGENAME eq Rserve.exe\"");
        p.waitFor();
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        existingRserve = in.readLine();
    } catch(IOException e){}

    if(rserve == null || existingRserve.contains("No tasks are running")) {
        // start and rserve if we don't have one for this run yet,
        // or if it has unexpectedly failed since we last used it
        try {
            rserve = Runtime.getRuntime().exec("Rscript -e \"library(Rserve); Rserve()\"");
            rserve.waitFor();
        } catch (IOException e) {
            System.out.print("*** R Error: Unable to start the R server ***");
        }
    }
}


问:
How to stack submatrices of a matrix to reduce dimensionality
I couldn't find a good solution for this:

I have a matrix of this size: 60x10x3

And I want to transform it into a matrix of this size: 600x3

Basically I want to stack the 10 matrices with the dimension 60x3 next to each other in the first dimension.

How can I achieve that elegantly in matlab?

答:
It seems that I don't understand what the intended output is, but here are two different ways to achieve it. I added the loop to create different numbers so the results can be studied.

Method 1 - Stack Vertically or Horizontally

```<code>s = zeros(60,10,3);
for x = 1:9
    s(:,x,:) = x;
end
t = reshape(s, 600, 3); %vert
u = t'; %hori
</code>```

Method 2 - Stack 3rd dimension Vertically or horizontally

```<code>s = zeros(60,10,3);
for x = 1:9
    s(:,x,:) = x;
end
t = [s(:,:,1) , s(:,:,2), s(:,:,3)]; % hori
t = [s(:,:,1) ; s(:,:,2); s(:,:,3)]; % vert
</code>```

Hope it helps, but this shows that there are multiple ways to achieve the same output in Matlab. Very powerful tool indeed.

Body:
It seems that I don't understand what the intended output is, but here are two different ways to achieve it. I added the loop to create different numbers so the results can be studied.

Method 1 - Stack Vertically or Horizontally

s = zeros(60,10,3);
for x = 1:9
    s(:,x,:) = x;
end
t = reshape(s, 600, 3); %vert
u = t'; %hori

Method 2 - Stack 3rd dimension Vertically or horizontally

s = zeros(60,10,3);
for x = 1:9
    s(:,x,:) = x;
end
t = [s(:,:,1) , s(:,:,2), s(:,:,3)]; % hori
t = [s(:,:,1) ; s(:,:,2); s(:,:,3)]; % vert

Hope it helps, but this shows that there are multiple ways to achieve the same output in Matlab. Very powerful tool indeed.


问:
Returning custom error in spring security filter
I am working on a Spring Boot & Spring Security application that makes use of JSON Web Tokens.

I have a spring security filter that checks for the presence of an existing JWT and if so, injects a UsernamePasswordAuthenticationToken:

```<code>public class AuthenticationTokenFilter extends UsernamePasswordAuthenticationFilter {

    @Value("${api.token.header}")
    String tokenHeader;

    @Autowired
    TokenUtility tokenUtility;

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;

        String incomingToken = httpRequest.getHeader(tokenHeader);

        if (SecurityContextHolder.getContext().getAuthentication() == null && incomingToken != null) {

            UserDetails userDetails = null;

            try {

                userDetails = tokenUtility.validateToken(incomingToken);

            } catch (TokenExpiredException e) {

                throw new ServletException("Token has expired", e);
            }

            if (userDetails != null) {

                UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());

                authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(httpRequest));

                SecurityContextHolder.getContext().setAuthentication(authentication);
            }
        }

        filterChain.doFilter(servletRequest, servletResponse);
    }
}
</code>```

This filter is injected as follows:

```<code>@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    UserDetailsService userDetailsService;

    @Autowired
    EntryPointUnauthorizedHandler unauthorizedHandler;

    @Autowired
    public void configureAuthentication(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {

        authenticationManagerBuilder
                            .userDetailsService(userDetailsService)
                            .passwordEncoder(passwordEncoder());
    }

    @Bean
    public PasswordEncoder passwordEncoder() {

        return new BCryptPasswordEncoder();
    }

    @Bean
    @Override
    public AuthenticationManager authenticationManager() throws Exception {

        return super.authenticationManager();
    }

    @Bean
    public AuthenticationTokenFilter authenticationTokenFilter() throws Exception {

        AuthenticationTokenFilter authenticationTokenFilter = new AuthenticationTokenFilter();
        authenticationTokenFilter.setAuthenticationManager(authenticationManager());

        return authenticationTokenFilter;
    }

    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {

        httpSecurity
            .csrf()
                .disable()
            .exceptionHandling()
                .authenticationEntryPoint(unauthorizedHandler)
                .and()
            .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
            .authorizeRequests()
                .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
                .antMatchers("/auth/**").permitAll()
                .anyRequest().authenticated();

        // filter injected here
        httpSecurity.addFilterBefore(authenticationTokenFilter(), UsernamePasswordAuthenticationFilter.class);
    }
}
</code>```

If a user passes in a token that has expired, they receive the following error:

```<code>{
    "timestamp":1496424964894,
    "status":500,
    "error":"Internal Server Error",
    "exception":"com.app.exceptions.TokenExpiredException",
    "message":"javax.servlet.ServletException: Token has expired",
    "path":"/orders"
}
</code>```

I know that spring security intercepts the requests before they make it to the controller layer, so I can't use my existing @ControllerAdvice to handle these exceptions.

My question is, how do I customise the error message/object that gets returned here? Elsewhere I use a JSON-serialized POJO to return error messages and I want to be consistent. I also don't want the user to see javax.servlet.ServletException

答:
As you are using .exceptionHandling() I believe you can configure a new ExceptionHandler;

Another way would be to override the messages you want to be different, like this post

Body:
I am working on a Spring Boot & Spring Security application that makes use of JSON Web Tokens.

I have a spring security filter that checks for the presence of an existing JWT and if so, injects a UsernamePasswordAuthenticationToken:

public class AuthenticationTokenFilter extends UsernamePasswordAuthenticationFilter {

    @Value("${api.token.header}")
    String tokenHeader;

    @Autowired
    TokenUtility tokenUtility;

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;

        String incomingToken = httpRequest.getHeader(tokenHeader);

        if (SecurityContextHolder.getContext().getAuthentication() == null && incomingToken != null) {

            UserDetails userDetails = null;

            try {

                userDetails = tokenUtility.validateToken(incomingToken);

            } catch (TokenExpiredException e) {

                throw new ServletException("Token has expired", e);
            }

            if (userDetails != null) {

                UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());

                authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(httpRequest));

                SecurityContextHolder.getContext().setAuthentication(authentication);
            }
        }

        filterChain.doFilter(servletRequest, servletResponse);
    }
}

This filter is injected as follows:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    UserDetailsService userDetailsService;

    @Autowired
    EntryPointUnauthorizedHandler unauthorizedHandler;

    @Autowired
    public void configureAuthentication(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {

        authenticationManagerBuilder
                            .userDetailsService(userDetailsService)
                            .passwordEncoder(passwordEncoder());
    }

    @Bean
    public PasswordEncoder passwordEncoder() {

        return new BCryptPasswordEncoder();
    }

    @Bean
    @Override
    public AuthenticationManager authenticationManager() throws Exception {

        return super.authenticationManager();
    }

    @Bean
    public AuthenticationTokenFilter authenticationTokenFilter() throws Exception {

        AuthenticationTokenFilter authenticationTokenFilter = new AuthenticationTokenFilter();
        authenticationTokenFilter.setAuthenticationManager(authenticationManager());

        return authenticationTokenFilter;
    }

    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {

        httpSecurity
            .csrf()
                .disable()
            .exceptionHandling()
                .authenticationEntryPoint(unauthorizedHandler)
                .and()
            .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
            .authorizeRequests()
                .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
                .antMatchers("/auth/**").permitAll()
                .anyRequest().authenticated();

        // filter injected here
        httpSecurity.addFilterBefore(authenticationTokenFilter(), UsernamePasswordAuthenticationFilter.class);
    }
}

If a user passes in a token that has expired, they receive the following error:

{
    "timestamp":1496424964894,
    "status":500,
    "error":"Internal Server Error",
    "exception":"com.app.exceptions.TokenExpiredException",
    "message":"javax.servlet.ServletException: Token has expired",
    "path":"/orders"
}

I know that spring security intercepts the requests before they make it to the controller layer, so I can't use my existing @ControllerAdvice to handle these exceptions.

My question is, how do I customise the error message/object that gets returned here? Elsewhere I use a JSON-serialized POJO to return error messages and I want to be consistent. I also don't want the user to see javax.servlet.ServletException


问:
Square API, VALUE_TOO_LOW error when charging a card
I am currently working with sandbox credentials for my companies Square Up account. When I make a web service call to charge a card with an amount that is under $100, I get the following error:

```<code>Error calling Charge: {\"errors\":[{\"category\":\"INVALID_REQUEST_ERROR\",\"code\":\"VALUE_TOO_LOW\",\"detail\":\"`amount_money.amount` must be greater than 100.\
</code>```

I need to be able to charge for as low as $10 at a time. Is there some sort of setting in my companies account that needs to be changed in order to allow this? or is this a native Square setting that I cannot get around?

答: The amount you are charging (if in US dollars) is in cents, not dollars. So a charge of 100 would be $1. 10 would just be ten cents. Try multiplying your value by 100. See the documentation for more details.

Body:
I am currently working with sandbox credentials for my companies Square Up account. When I make a web service call to charge a card with an amount that is under $100, I get the following error:

Error calling Charge: {\"errors\":[{\"category\":\"INVALID_REQUEST_ERROR\",\"code\":\"VALUE_TOO_LOW\",\"detail\":\"`amount_money.amount` must be greater than 100.\

I need to be able to charge for as low as $10 at a time. Is there some sort of setting in my companies account that needs to be changed in order to allow this? or is this a native Square setting that I cannot get around?


问:
browser.keys() is not working on Firefox 53.0 & webdriver.io
On firefox, browser.keys throwing error.

```
Os: MacOs
Firefox version: 53.0.3
Geckodriver: 0.16.1
Webdriver.io: 4.8
```

Please help me how to deal with this error.

Here are the logs

```
[17:11:35]  COMMAND POST     "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/url"
[17:11:41]  COMMAND POST     "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/refresh"
[17:11:45]  COMMAND GET      "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/window/current/size"
[17:11:46]  COMMAND POST     "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/elements"
[17:11:46]  COMMAND GET      "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/element/0/displayed"
[17:11:46]  COMMAND GET      "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/element/1/displayed"
[17:11:46]  COMMAND POST     "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/elements"
[17:11:46]  COMMAND GET      "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/element/0/displayed"
[17:11:46]  COMMAND GET      "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/element/1/displayed"
[17:11:46]  COMMAND POST     "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/elements"
[17:11:47]  COMMAND POST     "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/element/0/value"
WARNING: the "keys" command will be depcrecated soon. Please use a different command in order to avoid failures in your test after updating WebdriverIO.
[17:11:47]  COMMAND POST     "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/keys"
[17:11:47]  COMMAND GET      "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/screenshot"
[17:11:48]      Saved screenshot: ERROR_firefox_2017-06-03T00-11-47.734Z.png
[17:11:48]  COMMAND DELETE   "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/cookie"
Error: sendKeysToActiveElement
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'xxx.local', ip: '10.142.4.252', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.5', java.version: '1.8.0_131'
Driver info: driver.version: RemoteWebDriver
Error: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource.
    at Object.wait (/Users/xxxx/c3web/xxxx/node_modules/fibers/future.js:449:15)
    at Object.keys (/Users/xxxxx/node_modules/wdio-sync/build/index.js:264:31)
    at Object.exports.customCommands.selector (/Users/xxx/c3web/xxxx/testlib/browser/customCommands.js:158:17)
    at /Users/xxxx/node_modules/wdio-sync/build/index.js:191:29
    - - - - -
    at keys("Enter") - index.js:244:37
    at elementIdValue("0", "xxxyyyzzz") - index.js:293:3
```

答:
Well, that error pretty much explains that there is an issue with the implementation of the keys command: WARNING: the "keys" command will be depcrecated soon. Please use a different command in order to avoid failures in your test after updating WebdriverIO..

It is currently only working with chromedriver in my test cases too, but I'm also not able to chain commands with it. (simulate Ctrl+C, Ctrl+V).

See my answer on this question. You'll have to find another way to go around this, or wait for the drivers (chromedriver, geckodriver, etc.) to implement the new Selenium actions methods.

The answer I gave there pretty much covers the entire issue. Alternatively, you could try the codepoint approach: browser.keys("\uE007").

Hope this helps you!

Body:
On firefox, browser.keys throwing error.

Os: MacOs
Firefox version: 53.0.3
Geckodriver: 0.16.1
Webdriver.io: 4.8

Please help me how to deal with this error.

Here are the logs

[17:11:35]  COMMAND POST     "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/url"
[17:11:41]  COMMAND POST     "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/refresh"
[17:11:45]  COMMAND GET      "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/window/current/size"
[17:11:46]  COMMAND POST     "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/elements"
[17:11:46]  COMMAND GET      "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/element/0/displayed"
[17:11:46]  COMMAND GET      "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/element/1/displayed"
[17:11:46]  COMMAND POST     "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/elements"
[17:11:46]  COMMAND GET      "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/element/0/displayed"
[17:11:46]  COMMAND GET      "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/element/1/displayed"
[17:11:46]  COMMAND POST     "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/elements"
[17:11:47]  COMMAND POST     "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/element/0/value"
WARNING: the "keys" command will be depcrecated soon. Please use a different command in order to avoid failures in your test after updating WebdriverIO.
[17:11:47]  COMMAND POST     "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/keys"
[17:11:47]  COMMAND GET      "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/screenshot"
[17:11:48]      Saved screenshot: ERROR_firefox_2017-06-03T00-11-47.734Z.png
[17:11:48]  COMMAND DELETE   "/wd/hub/session/97804a03-d52a-4232-9e3c-41e1fac6a9c5/cookie"
Error: sendKeysToActiveElement
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'xxx.local', ip: '10.142.4.252', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.5', java.version: '1.8.0_131'
Driver info: driver.version: RemoteWebDriver
Error: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource.
    at Object.wait (/Users/xxxx/c3web/xxxx/node_modules/fibers/future.js:449:15)
    at Object.keys (/Users/xxxxx/node_modules/wdio-sync/build/index.js:264:31)
    at Object.exports.customCommands.selector (/Users/xxx/c3web/xxxx/testlib/browser/customCommands.js:158:17)
    at /Users/xxxx/node_modules/wdio-sync/build/index.js:191:29
    - - - - -
    at keys("Enter") - index.js:244:37
    at elementIdValue("0", "xxxyyyzzz") - index.js:293:3


问:
Why do I need to override the equals and hashCode methods in Java?
Recently I read through this
 Developer Works Document.

The document is all about defining hashCode() and equals() effectively and correctly, however I am not able to figure out why we need to override these two methods.

How can I take the decision to implement these methods efficiently?

答:
IMHO, it's as per the rule says - If two objects are equal then they should have same hash, i.e., equal objects should produce equal hash values.

Given above, default equals() in Object is == which does comparison on the address, hashCode() returns the address in integer(hash on actual address) which is again distinct for distinct Object.

If you need to use the custom Objects in the Hash based collections, you need to override both equals() and hashCode(), example If I want to maintain the HashSet of the Employee Objects, if I don't use stronger hashCode and equals I may endup overriding the two different Employee Objects, this happen when I use the age as the hashCode(), however I should be using the unique value which can be the Employee ID.


问:
Multi-line text padding
I have a following structure:

```<code><div class="1">
  <div class="2">
    2.
  </div>
  <div class="3">
    3.
  </div>
  <div class="4">
    very long line of text
  </div>
</div>
</code>```

So div 1 has display: block, all the others have display: inline. My goal is to make this very long line of text being displayed like that:

```<code>2. 3. very long
      line of text
</code>```

If I try making div 4 an inline-block or inline-flex and set margin and text-indent properties, then it kinda does what I want, but it also moves whole text down one line like this:

```<code>2. 3.
very long
      line of text
</code>```

How do I do that properly?

答:
If you don't want to use display: flex for compatibility reasons with older browsers, you can make them inline-blocks, align them vertically at the top and then use jQuery to get their widths and calculate the width of DIV4:

jQuery(document).ready(function() {
var width1 = $(".x1").innerWidth();
var width2 = $(".x2").innerWidth();
var width3 = $(".x3").innerWidth();
var width4 = (width1 - width2 - width3 - 8) + "px";
$(".x4").css("width", width4);
});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.x2, .x3, .x4 {
display: inline-block;
vertical-align: top;
}</code>```

    2.

    3.

    very long line of text very long line of text very long line of text very long line of text very long line of text very long line of text very long line of text

```

(Note: The -8 in the calculation is done by trial and error - it's necessary because of some whitespace created by the linebreaks in the HTML code which otherwise would break DIV4 into the next line)

Title: Multi-line text padding

Body:
I have a following structure:

    2.

    3.

    very long line of text

So div 1 has display: block, all the others have display: inline. My goal is to make this very long line of text being displayed like that:

2. 3. very long
      line of text

If I try making div 4 an inline-block or inline-flex and set margin and text-indent properties, then it kinda does what I want, but it also moves whole text down one line like this:

2. 3.
very long
      line of text

How do I do that properly?

Body:
If you don't want to use display: flex for compatibility reasons with older browsers, you can make them inline-blocks, align them vertically at the top and then use jQuery to get their widths and calculate the width of DIV4:

jQuery(document).ready(function() {
var width1 = $(".x1").innerWidth();
var width2 = $(".x2").innerWidth();
var width3 = $(".x3").innerWidth();
var width4 = (width1 - width2 - width3 - 8) + "px";
$(".x4").css("width", width4);
});

.x2, .x3, .x4 {
display: inline-block;
vertical-align: top;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="x1">
  <div class="x2">
    2.
  </div>
  <div class="x3">
    3.
  </div>
  <div class="x4">
    very long line of text very long line of text very long line of text very long line of text very long line of text very long line of text very long line of text
  </div>
</div>

(Note: The -8 in the calculation is done by trial and error - it's necessary because of some whitespace created by the linebreaks in the HTML code which otherwise would break DIV4 into the next line)


问:
Duplicate Output Destination Error in Access
I am using the following query. But when i run it, it gives error </p>

<blockquote>
  <p>"Duplicate Output Destination 'ShipmentID'.  </p>
</blockquote>

```<code>CurrentDb.Execute "INSERT INTO TmpContainersForPLReport " & _
                  "SELECT * FROM Containers INNER JOIN Shipments ON (Containers.ShipmentID = Shipments.ShipmentID)  WHERE Containers.PackinglistentryDate = #" & TxtEntryDate & "# and Containers.PONumber = '" & TxtPONumber & "'" & _
                  " OR Containers.PackinglistentryDate = #" & TxtEntryDate & "# and Containers.SalesOrderNumber = '" & txtSalesOrderNumber & "'"
</code>```

答:
You are getting thin error because you are using 'SELECT *' from a JOIN between two tables and the field ShipmentID exists in both tables so you are selecting that field twice.

If you go to this link, you will see that's the description for this error:

https://msdn.microsoft.com/en-us/library/bb209781(v=office.12).aspx

Body:
I am using the following query. But when i run it, it gives error

"Duplicate Output Destination 'ShipmentID'.

CurrentDb.Execute "INSERT INTO TmpContainersForPLReport " & _
                  "SELECT * FROM Containers INNER JOIN Shipments ON (Containers.ShipmentID = Shipments.ShipmentID)  WHERE Containers.PackinglistentryDate = #" & TxtEntryDate & "# and Containers.PONumber = '" & TxtPONumber & "'" & _
                  " OR Containers.PackinglistentryDate = #" & TxtEntryDate & "# and Containers.SalesOrderNumber = '" & txtSalesOrderNumber & "'"


问:
I want to achieve a specific row layout, but can't quite figure it out with Android
I'm trying to achieve this:

on a ListView but can't quite get the restraints on the items in the row layout.xml right, anyone have a suggestion?

here is my photo_album_row_layout.xml:

```<code><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/photoAlbumTitle"
        android:layout_alignParentStart="true"
        android:layout_alignParentEnd="true"
        android:layout_centerVertical="true"
        android:textColor="@android:color/black"
        android:paddingBottom="@dimen/default_padding"
        android:textStyle="bold"
    />
    <TextView
        android:id="@+id/photoAlbumDesc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_centerVertical="true"
        android:textColor="@android:color/black"
        android:layout_below="@+id/photoAlbumTitle"
        android:layout_toStartOf="@+id/viewPhotoAlbum"/>

    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentEnd="true"
        android:id="@+id/viewPhotoAlbum"/>

    <TextView
        android:id="@+id/viewPhotoAlbumText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:textSize="12sp"
        android:textColor="@android:color/black"
        android:text="Open Album"
        android:layout_alignStart="@+id/viewPhotoAlbum"
        android:layout_alignEnd="@+id/viewPhotoAlbum"
        android:layout_below="@+id/viewPhotoAlbum"/>

</RelativeLayout>
</code>```

It seems to center the text okay if there's only the title displayed, otherwise there is overlap, this is what I mean:

答:
Try this:</p>

```<code><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
    android:layout_toStartOf="@+id/imageLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_centerVertical="true">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/photoAlbumTitle"
        android:textColor="@android:color/black"
        android:text="Hello world its title"
        android:textStyle="bold"
        />
    <TextView
        android:id="@+id/photoAlbumDesc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:text="Hello world its description"
        android:textColor="@android:color/black"/>
</LinearLayout>

<RelativeLayout
    android:id="@+id/imageLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_alignParentEnd="true"
    android:gravity="center">
    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:src="@mipmap/ic_launcher"
        android:id="@+id/viewPhotoAlbum"/>

    <TextView
        android:id="@+id/viewPhotoAlbumText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:layout_alignStart="@+id/viewPhotoAlbum"
        android:layout_alignEnd="@+id/viewPhotoAlbum"
        android:layout_below="@+id/viewPhotoAlbum"
        android:textSize="12sp"
        android:textColor="@android:color/black"
        android:text="Open Album"/>
</RelativeLayout>

</RelativeLayout>
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I'm trying to achieve this:

on a ListView but can't quite get the restraints on the items in the row layout.xml right, anyone have a suggestion?

here is my photo_album_row_layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/photoAlbumTitle"
        android:layout_alignParentStart="true"
        android:layout_alignParentEnd="true"
        android:layout_centerVertical="true"
        android:textColor="@android:color/black"
        android:paddingBottom="@dimen/default_padding"
        android:textStyle="bold"
    />
    <TextView
        android:id="@+id/photoAlbumDesc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_centerVertical="true"
        android:textColor="@android:color/black"
        android:layout_below="@+id/photoAlbumTitle"
        android:layout_toStartOf="@+id/viewPhotoAlbum"/>

    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentEnd="true"
        android:id="@+id/viewPhotoAlbum"/>

    <TextView
        android:id="@+id/viewPhotoAlbumText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:textSize="12sp"
        android:textColor="@android:color/black"
        android:text="Open Album"
        android:layout_alignStart="@+id/viewPhotoAlbum"
        android:layout_alignEnd="@+id/viewPhotoAlbum"
        android:layout_below="@+id/viewPhotoAlbum"/>

</RelativeLayout>

It seems to center the text okay if there's only the title displayed, otherwise there is overlap, this is what I mean:

Body:
Try this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
    android:layout_toStartOf="@+id/imageLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_centerVertical="true">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/photoAlbumTitle"
        android:textColor="@android:color/black"
        android:text="Hello world its title"
        android:textStyle="bold"
        />
    <TextView
        android:id="@+id/photoAlbumDesc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:text="Hello world its description"
        android:textColor="@android:color/black"/>
</LinearLayout>

<RelativeLayout
    android:id="@+id/imageLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_alignParentEnd="true"
    android:gravity="center">
    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:src="@mipmap/ic_launcher"
        android:id="@+id/viewPhotoAlbum"/>

    <TextView
        android:id="@+id/viewPhotoAlbumText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:layout_alignStart="@+id/viewPhotoAlbum"
        android:layout_alignEnd="@+id/viewPhotoAlbum"
        android:layout_below="@+id/viewPhotoAlbum"
        android:textSize="12sp"
        android:textColor="@android:color/black"
        android:text="Open Album"/>
</RelativeLayout>

</RelativeLayout>


问:
Track conversation chain from different server sessions to one number
I'm creating an app which will allow all users to initiate conversation with page owner using Chat-to-SMS service.

Problem is that I'm not sure how to track conversations since there would be one conversation chain from SMS Provider <-> page owner. When owner clicks reply, it needs to know which session user it needs to send the message to.

Basically, I need to do opposite what is being explained here: https://www.twilio.com/docs/quickstart/php/sms/tracking-conversations

How should I accomplish this? I can't quite wrap my head around this.

答:
Twilio developer evangelist here.

If you are sending all the chat messages to just one SMS number then there is no easy way to tie replies back to the original message. (As a quick experiment, if you open an SMS conversation in your own phone and try to reply to any message that wasn't the latest one, you'll see it's not possible.)

There are workarounds though.

You could, when forwarding the message, generate an ID for it. Then get your page owner to include that ID when responding to that message, that way you can route the message back to the original sender and strip out the ID.

Alternatively, when replying you could always respond to the last message that came in. This relies on there not being much traffic, allowing the page owner to respond before the next message arrives. This is error prone though.

Another alternative is purchasing a new number for each new conversation. You could expire the number after a predetermined amount of time. This is made much easier with Twilio Proxy, which was announced recently and is currently in preview.

Let me know if that helps at all.


问:
Determining correct frame format in libuvc
I'm trying to connect to a UVC compatible camera on OS X. Using the hello world example from libuvc, my camera outputs this:

```<code>DEVICE CONFIGURATION (2560:c114/39254404) ---
Status: idle
VideoControl:
    bcdUVC: 0x0100
VideoStreaming(1):
    bEndpointAddress: 131
    Formats:
    UncompressedFormat(1)
          bits per pixel: 16
          GUID: 5931362000001000800000aa00389b71
          default frame: 1
          aspect ration: 0x0
          interlace flags: 00
          copy protect: 00
            FrameDescriptor(1)
              capabilities: 00
              size: 752x480
              bit rate: 346521600-346521600
              max frame size: 721920
              default interval: 1/60
              interval[0]: 1/60
              interval[1]: 1/30
            FrameDescriptor(2)
              capabilities: 00
              size: 640x480
              bit rate: 294912000-294912000
              max frame size: 614400
              default interval: 1/60
              interval[0]: 1/60
              interval[1]: 1/30
            FrameDescriptor(3)
              capabilities: 00
              size: 320x240
              bit rate: 73728000-73728000
              max frame size: 153600
              default interval: 1/60
              interval[0]: 1/60
    UncompressedFormat(2)
          bits per pixel: 24
          GUID: 7deb36e44f52ce119f530020af0ba770
          default frame: 1
          aspect ration: 0x0
          interlace flags: 00
          copy protect: 00
            FrameDescriptor(1)
              capabilities: 00
              size: 752x480
              bit rate: 519782400-519782400
              max frame size: 1082880
              default interval: 1/60
              interval[0]: 1/60
              interval[1]: 1/30
            FrameDescriptor(2)
              capabilities: 00
              size: 640x480
              bit rate: 442368000-442368000
              max frame size: 921600
              default interval: 1/60
              interval[0]: 1/60
              interval[1]: 1/30
            FrameDescriptor(3)
              capabilities: 00
              size: 320x240
              bit rate: 110592000-110592000
              max frame size: 230400
              default interval: 1/60
              interval[0]: 1/60
END DEVICE CONFIGURATION
</code>```

However none of the frame formats seem to work, i.e.

```<code>res = uvc_get_stream_ctrl_format_size(
                  devh, &ctrl,
                  UVC_FRAME_FORMAT_YUYV,
                  752, 480, 60 /* width, height, fps */
              );
</code>```

Whatever frame format I try (I tried looping over the enum) I get something like this:

```<code>UVC initialized
Device found
Device opened
get_mode: Invalid mode (-51)
Device closed
UVC exited
</code>```

The camera works fine in Windows and in Linux under ROS. What frame format should I use? Given the configuration, I hoped UVC_FRAME_FORMAT_RGB would work, but no dice. The code for libuvc seems to compare the UVC frame format to what the device provided, but I don't understand how it determines what's a valid format.

答:
You have to use

const uvc_format_desc_t *uvc_get_format_descs(uvc_device_handle_t* )

The returned pointer to uvc_format_desc_t will contain the first available format that is valid for the given camera. You can then iterate through all possible formats with the next pointer in uvc_format_desc_t.

frame_descs in uvc_format_desc_t contains width height etc.

bDescriptorSubtype in uvc_format_desc_t contains the format e.g. UVC_VS_FORMAT_UNCOMPRESSED

Body:
I'm trying to connect to a UVC compatible camera on OS X. Using the hello world example from libuvc, my camera outputs this:

DEVICE CONFIGURATION (2560:c114/39254404) ---
Status: idle
VideoControl:
    bcdUVC: 0x0100
VideoStreaming(1):
    bEndpointAddress: 131
    Formats:
    UncompressedFormat(1)
          bits per pixel: 16
          GUID: 5931362000001000800000aa00389b71
          default frame: 1
          aspect ration: 0x0
          interlace flags: 00
          copy protect: 00
            FrameDescriptor(1)
              capabilities: 00
              size: 752x480
              bit rate: 346521600-346521600
              max frame size: 721920
              default interval: 1/60
              interval[0]: 1/60
              interval[1]: 1/30
            FrameDescriptor(2)
              capabilities: 00
              size: 640x480
              bit rate: 294912000-294912000
              max frame size: 614400
              default interval: 1/60
              interval[0]: 1/60
              interval[1]: 1/30
            FrameDescriptor(3)
              capabilities: 00
              size: 320x240
              bit rate: 73728000-73728000
              max frame size: 153600
              default interval: 1/60
              interval[0]: 1/60
    UncompressedFormat(2)
          bits per pixel: 24
          GUID: 7deb36e44f52ce119f530020af0ba770
          default frame: 1
          aspect ration: 0x0
          interlace flags: 00
          copy protect: 00
            FrameDescriptor(1)
              capabilities: 00
              size: 752x480
              bit rate: 519782400-519782400
              max frame size: 1082880
              default interval: 1/60
              interval[0]: 1/60
              interval[1]: 1/30
            FrameDescriptor(2)
              capabilities: 00
              size: 640x480
              bit rate: 442368000-442368000
              max frame size: 921600
              default interval: 1/60
              interval[0]: 1/60
              interval[1]: 1/30
            FrameDescriptor(3)
              capabilities: 00
              size: 320x240
              bit rate: 110592000-110592000
              max frame size: 230400
              default interval: 1/60
              interval[0]: 1/60
END DEVICE CONFIGURATION

However none of the frame formats seem to work, i.e.

res = uvc_get_stream_ctrl_format_size(
                  devh, &ctrl,
                  UVC_FRAME_FORMAT_YUYV,
                  752, 480, 60 /* width, height, fps */
              );

Whatever frame format I try (I tried looping over the enum) I get something like this:

UVC initialized
Device found
Device opened
get_mode: Invalid mode (-51)
Device closed
UVC exited

The camera works fine in Windows and in Linux under ROS. What frame format should I use? Given the configuration, I hoped UVC_FRAME_FORMAT_RGB would work, but no dice. The code for libuvc seems to compare the UVC frame format to what the device provided, but I don't understand how it determines what's a valid format.


答:
For the first file you are decoding to 16-bit linear PCM in WAV and then converting that to floating point.  For the second file you are decoding to floating point directly.  16-bit linear PCM has less precision than floating point so that will lose information, although the loss would normally be negligible compared to the loss of the lossy compression, so could be ignored.

Although WAV is most often used with 16-bit linear PCM it is also possible to store floating point PCM in a wav file (although the file will be about twice as large).  To write floating point in wav:

```<code>ffmpeg -i in.ogg -c:a pcm_f32le out.wav
</code>```

There could also be differences in the decoders for the lossy formats which produce slightly different results.  Also if one of the decoders is not gapless it may only produce whole frames and may therefore have a few extra samples at the beginning and/or end.

Title: Python read sound file, ogg or wav?

Body:
I want to import music in Python, I am using soundfile. I noticed that importing ogg or wav files yield different results, as the following shows (the wav file is a conversion of the ogg file using ffmpeg). Using the code below, I observe a small difference between the ogg and wav files, is this difference normal ?

Edit : I used the following command to convert my ffmpeg -i filename.mp3 newfilename.wav

X, sample_rate= sf.read(wav_file)
print(wav_file)
print(X[0:20,])

And it outputs:

test_inputs/Shikantaza.wav
[[  0.00000000e+00   0.00000000e+00]
 [  0.00000000e+00   0.00000000e+00]
 [  0.00000000e+00   0.00000000e+00]
 [  0.00000000e+00   0.00000000e+00]
 [  0.00000000e+00   0.00000000e+00]
 [  0.00000000e+00   0.00000000e+00]
 [  0.00000000e+00   0.00000000e+00]
 [  0.00000000e+00   0.00000000e+00]
 [  0.00000000e+00   0.00000000e+00]
 [  0.00000000e+00   0.00000000e+00]
 [  0.00000000e+00   0.00000000e+00]
 [  0.00000000e+00   0.00000000e+00]
 [  0.00000000e+00   0.00000000e+00]
 [  0.00000000e+00   0.00000000e+00]
 [  0.00000000e+00   0.00000000e+00]
 [ -3.05175781e-05  -3.05175781e-05]
 [ -3.05175781e-05   0.00000000e+00]
 [  0.00000000e+00   0.00000000e+00]
 [  0.00000000e+00   0.00000000e+00]
 [  0.00000000e+00   0.00000000e+00]]
test_inputs/Shikantaza.ogg
[[  1.17459308e-06   3.78499834e-07]
 [  5.19584228e-06   2.25495864e-06]
 [  1.13173719e-05   6.28675980e-06]
 [  1.07316619e-05   4.50928837e-06]
 [  2.70867986e-06  -3.40946622e-06]
 [  5.37277947e-06   5.06399772e-07]
 [  3.64179391e-06   6.27796169e-07]
 [ -5.09244865e-06  -6.14764804e-06]
 [ -4.38827237e-06  -3.74127058e-06]
 [ -5.41250847e-06  -3.70974522e-06]
 [ -2.75347884e-06  -7.08531957e-07]
 [ -9.67129495e-07   6.15705801e-07]
 [ -4.91217952e-06  -3.82820826e-06]
 [  4.38740926e-06   6.00675048e-06]
 [ -3.00040119e-06  -4.78463562e-08]
 [ -2.18559871e-05  -1.67418439e-05]
 [ -1.57035538e-05  -8.82137283e-06]
 [ -1.28820702e-05  -5.31934711e-06]
 [ -9.44996100e-06  -8.10974825e-07]
 [ -5.33486082e-06   3.71237797e-06]]

Body:
For the first file you are decoding to 16-bit linear PCM in WAV and then converting that to floating point.  For the second file you are decoding to floating point directly.  16-bit linear PCM has less precision than floating point so that will lose information, although the loss would normally be negligible compared to the loss of the lossy compression, so could be ignored.

Although WAV is most often used with 16-bit linear PCM it is also possible to store floating point PCM in a wav file (although the file will be about twice as large).  To write floating point in wav:

ffmpeg -i in.ogg -c:a pcm_f32le out.wav

There could also be differences in the decoders for the lossy formats which produce slightly different results.  Also if one of the decoders is not gapless it may only produce whole frames and may therefore have a few extra samples at the beginning and/or end.


问:
Volume Rendering in OpenGL using 2D textures
Why we have to align the textures in different directions depending on the perspective of the camera? Shouldn't it be the same?(If I enabled depth test)

Edit 1:

I used my own program to test it.

Here is my code for the rendering function.

```<code>        if (position.z >= 0) pz = true;
        else pz = false;

        if (lz != pz) {
            slice.clear();
            printf("Changed !!! :: %s", (pz?"Positive Z":"Negative Z") );
            if (pz) {
                for (float i = 0; i < count; ++i) {
                    slice.push_back( glm::vec2( -SIZE/2 + SIZE * i / (count-1), i ) );
                }
                lz = pz;
            } else {
                for (float i = count-1; i >= 0; --i) {
                    slice.push_back( glm::vec2( -SIZE/2 + SIZE * i / (count-1), i ) );
                }
                lz = pz;
            }
            glBindBuffer(GL_ARRAY_BUFFER, ibo);
            glBufferData(GL_ARRAY_BUFFER, slice.size()* 2 *sizeof(float), &slice[0], GL_STATIC_DRAW);
        }

        glUseProgram(programID);
        glBindVertexArray(vao);
        glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &mvp[0][0]);
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, texture);
        glEnableVertexAttribArray(0);
        glEnableVertexAttribArray(1);
        glEnableVertexAttribArray(2);
        glDrawArraysInstanced(GL_TRIANGLES, 0, 6, slice.size());
        glDisableVertexAttribArray(0);
        glDisableVertexAttribArray(1);
        glDisableVertexAttribArray(2);
        glBindVertexArray(0);
</code>```

The vector "slice" contains 2 floats (z position and the id of the slice). It is unique for each instance. Without this "if (lz != pz) ... " clause, I can only see the model in +ve Z direction.

Edit 2:

This is one perspective.

But when my camera move to near z=0, parts of the textures can't be seen.
I tried to turn off the depth test and then I see the textures AT THE BACK. Why the texture at the front disappeared?

Enabled depth test

Disabled back-face culling

Enabled alpha testing

Edit 3:

I changed the  "if (lz != pz) ... " clause, to the following code and every thing works fine now. But I still don't understand why.

```<code>        slice.clear();
        for (float i = 0; i < count; ++i) { // position is a vector representing the location of the camera
            if (-SIZE/2 + SIZE * i / (count-1) >= position.z) break;
            slice.push_back( glm::vec2( -SIZE/2 + SIZE * i / (count-1), i ) );
        }

        for (float i = count-1; i >= 0; --i) {
            if (-SIZE/2 + SIZE * i / (count-1) < position.z) break;
            slice.push_back( glm::vec2( -SIZE/2 + SIZE * i / (count-1), i ) );
        }
</code>```

Although it doesn't look appealing, it worked as expected. For each frame, I ordered the slices according to the position of the camera.

Edit 4:

My alpha testing code

```<code>glEnable (GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.1);
</code>```

These two lines are in the init() function.

答:
Essentially I see two questions here:

Why choose the axis closest to the camera direction?

Because otherwise the slices might not even fill the whole screen area of the volume. Imagine that you render the slices parallel to the XY plane, but the camera looks along the X axis, i.e. 'from the side'. Then you will see the gaps between the slices. Like this:

Why render back to front?

This is not always necessary. In principle, if you enable alpha-test and depth-test then you may render in any order. However, volume rendering usually assumes support of partially-transparent data, in which case for the usual alpha-blending equations to work the geometry has to be rendered back to front.

Body:
Why we have to align the textures in different directions depending on the perspective of the camera? Shouldn't it be the same?(If I enabled depth test)

Edit 1:

I used my own program to test it.

Here is my code for the rendering function.

        if (position.z >= 0) pz = true;
        else pz = false;

        if (lz != pz) {
            slice.clear();
            printf("Changed !!! :: %s", (pz?"Positive Z":"Negative Z") );
            if (pz) {
                for (float i = 0; i < count; ++i) {
                    slice.push_back( glm::vec2( -SIZE/2 + SIZE * i / (count-1), i ) );
                }
                lz = pz;
            } else {
                for (float i = count-1; i >= 0; --i) {
                    slice.push_back( glm::vec2( -SIZE/2 + SIZE * i / (count-1), i ) );
                }
                lz = pz;
            }
            glBindBuffer(GL_ARRAY_BUFFER, ibo);
            glBufferData(GL_ARRAY_BUFFER, slice.size()* 2 *sizeof(float), &slice[0], GL_STATIC_DRAW);
        }

        glUseProgram(programID);
        glBindVertexArray(vao);
        glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &mvp[0][0]);
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, texture);
        glEnableVertexAttribArray(0);
        glEnableVertexAttribArray(1);
        glEnableVertexAttribArray(2);
        glDrawArraysInstanced(GL_TRIANGLES, 0, 6, slice.size());
        glDisableVertexAttribArray(0);
        glDisableVertexAttribArray(1);
        glDisableVertexAttribArray(2);
        glBindVertexArray(0);

The vector "slice" contains 2 floats (z position and the id of the slice). It is unique for each instance. Without this "if (lz != pz) ... " clause, I can only see the model in +ve Z direction.

Edit 2:

This is one perspective.

But when my camera move to near z=0, parts of the textures can't be seen.
I tried to turn off the depth test and then I see the textures AT THE BACK. Why the texture at the front disappeared?

Enabled depth test

Disabled back-face culling

Enabled alpha testing

Edit 3:

I changed the  "if (lz != pz) ... " clause, to the following code and every thing works fine now. But I still don't understand why.

        slice.clear();
        for (float i = 0; i < count; ++i) { // position is a vector representing the location of the camera
            if (-SIZE/2 + SIZE * i / (count-1) >= position.z) break;
            slice.push_back( glm::vec2( -SIZE/2 + SIZE * i / (count-1), i ) );
        }

        for (float i = count-1; i >= 0; --i) {
            if (-SIZE/2 + SIZE * i / (count-1) < position.z) break;
            slice.push_back( glm::vec2( -SIZE/2 + SIZE * i / (count-1), i ) );
        }

Although it doesn't look appealing, it worked as expected. For each frame, I ordered the slices according to the position of the camera.

Edit 4:

My alpha testing code

glEnable (GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.1);

These two lines are in the init() function.


问:
How to create a method that takes any object and returns a name:value pair for all properties?
For example I have a simple class like

```<code>public class Person{
    public int Age {get;set;}
    public string Name {get;set;}
}
</code>```

I need to make a method that takes any class and spits out values of properties set in the  object as a string in format "Age:35;Name:John Doe;"

I am looking for a method signature on the lines of

```<code>public string SpitNameValuePairs<T>()
</code>```

or something like it. How can this be done efficiently if using reflection?

答:
Here is a quick implementation.

```<code>    public static string SplitNameValuePairs(object value)
    {
        string retVal = string.Empty;
        List<string> keyValuePairs = new List<string>();

        foreach (var propInfo in value.GetType().GetProperties())
        {
            keyValuePairs.Add(string.Format("{0}:{1};", propInfo.Name, propInfo.GetValue(value, null).ToString()));
        }

        retVal = string.Join("", keyValuePairs.ToArray());

        return retVal;
    }
</code>```

Then called like this:

```<code>        var person = new Person();
        person.Name = "Hello";
        person.Age = 10;
        Console.WriteLine(SplitNameValuePairs(person));
</code>```

OwnerDisplayName: Perpetualcoder

Body:
For example I have a simple class like

public class Person{
    public int Age {get;set;}
    public string Name {get;set;}
}

I need to make a method that takes any class and spits out values of properties set in the  object as a string in format "Age:35;Name:John Doe;"

I am looking for a method signature on the lines of

public string SpitNameValuePairs<T>()

or something like it. How can this be done efficiently if using reflection?

LastEditorDisplayName: Perpetualcoder

Body:
Here is a quick implementation.

    public static string SplitNameValuePairs(object value)
    {
        string retVal = string.Empty;
        List<string> keyValuePairs = new List<string>();

        foreach (var propInfo in value.GetType().GetProperties())
        {
            keyValuePairs.Add(string.Format("{0}:{1};", propInfo.Name, propInfo.GetValue(value, null).ToString()));
        }

        retVal = string.Join("", keyValuePairs.ToArray());

        return retVal;
    }

Then called like this:

        var person = new Person();
        person.Name = "Hello";
        person.Age = 10;
        Console.WriteLine(SplitNameValuePairs(person));

OwnerDisplayName: Tom Anderson