View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.transport.http;
20  
21  import javax.inject.Inject;
22  import javax.inject.Named;
23  
24  import java.util.Map;
25  
26  import org.eclipse.aether.RepositorySystemSession;
27  import org.eclipse.aether.repository.RemoteRepository;
28  import org.eclipse.aether.spi.connector.transport.Transporter;
29  import org.eclipse.aether.spi.connector.transport.TransporterFactory;
30  import org.eclipse.aether.transfer.NoTransporterException;
31  
32  import static java.util.Objects.requireNonNull;
33  
34  /**
35   * A transporter factory for repositories using the {@code http:} or {@code https:} protocol. The provided transporters
36   * support uploads to WebDAV servers and resumable downloads.
37   */
38  @Named(HttpTransporterFactory.NAME)
39  public final class HttpTransporterFactory implements TransporterFactory {
40      public static final String NAME = "http";
41  
42      private float priority = 5.0f;
43  
44      private final Map<String, ChecksumExtractor> extractors;
45  
46      /**
47       * Creates an (uninitialized) instance of this transporter factory. <em>Note:</em> In case of manual instantiation
48       * by clients, the new factory needs to be configured via its various mutators before first use or runtime errors
49       * will occur.
50       */
51      @Inject
52      public HttpTransporterFactory(Map<String, ChecksumExtractor> extractors) {
53          this.extractors = requireNonNull(extractors);
54      }
55  
56      @Override
57      public float getPriority() {
58          return priority;
59      }
60  
61      /**
62       * Sets the priority of this component.
63       *
64       * @param priority The priority.
65       * @return This component for chaining, never {@code null}.
66       */
67      public HttpTransporterFactory setPriority(float priority) {
68          this.priority = priority;
69          return this;
70      }
71  
72      @Override
73      public Transporter newInstance(RepositorySystemSession session, RemoteRepository repository)
74              throws NoTransporterException {
75          requireNonNull(session, "session cannot be null");
76          requireNonNull(repository, "repository cannot be null");
77  
78          return new HttpTransporter(extractors, repository, session);
79      }
80  }