
org.glassfish.admin.rest.resources.TemplateRestResource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest-service Show documentation
Show all versions of rest-service Show documentation
Rest Interface for GlassFish Management and Monitoring
The newest version!
/*
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.admin.rest.resources;
import com.sun.enterprise.config.modularity.ConfigModularityUtils;
import com.sun.enterprise.util.LocalStringManagerImpl;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.DefaultValue;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.OPTIONS;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
import jakarta.ws.rs.core.UriInfo;
import java.io.File;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
import java.util.logging.Level;
import org.glassfish.admin.rest.Constants;
import org.glassfish.admin.rest.OptionsCapable;
import org.glassfish.admin.rest.RestLogging;
import org.glassfish.admin.rest.composite.metadata.RestResourceMetadata;
import org.glassfish.admin.rest.provider.MethodMetaData;
import org.glassfish.admin.rest.results.ActionReportResult;
import org.glassfish.admin.rest.results.OptionsResult;
import org.glassfish.admin.rest.utils.ResourceUtil;
import org.glassfish.admin.rest.utils.Util;
import org.glassfish.admin.rest.utils.xml.RestActionReporter;
import org.glassfish.api.ActionReport;
import org.glassfish.api.ActionReport.ExitCode;
import org.glassfish.api.admin.RestRedirect;
import org.glassfish.config.support.Delete;
import org.glassfish.hk2.api.MultiException;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
import org.jvnet.hk2.config.ConfigBean;
import org.jvnet.hk2.config.ConfigBeanProxy;
import org.jvnet.hk2.config.ConfigModel;
import org.jvnet.hk2.config.ConfigSupport;
import org.jvnet.hk2.config.Dom;
import org.jvnet.hk2.config.TransactionFailure;
import static org.glassfish.admin.rest.utils.Util.eleminateHypen;
/**
* @author Ludovic Champenois [email protected]
* @author Rajeshwar Patil
*/
@Produces({ "text/html", MediaType.APPLICATION_JSON + ";qs=0.5", MediaType.APPLICATION_XML + ";qs=0.5",
MediaType.APPLICATION_FORM_URLENCODED + ";qs=0.5" })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
public class TemplateRestResource extends AbstractResource implements OptionsCapable {
public static final LocalStringManagerImpl localStrings = new LocalStringManagerImpl(TemplateRestResource.class);
private static final List attributesToSkip = List.of("parent", "name", "children", "submit");
protected Dom entity; //may be null when not created yet...
protected Dom parent;
protected String tagName;
protected ConfigModel childModel; //good model even if the child entity is null
protected String childID; // id of the current child if part of a list, might be null
/**
* Creates a new instance of xxxResource
*/
public TemplateRestResource() {
}
@GET
public ActionReportResult getEntityLegacyFormat(@QueryParam("expandLevel") @DefaultValue("1") int expandLevel) {
if (childModel == null) {//wrong entity name at this point
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
return buildActionReportResult(true);
}
@GET
@Produces(Constants.MEDIA_TYPE_JSON + ";qs=0.5")
public Map getEntity(@QueryParam("expandLevel") @DefaultValue("1") int expandLevel) {
if (childModel == null) {//wrong entity name at this point
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
return getAttributes(getEntity());
}
@POST
//create or update
public Response createOrUpdateEntityLegacyFormat(HashMap data) {
return Response.ok(ResourceUtil.getActionReportResult(doCreateOrUpdate(data),
localStrings.getLocalString("rest.resource.update.message", "\"{0}\" updated successfully.", uriInfo.getAbsolutePath()),
requestHeaders, uriInfo)).build();
}
@POST
@Produces(Constants.MEDIA_TYPE_JSON + ";qs=0.5")
public Response createOrUpdateEntity(HashMap data) {
doCreateOrUpdate(data);
return Response.status(Status.CREATED).build();
}
/**
* allows for remote files to be put in a tmp area and we pass the local location of this file to the corresponding
* command instead of the content of the file * Yu need to add enctype="multipart/form-data" in the form for ex:
*
© 2015 - 2025 Weber Informatics LLC | Privacy Policy