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