// Path: NetLicensingClient/src/main/java/com/labs64/netlicensing/exception/RestException.java
// public class RestException extends NetLicensingException {
// 
//     private static final long serialVersionUID = -3863879794574523844L;
// 
//     /**
//      * Construct a <code>RestException</code> with the specified detail message.
//      * 
//      * @param msg
//      *            the detail message
//      */
//     public RestException(final String msg) {
//         super(msg);
//     }
// 
//     /**
//      * Construct a <code>RestException</code> with the specified detail message and cause exception.
//      * 
//      * @param msg
//      *            the detail message
//      * @param cause
//      *            the cause exception
//      */
//     public RestException(final String msg, final Throwable cause) {
//         super(msg, cause);
//     }
// 
// }
// 
// Path: NetLicensingClient/src/main/java/com/labs64/netlicensing/provider/auth/Authentication.java
// public interface Authentication {
// 	
// 	String getUsername();
// 	
// 	String getPassword();
// 
// }


import java.util.Map;
import javax.ws.rs.ProcessingException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.NoContentException;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import com.labs64.netlicensing.exception.RestException;
import com.labs64.netlicensing.provider.auth.Authentication;
/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.labs64.netlicensing.provider;





/**
 * Low level REST client implementation.
 * <p>
 * This will also log each request in INFO level.
 */
public class RestProviderJersey extends AbstractRestProvider {

    private static final MediaType[] DEFAULT_ACCEPT_TYPES = { MediaType.APPLICATION_XML_TYPE };

    private static Client client;

    private final String basePath;

    private class JerseyDefaultConfig implements RestProvider.Configuration {

        @Override
        public String getUserAgent() {
            return "NetLicensing/Java " + System.getProperty("java.version") + " (https://netlicensing.io)";
        }

        @Override
        public boolean isLoggingEnabled() {
            return true;
        }

    }

    /**
     * @param basePath
     *            base provider path
     */
    public RestProviderJersey(final String basePath) {
        this.basePath = basePath;
        configure(new JerseyDefaultConfig());
    }

    /*
     * @see com.labs64.netlicensing.provider.RestProvider#call(java.lang.String, java.lang.String, java.lang.Object,
     * java.lang.Class, java.util.Map)
     */
    @Override
    public <REQ, RES> RestResponse<RES> call(final String httpMethod, final String urlTemplate, final REQ request,
            final Class<RES> responseType,
// Path: NetLicensingClient/src/main/java/com/labs64/netlicensing/exception/RestException.java
// public class RestException extends NetLicensingException {
// 
//     private static final long serialVersionUID = -3863879794574523844L;
// 
//     /**
//      * Construct a <code>RestException</code> with the specified detail message.
//      * 
//      * @param msg
//      *            the detail message
//      */
//     public RestException(final String msg) {
//         super(msg);
//     }
// 
//     /**
//      * Construct a <code>RestException</code> with the specified detail message and cause exception.
//      * 
//      * @param msg
//      *            the detail message
//      * @param cause
//      *            the cause exception
//      */
//     public RestException(final String msg, final Throwable cause) {
//         super(msg, cause);
//     }
// 
// }
// 
// Path: NetLicensingClient/src/main/java/com/labs64/netlicensing/provider/auth/Authentication.java
// public interface Authentication {
// 	
// 	String getUsername();
// 	
// 	String getPassword();
// 
// }


// Path: NetLicensingClient/src/main/java/com/labs64/netlicensing/provider/RestProviderJersey.java
import java.util.Map;
import javax.ws.rs.ProcessingException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.NoContentException;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import com.labs64.netlicensing.exception.RestException;
import com.labs64.netlicensing.provider.auth.Authentication;

/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.labs64.netlicensing.provider;





/**
 * Low level REST client implementation.
 * <p>
 * This will also log each request in INFO level.
 */
public class RestProviderJersey extends AbstractRestProvider {

    private static final MediaType[] DEFAULT_ACCEPT_TYPES = { MediaType.APPLICATION_XML_TYPE };

    private static Client client;

    private final String basePath;

    private class JerseyDefaultConfig implements RestProvider.Configuration {

        @Override
        public String getUserAgent() {
            return "NetLicensing/Java " + System.getProperty("java.version") + " (https://netlicensing.io)";
        }

        @Override
        public boolean isLoggingEnabled() {
            return true;
        }

    }

    /**
     * @param basePath
     *            base provider path
     */
    public RestProviderJersey(final String basePath) {
        this.basePath = basePath;
        configure(new JerseyDefaultConfig());
    }

    /*
     * @see com.labs64.netlicensing.provider.RestProvider#call(java.lang.String, java.lang.String, java.lang.Object,
     * java.lang.Class, java.util.Map)
     */
    @Override
    public <REQ, RES> RestResponse<RES> call(final String httpMethod, final String urlTemplate, final REQ request,
            final Class<RES> responseType,
            final Map<String, Object> queryParams) throws RestException {