Java Code Examples for com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse#setResponseBody()
The following examples show how to use
com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse#setResponseBody() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerHealthRequestProcessor.java From gocd with Apache License 2.0 | 6 votes |
@Override public GoApiResponse process(GoPluginDescriptor pluginDescriptor, GoApiRequest goPluginApiRequest) { String errorMessageTitle = format("Message from plugin: {0}", pluginDescriptor.id()); HealthStateScope scope = HealthStateScope.fromPlugin(pluginDescriptor.id()); try { MessageHandlerForServerHealthRequestProcessor messageHandler = versionToMessageHandlerMap.get(goPluginApiRequest.apiVersion()); List<PluginHealthMessage> pluginHealthMessages = messageHandler.deserializeServerHealthMessages(goPluginApiRequest.requestBody()); replaceServerHealthMessages(errorMessageTitle, scope, pluginHealthMessages); } catch (Exception e) { DefaultGoApiResponse response = new DefaultGoApiResponse(DefaultGoApiResponse.INTERNAL_ERROR); response.setResponseBody(format("'{' \"message\": \"{0}\" '}'", e.getMessage())); LOGGER.warn("Failed to handle message from plugin {}: {}", pluginDescriptor.id(), goPluginApiRequest.requestBody(), e); return response; } return new DefaultGoApiResponse(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE); }
Example 2
Source File: ConsoleLogRequestProcessor.java From gocd with Apache License 2.0 | 6 votes |
@Override public GoApiResponse process(GoPluginDescriptor pluginDescriptor, GoApiRequest request) { try { validatePluginRequest(request); final MessageHandlerForConsoleLogRequestProcessor handler = versionToMessageHandlerMap.get(request.apiVersion()); final ConsoleLogAppendRequest logUpdateRequest = handler.deserializeConsoleLogAppendRequest(request.requestBody()); consoleService.appendToConsoleLog(logUpdateRequest.jobIdentifier(), logUpdateRequest.text()); } catch (Exception e) { DefaultGoApiResponse response = new DefaultGoApiResponse(DefaultGoApiResponse.INTERNAL_ERROR); response.setResponseBody(format("'{' \"message\": \"Error: {0}\" '}'", e.getMessage())); LOGGER.warn("Failed to handle message from plugin {}: {}", pluginDescriptor.id(), request.requestBody(), e); return response; } return new DefaultGoApiResponse(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE); }
Example 3
Source File: PluginSettingsRequestProcessor.java From gocd with Apache License 2.0 | 6 votes |
@Override public GoApiResponse process(GoPluginDescriptor pluginDescriptor, GoApiRequest goPluginApiRequest) { try { MessageHandlerForPluginSettingsRequestProcessor processor = versionToMessageHandlerMap.get(goPluginApiRequest.apiVersion()); DefaultGoApiResponse response = new DefaultGoApiResponse(200); response.setResponseBody(processor.pluginSettingsToJSON(pluginSettingsFor(pluginDescriptor.id()))); return response; } catch (Exception e) { LOGGER.error(format("Error processing PluginSettings request from plugin: %s.", pluginDescriptor.id()), e); DefaultGoApiResponse errorResponse = new DefaultGoApiResponse(400); errorResponse.setResponseBody(format("Error while processing get PluginSettings request - %s", e.getMessage())); return errorResponse; } }
Example 4
Source File: GitHubBuildStatusNotifierPluginTest.java From gocd-build-status-notifier with Apache License 2.0 | 5 votes |
@Before public void setUp() { initMocks(this); plugin = new GitHubBuildStatusNotifierPlugin(); DefaultGoApiResponse pluginSettingsResponse = new DefaultGoApiResponse(200); pluginSettingsResponse.setResponseBody(JSONUtils.toJSON(new HashMap<String, String>())); when(goApplicationAccessor.submit(any(GoApiRequest.class))).thenReturn(pluginSettingsResponse); when(provider.pluginId()).thenReturn(PLUGIN_ID); when(provider.pollerPluginId()).thenReturn(POLLER_PLUGIN_ID); plugin.initializeGoApplicationAccessor(goApplicationAccessor); plugin.setProvider(provider); }
Example 5
Source File: GerritBuildStatusNotifierPluginTest.java From gocd-build-status-notifier with Apache License 2.0 | 5 votes |
@Before public void setUp() { initMocks(this); plugin = new GerritBuildStatusNotifierPlugin(); DefaultGoApiResponse pluginSettingsResponse = new DefaultGoApiResponse(200); pluginSettingsResponse.setResponseBody(JSONUtils.toJSON(new HashMap<String, String>())); when(goApplicationAccessor.submit(any(GoApiRequest.class))).thenReturn(pluginSettingsResponse); when(provider.pluginId()).thenReturn(PLUGIN_ID); when(provider.pollerPluginId()).thenReturn(POLLER_PLUGIN_ID); plugin.initializeGoApplicationAccessor(goApplicationAccessor); plugin.setProvider(provider); }
Example 6
Source File: StashBuildStatusNotifierPluginTest.java From gocd-build-status-notifier with Apache License 2.0 | 5 votes |
@Before public void setUp() { initMocks(this); plugin = new StashBuildStatusNotifierPlugin(); DefaultGoApiResponse pluginSettingsResponse = new DefaultGoApiResponse(200); pluginSettingsResponse.setResponseBody(JSONUtils.toJSON(new HashMap<String, String>())); when(goApplicationAccessor.submit(any(GoApiRequest.class))).thenReturn(pluginSettingsResponse); when(provider.pluginId()).thenReturn(PLUGIN_ID); when(provider.pollerPluginId()).thenReturn(POLLER_PLUGIN_ID); plugin.initializeGoApplicationAccessor(goApplicationAccessor); plugin.setProvider(provider); }