Uploaded image for project: 'Dev - Nexus Repo'
  1. Dev - Nexus Repo
  2. NEXUS-9962

Unable to create proxy repository via REST API

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 2.11.4
    • Fix Version/s: None
    • Component/s: Proxy Repository, REST
    • Labels:
      None

      Description

      When I follow the documentation for using the REST API to add repository, I get an error hinting that I am not providing enough information:

      Request (of type repositoryResourceResponse):

      <?xml version="1.0" encoding="UTF-8"?><repository><data><name>Releases_proxy</name><repoType>proxy</repoType><providerRole>org.sonatype.nexus.proxy.repository.Repository</providerRole><exposed>true</exposed><id>releases_proxy</id><provider>maven2</provider><contentResourceURI>http://host2/nexus/content/repositories/releases/</contentResourceURI><format>maven2</format><remoteStorage><authentication><username>userhash</username><password>passwordhash</password></authentication></remoteStorage></data></repository>
      

      Response:

      <nexus-error><errors><error><id>*</id><msg>No enum const class org.sonatype.nexus.proxy.maven.RepositoryPolicy.null</msg></error></errors></nexus-error>
      

      Log:

      2016-03-17 08:42:57,515-0400 DEBUG [qtp836514715-4785] admin org.sonatype.nexus.restlet1x.internal.RestletServlet - Processing: POST /service/local/repositories (https://host1/service/local/repositories)
      

      Through trial an error, I have been able to work past the deserialization errors by adding elements from other complex types complex types (such as writePolicy, indexable, repoPolicy, remoteStorage, etc); however, I have two errors that appear to be mutually exclusive concerning the existance of /repository/data/remoteStorage/url.

      Error 1 - Request:

      <?xml version="1.0" encoding="UTF-8"?><repository><data><name>Releases_proxy</name><repoType>proxy</repoType><providerRole>org.sonatype.nexus.proxy.repository.Repository</providerRole><exposed>true</exposed><id>releases_proxy</id><provider>maven2</provider><contentResourceURI>http://host2/nexus/content/repositories/releases/</contentResourceURI><format>maven2</format><browseable>true</browseable><writePolicy>READ_ONLY</writePolicy><indexable>true</indexable><repoPolicy>MIXED</repoPolicy><remoteStorage><authentication><username>userhash</username><password>passwordhash</password></authentication></remoteStorage></data></repository>
      

      Error 1 - Response:
      500 Internal Server Error

      Error 1 - Log:

      2016-03-17 08:49:25,514-0400 DEBUG [qtp836514715-4792] admin org.sonatype.nexus.restlet1x.internal.RestletServlet - Processing: POST /service/local/repositories (https://nexus.swift.com/service/local/repositories)
      2016-03-17 08:49:25,573-0400 ERROR [qtp836514715-4792] admin org.sonatype.nexus.rest.NexusRestletResource - java.lang.IllegalArgumentException: Remote URL cannot be null!
      java.lang.IllegalArgumentException: Remote URL cannot be null!
      	at org.sonatype.nexus.proxy.storage.remote.DefaultRemoteProviderHintFactory.getDefaultRoleHint(DefaultRemoteProviderHintFactory.java:60) ~[nexus-core-2.11.4-01.jar:2.11.4-01]
      	at org.sonatype.nexus.rest.repositories.RepositoryListPlexusResource.getRepositoryAppModel(RepositoryListPlexusResource.java:251) ~[nexus-restlet1x-plugin-2.11.4-01/:na]
      	at org.sonatype.nexus.rest.repositories.RepositoryListPlexusResource.post(RepositoryListPlexusResource.java:134) ~[nexus-restlet1x-plugin-2.11.4-01/:na]
      	at org.sonatype.plexus.rest.resource.RestletResource.acceptRepresentation(RestletResource.java:262) ~[nexus-restlet1x-plugin-2.11.4-01/:na]
      	at org.sonatype.nexus.rest.NexusRestletResource.acceptRepresentation(NexusRestletResource.java:70) ~[nexus-restlet1x-plugin-2.11.4-01/:na]
      	at org.restlet.resource.Resource.post(Resource.java:688) [nexus-restlet1x-plugin-2.11.4-01/:na]
      	at org.restlet.resource.Resource.handlePost(Resource.java:537) [nexus-restlet1x-plugin-2.11.4-01/:na]
      

      Error 2 - Request:

      <?xml version="1.0" encoding="UTF-8"?><repository><data><name>Releases_proxy</name><repoType>proxy</repoType><providerRole>org.sonatype.nexus.proxy.repository.Repository</providerRole><exposed>true</exposed><id>releases_proxy</id><provider>maven2</provider><contentResourceURI>http://host2/nexus/content/repositories/releases/</contentResourceURI><format>maven2</format><browseable>true</browseable><writePolicy>READ_ONLY</writePolicy><indexable>true</indexable><repoPolicy>MIXED</repoPolicy><remoteStorage><url>http://host2/nexus/content/repositories/releases/</url><authentication><username>userhash</username><password>passwordhash</password></authentication></remoteStorage></data></repository>
      

      Error 2 - Response:
      400 Bad Request

      Error 2 - Log:

      2016-03-17 08:53:48,966-0400 DEBUG [qtp836514715-4797] admin org.sonatype.nexus.restlet1x.internal.RestletServlet - Processing: POST /service/local/repositories (https://nexus.swift.com/service/local/repositories)
      2016-03-17 08:53:49,016-0400 WARN  [qtp836514715-4797] admin org.sonatype.nexus.rest.NexusRestletResource - Invalid XML, unable to parse using XStream class org.sonatype.nexus.rest.repositories.RepositoryListPlexusResource
      com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field org.sonatype.nexus.rest.model.RepositoryResourceRemoteStorage.url
      ---- Debugging information ----
      field               : url
      class               : org.sonatype.nexus.rest.model.RepositoryResourceRemoteStorage
      required-type       : org.sonatype.nexus.rest.model.RepositoryResourceRemoteStorage
      converter-type      : com.thoughtworks.xstream.XStream$WhitelistReflectionConverter
      path                : /repository/data/remoteStorage/url
      line number         : 1
      class[1]            : org.sonatype.nexus.rest.model.RepositoryBaseResource
      converter-type[1]   : org.sonatype.nexus.rest.repositories.RepositoryBaseResourceConverter
      class[2]            : org.sonatype.nexus.rest.model.RepositoryResourceResponse
      converter-type[2]   : org.sonatype.nexus.rest.repositories.RepositoryResourceResponseConverter
      version             : 1.4.6-SONATYPE-03
      -------------------------------
      	at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.handleUnknownField(AbstractReflectionConverter.java:495) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:351) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:257) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:474) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:406) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:257) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:474) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:406) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:257) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1537) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1521) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1451) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1439) ~[xstream-1.4.6-SONATYPE-03.jar:1.4.6-SONATYPE-03]
      	at org.sonatype.plexus.rest.representation.XStreamRepresentation.getPayload(XStreamRepresentation.java:66) ~[nexus-restlet1x-plugin-2.11.4-01/:na]
      	at org.sonatype.plexus.rest.resource.RestletResource.deserialize(RestletResource.java:174) [nexus-restlet1x-plugin-2.11.4-01/:na]
      	at org.sonatype.plexus.rest.resource.RestletResource.acceptRepresentation(RestletResource.java:257) [nexus-restlet1x-plugin-2.11.4-01/:na]
      	at org.sonatype.nexus.rest.NexusRestletResource.acceptRepresentation(NexusRestletResource.java:70) [nexus-restlet1x-plugin-2.11.4-01/:na]
      	at org.restlet.resource.Resource.post(Resource.java:688) [nexus-restlet1x-plugin-2.11.4-01/:na]
      

      With a little googling, I was able to find a copy of the source code where I noticed a concerning comment on line 139.

      I suspect that the combination of deserializing into RepositoryResourceResponse and the subsequent conversion to CRepository are causing my problem.

      If this is so, is there a work around? If not, can you please provide a working example of how to create a proxy repository using the API?

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            rdavis Richard Davis
            Last Updated By:
            Peter Lynch Peter Lynch
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Date of First Response:

                tigCommentSecurity.panel-title