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 prepend to any existing
041         *                      path component in the base URI. Must not be
042         *                      {@code null}.
043         */
044        public AbstractConfigurationRequest(final URI baseURI, final String wellKnownPath) {
045                
046                super(URIUtils.prependPath(baseURI, wellKnownPath));
047        }
048        
049        
050        @Override
051        public HTTPRequest toHTTPRequest() {
052                
053                URL url;
054                try {
055                        url = getEndpointURI().toURL();
056                } catch (IllegalArgumentException | MalformedURLException e) {
057                        throw new SerializeException(e.getMessage(), e);
058                }
059                
060                return new HTTPRequest(HTTPRequest.Method.GET, url);
061        }
062}