001/*
002 * oauth2-oidc-sdk
003 *
004 * Copyright 2012-2016, Connect2id Ltd and contributors.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
007 * this file except in compliance with the License. You may obtain a copy of the
008 * License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software distributed
013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
015 * specific language governing permissions and limitations under the License.
016 */
017
018package com.nimbusds.oauth2.sdk;
019
020
021import java.net.MalformedURLException;
022import java.net.URI;
023import java.net.URL;
024
025import com.nimbusds.oauth2.sdk.http.HTTPRequest;
026import com.nimbusds.oauth2.sdk.util.URIUtils;
027
028
029/**
030 * The base abstract class for OAuth 2.0 and OpenID Connect configuration
031 * requests.
032 */
033public abstract class AbstractConfigurationRequest extends AbstractRequest {
034        
035        
036        /**
037         * Creates a new base abstract request.
038         *
039         * @param baseURI       The base URI. Must not be {@code null}.
040         * @param wellKnownPath The well known path to append to the base URI.
041         *                      Must not be {@code null}.
042         */
043        public AbstractConfigurationRequest(final URI baseURI, final String wellKnownPath) {
044                
045                super(URI.create(URIUtils.removeTrailingSlash(baseURI) + wellKnownPath));
046        }
047        
048        
049        @Override
050        public HTTPRequest toHTTPRequest() {
051                
052                URL url;
053                try {
054                        url = getEndpointURI().toURL();
055                } catch (IllegalArgumentException | MalformedURLException e) {
056                        throw new SerializeException(e.getMessage(), e);
057                }
058                
059                return new HTTPRequest(HTTPRequest.Method.GET, url);
060        }
061}