use of jetbrains.buildServer.server.rest.errors.OperationException in project teamcity-rest by JetBrains.
the class PropEntityTrigger method addToInternalMain.
@NotNull
public BuildTriggerDescriptor addToInternalMain(@NotNull final BuildTypeSettingsEx buildType, @NotNull final ServiceLocator serviceLocator) {
if (StringUtil.isEmpty(type)) {
throw new BadRequestException("Build trigger cannot have empty 'type'.");
}
BuildTriggerDescriptor similar = getInheritedOrSameIdSimilar(buildType, serviceLocator);
if (inherited != null && inherited && similar != null) {
return similar;
}
if (similar != null && id != null && id.equals(similar.getId())) {
// todo
return similar;
}
final BuildTriggerDescriptor triggerToAdd = serviceLocator.getSingletonService(BuildTriggerDescriptorFactory.class).createTriggerDescriptor(type, properties == null ? Collections.emptyMap() : properties.getMap(), buildTriggerCustomization == null ? BuildCustomizationSettings.empty() : buildTriggerCustomization.toBuildCustomizationSettings(serviceLocator));
if (!buildType.addBuildTrigger(triggerToAdd)) {
String additionalMessage = getDetails(buildType, triggerToAdd);
throw new OperationException("Build trigger addition failed." + (additionalMessage != null ? " " + additionalMessage : ""));
}
if (disabled != null) {
buildType.setEnabled(triggerToAdd.getId(), !disabled);
}
BuildTriggerDescriptor result = buildType.findTriggerById(triggerToAdd.getId());
if (result == null) {
throw new OperationException("Cannot find just added trigger with id '" + triggerToAdd.getId() + "'");
}
return result;
}
use of jetbrains.buildServer.server.rest.errors.OperationException in project teamcity-rest by JetBrains.
the class Sessions method getSessions.
@NotNull
private Collection<Session> getSessions(@NotNull final MBeanServer serverBean, @NotNull final ObjectName managerBean, @NotNull final Fields fields, @NotNull final BeanContext beanContext) {
String sessionsListRaw;
try {
sessionsListRaw = String.valueOf(serverBean.invoke(managerBean, "listSessionIds", null, null));
} catch (Exception e) {
throw new OperationException("Could not get sessions data: " + e.toString(), e);
}
final String[] sessionIds = sessionsListRaw.split(" ");
final ArrayList<Session> result = new ArrayList<Session>(sessionIds.length);
for (String sessionId : sessionIds) {
Long userId;
try {
userId = getSessionUserId(serverBean, managerBean, sessionId);
} catch (Exception e) {
userId = null;
LOG.debug("Cannot retrieve userId for session with id '" + sessionId + "': " + e.toString());
}
Long creationTimestamp = (Long) getBeanOperationResult(serverBean, managerBean, sessionId, "getCreationTimestamp");
Long lastAccessedTimestamp = (Long) getBeanOperationResult(serverBean, managerBean, sessionId, "getLastAccessedTimestamp");
result.add(new Session(sessionId, userId, creationTimestamp == null ? null : new Date(creationTimestamp), lastAccessedTimestamp == null ? null : new Date(lastAccessedTimestamp), fields, beanContext));
}
return SESSION_ORDERING.sortedCopy(result);
}
use of jetbrains.buildServer.server.rest.errors.OperationException in project teamcity-rest by JetBrains.
the class FilesSubResource method processCoreDownload.
private void processCoreDownload(@NotNull final Element element, @NotNull final HttpServletRequest request, @NotNull final HttpServletResponse response) {
setCacheControl(request, response);
boolean setContentDisposition = getSetContentDisposition(element, request, response);
try {
myBeanContext.getSingletonService(HttpDownloadProcessor.class).processDownload(new HttpDownloadProcessor.FileInfo() {
@Override
public long getLastModified() {
return FilesSubResource.getLastModified(element);
}
@Override
public long getFileSize() {
return element.getSize();
}
@Override
@NotNull
public String getFileName() {
return element.getName();
}
@Override
@NotNull
public String getFileDigest() {
// note: "aggregated" build artifacts are still not handled in due way here
return getETag(element, myUrlPrefix);
}
@Override
@NotNull
public InputStream getInputStream() throws IOException {
// todo: see this method in HttpDownloadProcessor
return element.getInputStream();
}
}, setContentDisposition, /*header is forced to attachment above*/
request, response);
} catch (IOException e) {
// todo add better processing
throw new OperationException("Error while processing file '" + element.getFullName() + "': " + e.toString(), e);
}
}
use of jetbrains.buildServer.server.rest.errors.OperationException in project teamcity-rest by JetBrains.
the class DebugRequest method saveMemoryDump.
/**
* Experimental use only!
*/
@POST
@Path("/memory/dumps")
@Produces({ "text/plain" })
public String saveMemoryDump(@QueryParam("archived") Boolean archived, @Context HttpServletRequest request) {
myDataProvider.checkGlobalPermission(Permission.MANAGE_SERVER_INSTALLATION);
final File logsPath = myDataProvider.getBean(ServerPaths.class).getLogsPath();
try {
final File memoryDumpFile = DiagnosticUtil.memoryDump(new File(logsPath, "memoryDumps"), archived == null || archived, "via REST API by user " + LogUtil.describe(SessionUser.getUser(request)), Loggers.SERVER);
return memoryDumpFile.getAbsolutePath();
} catch (Exception e) {
throw new OperationException("Error saving memory dump", e);
}
}
use of jetbrains.buildServer.server.rest.errors.OperationException in project teamcity-rest by JetBrains.
the class DebugRequest method getRequestDetails.
/**
* Experimental use only!
*/
@GET
// "extra" here is to allow checking arbitrary chars in the URL path
@Path("/currentRequest/details" + "{extra:(/.*)?}")
@Produces({ "text/plain" })
public String getRequestDetails(@PathParam("extra") final String extra, @Context HttpServletRequest request) {
if (!TeamCityProperties.getBoolean("rest.debug.currentRequest.details.allowUnauthorized")) {
myDataProvider.checkGlobalPermission(Permission.MANAGE_SERVER_INSTALLATION);
}
StringBuilder result = new StringBuilder();
String remoteAddress = WebUtil.hostAndPort(request.getRemoteAddr(), request.getRemotePort());
result.append("Client address: ").append(remoteAddress);
String refinedRemoteAddress = WebUtil.hostAndPort(WebUtil.getRemoteAddress(request), request.getRemotePort());
if (!refinedRemoteAddress.equals(remoteAddress))
result.append(" (").append(refinedRemoteAddress).append(")");
result.append("\n");
result.append("Local address: ").append(WebUtil.hostAndPort(request.getLocalAddr(), request.getLocalPort())).append("\n");
if (request.getLocalPort() != request.getServerPort()) {
result.append("Server port: ").append(request.getServerPort()).append("\n");
}
result.append("Method: ").append(request.getMethod()).append("\n");
result.append("Scheme: ").append(request.getScheme()).append("\n");
result.append("Path and query: ").append(WebUtil.getRequestUrl(request)).append("\n");
if (!StringUtil.isEmpty(extra))
result.append("Extra path: ").append(extra).append("\n");
result.append("Session id: ").append(request.getSession().getId()).append("\n");
result.append("Request object instance hash: ").append(Integer.toHexString(request.hashCode())).append("\n");
result.append("Current TeamCity user: ").append(myServiceLocator.getSingletonService(PermissionChecker.class).getCurrentUserDescription()).append("\n");
result.append("\n");
result.append("Headers:\n");
Enumeration<String> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName = headerNames.nextElement();
Enumeration<String> headers = request.getHeaders(headerName);
while (headers.hasMoreElements()) {
String header = headers.nextElement();
result.append(headerName).append(": ").append(header).append("\n");
}
}
result.append("\n");
try {
// consider using byte-to-byte copy method
StringUtil.processLines(request.getInputStream(), new StringUtil.LineProcessor() {
@Override
public boolean processLine(final String line) {
result.append(line);
return true;
}
});
} catch (IOException e) {
throw new OperationException("Error reading request body: " + e.getMessage(), e);
}
return result.toString();
}
Aggregations