All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jk.services.server.JKServiceConfig Maven / Gradle / Ivy

Go to download

A set wrappers, filters, and API's that enables faster development in microservices in Java

The newest version!
/*
 * Copyright 2002-2023 Dr. Jalal Kiswani. 
 * Email: [email protected]
 * Check out https://j-framework.com for more details
 * 
 * All the opensource projects of Dr. Jalal Kiswani are free for personal and academic use only, 
 * for commercial usage and support, please contact the author.
 *
 * 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.jk.services.server;

import java.util.Date;

import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature;

import com.jk.core.logging.JKLogger;
import com.jk.core.logging.JKLoggerFactory;
import com.jk.core.util.JK;
import com.jk.services.server.commons.util.JKLogServicePublisher;
import com.jk.services.server.listeners.JKApplicationEventListener;
import com.jk.web.monitoring.JKMonitorService;

import jakarta.ws.rs.ApplicationPath;

/**
 * This class extends {@link ResourceConfig}, which provides configuration
 * options for a Jersey application.
 * 
 * @author Dr. Jalal H. Kiswani
 * @version 1.0
 */
@ApplicationPath("util")
public class JKServiceConfig extends ResourceConfig {

	/**
	 * Represents the date of initialization for this Jersey application
	 * configuration.
	 */
	public static final Date LOAD_TIME = new Date();

	/**
	 * Represents the class logger.
	 */
	protected JKLogger logger = JKLoggerFactory.getLogger(getClass());

	/**
	 * This method constructs a new {@code JKServiceConfig} and initialize it.
	 */
	public JKServiceConfig() {
		init();

	}

	/**
	 * This method initializes the Jersey application configuration.
	 */
	protected void init() {
		logger.debug("RestServer initialized to packages {}", getPackagesToScan());

		packages(getPackagesToScan());
		registerComponents();
		JK.fixMe("Log current end points...");
	}

	/**
	 * This method registers various components used in the Jersey application.
	 */
	protected void registerComponents() {
		register(RolesAllowedDynamicFeature.class);
		register(MultiPartFeature.class);

		register(JKJerseyObjectMapperProvider.class);

		register(JKServiceExceptionHandler.class);
		register(JKServiceFilter.class);

		register(JKApplicationEventListener.class);
		JKMonitorService.setInstance(new JKLogServicePublisher());
	}

	/**
	 * This method determines the packages to scan for Jersey resources and
	 * components.
	 *
	 * @return the packages to scan for Jersey resources and components.
	 */
	protected String getPackagesToScan() {
		return getClass().getPackage().getName();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String getApplicationName() {
		String applicationName = super.getApplicationName();
		if (applicationName == null) {
			ApplicationPath path = getClass().getAnnotation(ApplicationPath.class);
			if (path != null) {
				applicationName = path.value();
			}
		}
		return applicationName;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy