> h = new HashMap<>(1);
- h.put("Content-Type", Arrays.asList("application/json"));
+ h.put(HttpHeaders.CONTENT_TYPE, Arrays.asList(MediaType.APPLICATION_JSON));
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
- ContainerResponse response = launcher.service("POST", requestPath, BASE_URI, h, properties.getBytes(), writer, null);
+ ContainerResponse response = launcher.service(HttpMethod.POST, requestPath, BASE_URI, h, properties.getBytes(), writer, null);
assertEquals(403, response.getStatus());
log.info(new String(writer.getBody()));
diff --git a/che-core-vfs-impl/src/test/java/org/eclipse/che/vfs/impl/fs/UploadFileTest.java b/che-core-vfs-impl/src/test/java/org/eclipse/che/vfs/impl/fs/UploadFileTest.java
index 09d5882d7..4933a17ae 100644
--- a/che-core-vfs-impl/src/test/java/org/eclipse/che/vfs/impl/fs/UploadFileTest.java
+++ b/che-core-vfs-impl/src/test/java/org/eclipse/che/vfs/impl/fs/UploadFileTest.java
@@ -12,6 +12,7 @@
import org.eclipse.che.api.vfs.shared.dto.Principal;
import org.eclipse.che.dto.server.DtoFactory;
+
import com.google.common.collect.Sets;
import org.everrest.core.impl.ContainerResponse;
@@ -20,6 +21,10 @@
import org.everrest.test.mock.MockHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+
import java.io.ByteArrayInputStream;
import java.util.Arrays;
import java.util.HashMap;
@@ -58,7 +63,7 @@ public void setUp() throws Exception {
public void testUploadNewFile() throws Exception {
final String fileName = "testUploadNewFile";
final String fileContent = "test upload file";
- final String fileMediaType = "text/plain";
+ final String fileMediaType = MediaType.TEXT_PLAIN;
ContainerResponse response = doUploadFile(folderId, fileName, fileMediaType, fileContent, "", "", false);
assertEquals("Error: " + response.getEntity(), 200, response.getStatus());
assertTrue(((String)response.getEntity()).isEmpty()); // empty if successful
@@ -74,7 +79,7 @@ public void testUploadNewFile() throws Exception {
public void testUploadNewFileNoPermissions() throws Exception {
final String fileName = "testUploadNewFileNoPermissions";
final String fileContent = "test upload file";
- final String fileMediaType = "text/plain";
+ final String fileMediaType = MediaType.TEXT_PLAIN;
ContainerResponse response = doUploadFile(protectedFolderId, fileName, fileMediaType, fileContent, "", "", false);
assertEquals("Error: " + response.getEntity(), 200, response.getStatus()); // always 200 even for errors
assertTrue(((String)response.getEntity()).startsWith("message: "));
@@ -85,7 +90,7 @@ public void testUploadNewFileNoPermissions() throws Exception {
public void testUploadNewFileInRootFolder() throws Exception {
final String fileName = "testUploadNewFile";
final String fileContent = "test upload file";
- final String fileMediaType = "text/plain";
+ final String fileMediaType = MediaType.TEXT_PLAIN;
folderId = ROOT_ID;
ContainerResponse response = doUploadFile(folderId, fileName, fileMediaType, fileContent, "", "", false);
assertEquals("Error: " + response.getEntity(), 200, response.getStatus());
@@ -101,7 +106,7 @@ public void testUploadNewFileInRootFolder() throws Exception {
public void testUploadNewFileCustomizeName() throws Exception {
final String fileName = "testUploadNewFileCustomizeName";
final String fileContent = "test upload file with custom name";
- final String fileMediaType = "text/plain";
+ final String fileMediaType = MediaType.TEXT_PLAIN;
// Name of file passed in HTML form. If present it should be used instead of original file name.
final String formFileName = fileName + ".txt";
ContainerResponse response = doUploadFile(folderId, fileName, fileMediaType, fileContent, "", formFileName, false);
@@ -118,9 +123,9 @@ public void testUploadNewFileCustomizeName() throws Exception {
public void testUploadNewFileCustomizeMediaType() throws Exception {
final String fileName = "testUploadNewFileCustomizeMediaType";
final String fileContent = "test upload file with custom media type";
- final String fileMediaType = "application/octet-stream";
+ final String fileMediaType = MediaType.APPLICATION_OCTET_STREAM;
final String formFileName = fileName + ".txt";
- final String formMediaType = "text/plain"; // should be used instead of fileMediaType
+ final String formMediaType = MediaType.TEXT_PLAIN; // should be used instead of fileMediaType
ContainerResponse response =
doUploadFile(folderId, fileName, fileMediaType, fileContent, formMediaType, formFileName, false);
assertEquals("Error: " + response.getEntity(), 200, response.getStatus());
@@ -136,7 +141,7 @@ public void testUploadNewFileCustomizeMediaType() throws Exception {
public void testUploadFileAlreadyExists() throws Exception {
final String fileName = "existedFile";
- final String fileMediaType = "application/octet-stream";
+ final String fileMediaType = MediaType.APPLICATION_OCTET_STREAM;
final String fileContent = "existed file";
createFile(folderPath, fileName, fileContent.getBytes());
ContainerResponse response = doUploadFile(folderId, fileName, fileMediaType, DEFAULT_CONTENT, "", "", false);
@@ -147,7 +152,7 @@ public void testUploadFileAlreadyExists() throws Exception {
public void testUploadFileAlreadyExistsAndProtected() throws Exception {
final String fileName = "existedProtectedFile";
- final String fileMediaType = "application/octet-stream";
+ final String fileMediaType = MediaType.APPLICATION_OCTET_STREAM;
final String fileContent = "existed protected file";
String path = createFile(folderPath, fileName, fileContent.getBytes());
Map> permissions = new HashMap<>(2);
@@ -165,7 +170,7 @@ public void testUploadFileAlreadyExistsAndProtected() throws Exception {
public void testUploadFileAlreadyExistsAndLocked() throws Exception {
final String fileName = "existedLockedFile";
- final String fileMediaType = "application/octet-stream";
+ final String fileMediaType = MediaType.APPLICATION_OCTET_STREAM;
final String fileContent = "existed locked file";
String path = createFile(folderPath, fileName, fileContent.getBytes());
createLock(path, "1234567890", Long.MAX_VALUE);
@@ -181,7 +186,7 @@ public void testUploadFileAlreadyExistsOverwrite() throws Exception {
final String fileContent = "existed file overwrite";
createFile(folderPath, fileName, fileContent.getBytes());
final String newFileContent = "test upload and overwrite existed file";
- final String fileMediaType = "text/plain";
+ final String fileMediaType = MediaType.TEXT_PLAIN;
ContainerResponse response = doUploadFile(folderId, fileName, fileMediaType, newFileContent, "", "", true);
assertEquals("Error: " + response.getEntity(), 200, response.getStatus());
assertTrue(((String)response.getEntity()).isEmpty()); // empty if successful
@@ -203,15 +208,15 @@ private ContainerResponse doUploadFile(String parentId,
boolean formOverwrite) throws Exception {
String requestPath = SERVICE_URI + "uploadfile/" + parentId;
Map> headers = new HashMap<>(1);
- headers.put("Content-Type", Arrays.asList("multipart/form-data; boundary=abcdef"));
+ headers.put(HttpHeaders.CONTENT_TYPE, Arrays.asList("multipart/form-data; boundary=abcdef"));
byte[] formData = String.format(uploadBodyPattern,
fileName, fileMediaType, fileContent, formMediaType, formFileName, formOverwrite)
.getBytes();
EnvironmentContext env = new EnvironmentContext();
env.put(HttpServletRequest.class, new MockHttpServletRequest("", new ByteArrayInputStream(formData),
- formData.length, "POST", headers));
+ formData.length, HttpMethod.POST, headers));
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
- ContainerResponse response = launcher.service("POST", requestPath, BASE_URI, headers, formData, writer, env);
+ ContainerResponse response = launcher.service(HttpMethod.POST, requestPath, BASE_URI, headers, formData, writer, env);
if (writer.getBody() != null) {
log.info(new String(writer.getBody()));
}
diff --git a/commons/che-core-commons-lang/pom.xml b/commons/che-core-commons-lang/pom.xml
index 4f19e6ffa..9f2787d7b 100644
--- a/commons/che-core-commons-lang/pom.xml
+++ b/commons/che-core-commons-lang/pom.xml
@@ -22,6 +22,11 @@
jar
Che Core :: Commons :: Java API extension classes
+
+ javax.ws.rs
+ javax.ws.rs-api
+ ${javax.ws.rs.version}
+
org.apache.commons
commons-compress
diff --git a/commons/che-core-commons-lang/src/main/java/org/eclipse/che/commons/lang/IoUtil.java b/commons/che-core-commons-lang/src/main/java/org/eclipse/che/commons/lang/IoUtil.java
index 9013b9f06..d6389190c 100644
--- a/commons/che-core-commons-lang/src/main/java/org/eclipse/che/commons/lang/IoUtil.java
+++ b/commons/che-core-commons-lang/src/main/java/org/eclipse/che/commons/lang/IoUtil.java
@@ -27,6 +27,8 @@
import java.util.LinkedList;
import java.util.List;
+import javax.ws.rs.HttpMethod;
+
import static java.nio.file.FileVisitResult.CONTINUE;
import static java.nio.file.FileVisitResult.TERMINATE;
@@ -243,7 +245,7 @@ public static File downloadFile(File parent, String prefix, String suffix, URL u
if ("http".equals(protocol) || "https".equals(protocol)) {
HttpURLConnection http = (HttpURLConnection)conn;
http.setInstanceFollowRedirects(false);
- http.setRequestMethod("GET");
+ http.setRequestMethod(HttpMethod.GET);
}
try (InputStream input = conn.getInputStream();
FileOutputStream fOutput = new FileOutputStream(file)) {
diff --git a/commons/che-core-commons-lang/src/main/java/org/eclipse/che/commons/lang/ws/rs/ExtMediaType.java b/commons/che-core-commons-lang/src/main/java/org/eclipse/che/commons/lang/ws/rs/ExtMediaType.java
new file mode 100644
index 000000000..2c847686e
--- /dev/null
+++ b/commons/che-core-commons-lang/src/main/java/org/eclipse/che/commons/lang/ws/rs/ExtMediaType.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2015 Codenvy, S.A.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Codenvy, S.A. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.che.commons.lang.ws.rs;
+
+import javax.ws.rs.core.MediaType;
+
+/**
+ * Extended media type.
+ *
+ * @author Tareq Sharafy (tareq.sharafy@sap.com)
+ */
+public interface ExtMediaType {
+ /**
+ * A {@code String} constant representing "{@value #APPLICATION_ZIP}" media type.
+ */
+ public final static String APPLICATION_ZIP = "application/zip";
+ /**
+ * A {@link MediaType} constant representing "{@value #APPLICATION_ZIP}" media type.
+ */
+ public final static MediaType APPLICATION_ZIP_TYPE = new MediaType("application", "zip");
+
+}
diff --git a/platform-api/che-core-api-account/src/test/java/org/eclipse/che/api/account/AccountServiceTest.java b/platform-api/che-core-api-account/src/test/java/org/eclipse/che/api/account/AccountServiceTest.java
index a26f85a0d..0706e54e8 100644
--- a/platform-api/che-core-api-account/src/test/java/org/eclipse/che/api/account/AccountServiceTest.java
+++ b/platform-api/che-core-api-account/src/test/java/org/eclipse/che/api/account/AccountServiceTest.java
@@ -50,9 +50,11 @@
import javax.annotation.security.RolesAllowed;
import javax.ws.rs.HttpMethod;
+import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
+
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
@@ -201,7 +203,7 @@ public void shouldBeAbleToCreateAccount() throws Exception {
public void shouldNotBeAbleToCreateAccountWithNotValidAttributes() throws Exception {
account.getAttributes().put("codenvy:god_mode", "true");
- ContainerResponse response = makeRequest("POST", SERVICE_PATH, MediaType.APPLICATION_JSON, account);
+ ContainerResponse response = makeRequest(HttpMethod.POST, SERVICE_PATH, MediaType.APPLICATION_JSON, account);
assertEquals(response.getEntity().toString(), "Attribute name 'codenvy:god_mode' is not valid");
}
@@ -440,9 +442,9 @@ public void shouldBeAbleToAddMember() throws Exception {
.withUserId(USER_ID)
.withRoles(singletonList("account/member"));
- final ContainerResponse response = makeRequest("POST",
+ final ContainerResponse response = makeRequest(HttpMethod.POST,
SERVICE_PATH + "/" + account.getId() + "/members",
- "application/json",
+ MediaType.APPLICATION_JSON,
newMembership);
assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
@@ -546,7 +548,7 @@ protected ContainerResponse makeRequest(String method, String path, String conte
Map> headers = null;
if (contentType != null) {
headers = new HashMap<>();
- headers.put("Content-Type", Arrays.asList(contentType));
+ headers.put(HttpHeaders.CONTENT_TYPE, Arrays.asList(contentType));
}
byte[] data = null;
if (toSend != null) {
diff --git a/platform-api/che-core-api-analytics/src/main/java/org/eclipse/che/api/analytics/impl/RemoteMetricHandler.java b/platform-api/che-core-api-analytics/src/main/java/org/eclipse/che/api/analytics/impl/RemoteMetricHandler.java
index 902718dc5..3653cb0dd 100644
--- a/platform-api/che-core-api-analytics/src/main/java/org/eclipse/che/api/analytics/impl/RemoteMetricHandler.java
+++ b/platform-api/che-core-api-analytics/src/main/java/org/eclipse/che/api/analytics/impl/RemoteMetricHandler.java
@@ -26,10 +26,12 @@
import org.eclipse.che.dto.server.JsonArrayImpl;
import org.eclipse.che.dto.server.JsonStringMapImpl;
+import javax.ws.rs.HttpMethod;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -68,7 +70,7 @@ public MetricValueDTO getValue(String metricName,
List> pairs = mapToParisList(executionContext);
return request(MetricValueDTO.class,
proxyUrl,
- "GET",
+ HttpMethod.GET,
null,
pairs.toArray(new Pair[pairs.size()]));
} catch (Exception e) {
@@ -90,7 +92,7 @@ public MetricValueListDTO getListValues(String metricName,
List> pairs = mapToParisList(executionContext);
return request(MetricValueListDTO.class,
proxyUrl,
- "POST",
+ HttpMethod.POST,
new JsonArrayImpl<>(parameters),
pairs.toArray(new Pair[pairs.size()]));
} catch (Exception e) {
@@ -108,7 +110,7 @@ public MetricValueDTO getValueByJson(String metricName,
List> pairs = mapToParisList(executionContext);
return request(MetricValueDTO.class,
proxyUrl,
- "POST",
+ HttpMethod.POST,
parameters,
pairs.toArray(new Pair[pairs.size()]));
} catch (Exception e) {
@@ -126,7 +128,7 @@ public MetricValueDTO getPublicValue(String metricName,
List> pairs = mapToParisList(executionContext);
return request(MetricValueDTO.class,
proxyUrl,
- "GET",
+ HttpMethod.GET,
null,
pairs.toArray(new Pair[pairs.size()]));
} catch (Exception e) {
@@ -144,7 +146,7 @@ public MetricValueListDTO getUserValues(List metricNames,
List> pairs = mapToParisList(executionContext);
return request(MetricValueListDTO.class,
proxyUrl,
- "POST",
+ HttpMethod.POST,
metricNames,
pairs.toArray(new Pair[pairs.size()]));
} catch (Exception e) {
@@ -160,7 +162,7 @@ public MetricInfoDTO getInfo(String metricName, UriInfo uriInfo) {
List> pairs = mapToParisList(Collections.emptyMap());
MetricInfoDTO metricInfoDTO = request(MetricInfoDTO.class,
proxyUrl,
- "GET",
+ HttpMethod.GET,
null,
pairs.toArray(new Pair[pairs.size()]));
updateLinks(uriInfo, metricInfoDTO);
@@ -178,7 +180,7 @@ public MetricInfoListDTO getAllInfo(UriInfo uriInfo) {
@SuppressWarnings("unchecked")
MetricInfoListDTO metricInfoListDTO = request(MetricInfoListDTO.class,
proxyUrl,
- "GET",
+ HttpMethod.GET,
null,
pairs.toArray(new Pair[pairs.size()]));
updateLinks(uriInfo, metricInfoListDTO);
@@ -255,7 +257,7 @@ private DTO request(Class dtoInterface,
try {
conn.setRequestMethod(method);
if (body != null) {
- conn.addRequestProperty("content-type", "application/json");
+ conn.addRequestProperty("content-type", MediaType.APPLICATION_JSON);
conn.setDoOutput(true);
try (OutputStream output = conn.getOutputStream()) {
output.write(DtoFactory.getInstance().toJson(body).getBytes());
@@ -272,7 +274,7 @@ private DTO request(Class dtoInterface,
throw new IOException(IoUtil.readAndCloseQuietly(in));
}
final String contentType = conn.getContentType();
- if (!contentType.startsWith("application/json")) {
+ if (!contentType.startsWith(MediaType.APPLICATION_JSON)) {
throw new IOException("Unsupported type of response from remote server. ");
}
try (InputStream input = conn.getInputStream()) {
@@ -295,7 +297,7 @@ private static List getLinks(String metricName, UriInfo uriInfo) {
.path(getMethod("getValue"))
.build(metricName, "name")
.toString());
- statusLink.setMethod("GET");
+ statusLink.setMethod(HttpMethod.GET);
statusLink.setProduces(MediaType.APPLICATION_JSON);
links.add(statusLink);
return links;
diff --git a/platform-api/che-core-api-auth/src/main/java/org/eclipse/che/security/oauth1/OAuthAuthenticator.java b/platform-api/che-core-api-auth/src/main/java/org/eclipse/che/security/oauth1/OAuthAuthenticator.java
index c49eb8c7d..c25b8646f 100644
--- a/platform-api/che-core-api-auth/src/main/java/org/eclipse/che/security/oauth1/OAuthAuthenticator.java
+++ b/platform-api/che-core-api-auth/src/main/java/org/eclipse/che/security/oauth1/OAuthAuthenticator.java
@@ -25,6 +25,10 @@
import org.eclipse.che.security.oauth1.shared.User;
import javax.annotation.Nonnull;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
@@ -49,10 +53,10 @@ public abstract class OAuthAuthenticator {
private static final String OAUTH_TOKEN_PARAM_KEY = "oauth_token";
private static final String OAUTH_VERIFIER_PARAM_KEY = "oauth_verifier";
- private static final String GET = "GET";
+ private static final String GET = HttpMethod.GET;
private static final String AUTHORIZATION = "Authorization";
- private static final String ACCEPT = "Accept";
- private static final String APPLICATION_JSON = "application/json";
+ private static final String ACCEPT = HttpHeaders.ACCEPT;
+ private static final String APPLICATION_JSON = MediaType.APPLICATION_JSON;
private final String clientId;
private final String clientSecret;
diff --git a/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/BuildQueueTask.java b/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/BuildQueueTask.java
index 9b95659cb..607f4374f 100644
--- a/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/BuildQueueTask.java
+++ b/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/BuildQueueTask.java
@@ -23,8 +23,10 @@
import org.eclipse.che.api.core.util.Cancellable;
import org.eclipse.che.dto.server.DtoFactory;
+import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
@@ -151,12 +153,12 @@ public BuildTaskDescriptor getDescriptor() throws BuilderException, NotFoundExce
.withRel(Constants.LINK_REL_GET_STATUS)
.withHref(getUriBuilder().path(BuilderService.class, "getStatus").build(request.getWorkspace(), id)
.toString())
- .withMethod("GET")
+ .withMethod(HttpMethod.GET)
.withProduces(MediaType.APPLICATION_JSON));
links.add(dtoFactory.createDto(Link.class)
.withRel(Constants.LINK_REL_CANCEL)
.withHref(getUriBuilder().path(BuilderService.class, "cancel").build(request.getWorkspace(), id).toString())
- .withMethod("POST")
+ .withMethod(HttpMethod.POST)
.withProduces(MediaType.APPLICATION_JSON));
final List buildStats = new ArrayList<>(1);
buildStats.add(dtoFactory.createDto(BuilderMetric.class)
diff --git a/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/BuilderService.java b/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/BuilderService.java
index 2c7694527..ca58aced9 100644
--- a/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/BuilderService.java
+++ b/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/BuilderService.java
@@ -333,7 +333,7 @@ public void downloadResultArchive(@ApiParam(value = "Workspace ID", required = t
@PathParam("ws-id") String workspace,
@ApiParam(value = "Build ID", required = true)
@PathParam("id") Long id,
- @ApiParam(value = "Archive type", defaultValue = "tar", allowableValues = "tar,zip")
+ @ApiParam(value = "Archive type", defaultValue = Constants.RESULT_ARCHIVE_TAR, allowableValues = "tar,zip")
@Required @QueryParam("arch") String arch,
@Context HttpServletResponse httpServletResponse) throws Exception {
// Response write directly to the servlet request stream
diff --git a/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/RemoteTask.java b/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/RemoteTask.java
index 54cf5ddd6..ec10ef7be 100644
--- a/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/RemoteTask.java
+++ b/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/RemoteTask.java
@@ -21,6 +21,7 @@
import org.eclipse.che.api.core.rest.HttpOutputMessage;
import org.eclipse.che.api.core.rest.shared.dto.Link;
import org.eclipse.che.dto.server.DtoFactory;
+
import com.google.common.io.ByteStreams;
import com.google.common.io.Closer;
@@ -32,6 +33,9 @@
import java.net.HttpURLConnection;
import java.net.URL;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.core.HttpHeaders;
+
/**
* Representation of remote builder's task.
*
@@ -213,9 +217,9 @@ public void listDirectory(String path, HttpOutputMessage output) throws IOExcept
public void downloadResultArchive(String archType, HttpOutputMessage output) throws IOException, BuilderException, NotFoundException {
final BuildTaskDescriptor descriptor = getBuildTaskDescriptor();
Link link = null;
- if (archType.equals("zip")) {
+ if (archType.equals(Constants.RESULT_ARCHIVE_ZIP)) {
link = descriptor.getLink(Constants.LINK_REL_DOWNLOAD_RESULTS_ZIPBALL);
- } else if (archType.equals("tar")) {
+ } else if (archType.equals(Constants.RESULT_ARCHIVE_TAR)) {
link = descriptor.getLink(Constants.LINK_REL_DOWNLOAD_RESULTS_TARBALL);
}
if (link == null) {
@@ -228,7 +232,7 @@ private void readFromUrl(String url, final HttpOutputMessage output) throws IOEx
final HttpURLConnection conn = (HttpURLConnection)new URL(url).openConnection();
conn.setConnectTimeout(60 * 1000);
conn.setReadTimeout(60 * 1000);
- conn.setRequestMethod("GET");
+ conn.setRequestMethod(HttpMethod.GET);
try {
output.setStatus(conn.getResponseCode());
final String contentType = conn.getContentType();
@@ -236,9 +240,9 @@ private void readFromUrl(String url, final HttpOutputMessage output) throws IOEx
output.setContentType(contentType);
}
// for download files
- final String contentDisposition = conn.getHeaderField("Content-Disposition");
+ final String contentDisposition = conn.getHeaderField(HttpHeaders.CONTENT_DISPOSITION);
if (contentDisposition != null) {
- output.addHttpHeader("Content-Disposition", contentDisposition);
+ output.addHttpHeader(HttpHeaders.CONTENT_DISPOSITION, contentDisposition);
}
diff --git a/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/internal/Builder.java b/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/internal/Builder.java
index e521e2b13..6b35b5f83 100644
--- a/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/internal/Builder.java
+++ b/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/internal/Builder.java
@@ -29,6 +29,7 @@
import org.eclipse.che.api.core.util.Watchdog;
import org.eclipse.che.commons.lang.IoUtil;
import org.eclipse.che.dto.server.DtoFactory;
+
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.slf4j.Logger;
@@ -36,6 +37,8 @@
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
+import javax.ws.rs.core.MediaType;
+
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
@@ -413,7 +416,7 @@ public void done(BuildTask task) {
protected BuildLogger createBuildLogger(BuilderConfiguration buildConfiguration, java.io.File logFile) throws BuilderException {
try {
- return new DefaultBuildLogger(logFile, "text/plain");
+ return new DefaultBuildLogger(logFile, MediaType.TEXT_PLAIN);
} catch (IOException e) {
throw new BuilderException(e);
}
diff --git a/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/internal/Constants.java b/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/internal/Constants.java
index 386dd6c97..b2d1d60b9 100644
--- a/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/internal/Constants.java
+++ b/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/internal/Constants.java
@@ -65,6 +65,11 @@ public class Constants {
*/
public static final String MAX_EXECUTION_TIME = "builder.max_execution_time";
+ /** Build results archive type: .zip */
+ public static final String RESULT_ARCHIVE_ZIP = "zip";
+ /** Build results archive type: .tar */
+ public static final String RESULT_ARCHIVE_TAR = "tar";
+
/* ================================================= */
/** @deprecated use {@link #BASE_DIRECTORY} */
diff --git a/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/internal/SlaveBuilderService.java b/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/internal/SlaveBuilderService.java
index 9c7013e96..87be1f02c 100644
--- a/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/internal/SlaveBuilderService.java
+++ b/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/internal/SlaveBuilderService.java
@@ -38,16 +38,19 @@
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
+import javax.ws.rs.HttpMethod;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
import javax.ws.rs.core.UriBuilder;
+
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
@@ -287,7 +290,7 @@ public List listDirectory(@PathParam("builder") String builder,
.replaceQueryParam("path", workDirPath.relativize(parentPath))
.build(task.getBuilder(), task.getId()).toString();
final ItemReference up = dtoFactory.createDto(ItemReference.class).withName("..").withPath("..").withType("folder");
- up.getLinks().add(dtoFactory.createDto(Link.class).withRel("children").withHref(upHref).withMethod("GET")
+ up.getLinks().add(dtoFactory.createDto(Link.class).withRel("children").withHref(upHref).withMethod(HttpMethod.GET)
.withProduces(MediaType.APPLICATION_JSON));
result.add(up);
}
@@ -309,9 +312,9 @@ public List listDirectory(@PathParam("builder") String builder,
.withType("file");
final List links = fileItem.getLinks();
final String contentType = ContentTypeGuesser.guessContentType(file);
- links.add(dtoFactory.createDto(Link.class).withRel("view").withHref(openHref).withMethod("GET")
+ links.add(dtoFactory.createDto(Link.class).withRel("view").withHref(openHref).withMethod(HttpMethod.GET)
.withProduces(contentType));
- links.add(dtoFactory.createDto(Link.class).withRel("download").withHref(downloadHref).withMethod("GET")
+ links.add(dtoFactory.createDto(Link.class).withRel("download").withHref(downloadHref).withMethod(HttpMethod.GET)
.withProduces(contentType));
fileItem.getAttributes().put("size", Size.toHumanSize(file.length()));
result.add(fileItem);
@@ -336,7 +339,7 @@ public List listDirectory(@PathParam("builder") String builder,
.replaceQueryParam("path", filePath)
.build(task.getBuilder(), task.getId()).toString();
final List links = folderItem.getLinks();
- links.add(dtoFactory.createDto(Link.class).withRel("children").withHref(childrenHref).withMethod("GET")
+ links.add(dtoFactory.createDto(Link.class).withRel("children").withHref(childrenHref).withMethod(HttpMethod.GET)
.withProduces(MediaType.APPLICATION_JSON));
}
@@ -361,7 +364,7 @@ public Response downloadFile(@PathParam("builder") String builder,
}
if (target.isFile()) {
return Response.status(200)
- .header("Content-Disposition", String.format("attachment; filename=\"%s\"", target.getName()))
+ .header(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=\"%s\"", target.getName()))
.type(ContentTypeGuesser.guessContentType(target))
.entity(target)
.build();
@@ -373,23 +376,23 @@ public Response downloadFile(@PathParam("builder") String builder,
@Path("download-all/{builder}/{id}")
public Response downloadResultArchive(@PathParam("builder") String builder,
@PathParam("id") Long id,
- @DefaultValue("tar") @QueryParam("arch") String arch) throws Exception {
+ @DefaultValue(Constants.RESULT_ARCHIVE_TAR) @QueryParam("arch") String arch) throws Exception {
final List results = getBuilder(builder).getBuildTask(id).getResult().getResults();
if (results.isEmpty()) {
throw new NotFoundException("Archive with build result is not available.");
}
File archFile;
- if ("tar".equals(arch)) {
+ if (Constants.RESULT_ARCHIVE_TAR.equals(arch)) {
archFile = Files.createTempFile(String.format("%s-%d-", builder, id), ".tar").toFile();
TarUtils.tarFiles(archFile, 0, results.toArray(new File[results.size()]));
- } else if ("zip".equals(arch)) {
+ } else if (Constants.RESULT_ARCHIVE_ZIP.equals(arch)) {
archFile = Files.createTempFile(String.format("%s-%d-", builder, id), ".zip").toFile();
ZipUtils.zipFiles(archFile, results.toArray(new File[results.size()]));
} else {
throw new ConflictException(String.format("Unsupported archive type: %s", arch));
}
return Response.status(200)
- .header("Content-Disposition", String.format("attachment; filename=\"%s\"", archFile.getName()))
+ .header(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=\"%s\"", archFile.getName()))
.type(ContentTypeGuesser.guessContentType(archFile))
.entity(new DeleteOnCloseFileInputStream(archFile))
.build();
@@ -433,14 +436,14 @@ private BuildTaskDescriptor getDescriptor(BuildTask task, UriBuilder uriBuilder)
links.add(dtoFactory.createDto(Link.class)
.withRel(Constants.LINK_REL_GET_STATUS)
.withHref(uriBuilder.clone().path(SlaveBuilderService.class, "getStatus").build(builder, taskId).toString())
- .withMethod("GET")
+ .withMethod(HttpMethod.GET)
.withProduces(MediaType.APPLICATION_JSON));
if (status == BuildStatus.IN_QUEUE || status == BuildStatus.IN_PROGRESS) {
links.add(dtoFactory.createDto(Link.class)
.withRel(Constants.LINK_REL_CANCEL)
.withHref(uriBuilder.clone().path(SlaveBuilderService.class, "cancel").build(builder, taskId).toString())
- .withMethod("POST")
+ .withMethod(HttpMethod.POST)
.withProduces(MediaType.APPLICATION_JSON));
}
@@ -448,13 +451,13 @@ private BuildTaskDescriptor getDescriptor(BuildTask task, UriBuilder uriBuilder)
links.add(dtoFactory.createDto(Link.class)
.withRel(Constants.LINK_REL_VIEW_LOG)
.withHref(uriBuilder.clone().path(SlaveBuilderService.class, "getLogs").build(builder, taskId).toString())
- .withMethod("GET")
+ .withMethod(HttpMethod.GET)
.withProduces(task.getBuildLogger().getContentType()));
links.add(dtoFactory.createDto(Link.class)
.withRel(Constants.LINK_REL_BROWSE)
.withHref(uriBuilder.clone().path(SlaveBuilderService.class, "browseDirectory").queryParam("path", "/")
.build(builder, taskId).toString())
- .withMethod("GET")
+ .withMethod(HttpMethod.GET)
.withProduces(MediaType.TEXT_HTML));
}
@@ -470,7 +473,7 @@ private BuildTaskDescriptor getDescriptor(BuildTask task, UriBuilder uriBuilder)
.withRel(Constants.LINK_REL_DOWNLOAD_RESULT)
.withHref(uriBuilder.clone().path(SlaveBuilderService.class, "downloadFile")
.queryParam("path", relativePath).build(builder, taskId).toString())
- .withMethod("GET")
+ .withMethod(HttpMethod.GET)
.withProduces(ContentTypeGuesser.guessContentType(ru)));
}
}
@@ -478,15 +481,15 @@ private BuildTaskDescriptor getDescriptor(BuildTask task, UriBuilder uriBuilder)
links.add(dtoFactory.createDto(Link.class)
.withRel(Constants.LINK_REL_DOWNLOAD_RESULTS_TARBALL)
.withHref(uriBuilder.clone().path(SlaveBuilderService.class, "downloadResultArchive")
- .queryParam("arch", "tar")
+ .queryParam("arch", Constants.RESULT_ARCHIVE_TAR)
.build(builder, taskId).toString())
- .withMethod("GET"));
+ .withMethod(HttpMethod.GET));
links.add(dtoFactory.createDto(Link.class)
.withRel(Constants.LINK_REL_DOWNLOAD_RESULTS_ZIPBALL)
.withHref(uriBuilder.clone().path(SlaveBuilderService.class, "downloadResultArchive")
- .queryParam("arch", "zip")
+ .queryParam("arch", Constants.RESULT_ARCHIVE_ZIP)
.build(builder, taskId).toString())
- .withMethod("GET"));
+ .withMethod(HttpMethod.GET));
}
}
@@ -504,7 +507,7 @@ private BuildTaskDescriptor getDescriptor(BuildTask task, UriBuilder uriBuilder)
.withHref(uriBuilder.clone().path(SlaveBuilderService.class, "browseDirectory")
.queryParam("path", relativePath)
.build(builder, taskId).toString())
- .withMethod("GET")
+ .withMethod(HttpMethod.GET)
.withProduces(MediaType.TEXT_HTML));
} else {
links.add(dtoFactory.createDto(Link.class)
@@ -512,7 +515,7 @@ private BuildTaskDescriptor getDescriptor(BuildTask task, UriBuilder uriBuilder)
.withHref(uriBuilder.clone().path(SlaveBuilderService.class, "viewFile")
.queryParam("path", relativePath)
.build(builder, taskId).toString())
- .withMethod("GET")
+ .withMethod(HttpMethod.GET)
.withProduces(ContentTypeGuesser.guessContentType(br)));
}
}
diff --git a/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/internal/SourcesManagerImpl.java b/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/internal/SourcesManagerImpl.java
index 792f06017..b33d46886 100644
--- a/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/internal/SourcesManagerImpl.java
+++ b/platform-api/che-core-api-builder/src/main/java/org/eclipse/che/api/builder/internal/SourcesManagerImpl.java
@@ -17,6 +17,7 @@
import org.eclipse.che.commons.lang.IoUtil;
import org.eclipse.che.commons.lang.Pair;
import org.eclipse.che.commons.lang.ZipUtils;
+
import com.google.common.hash.Hashing;
import com.google.common.io.CharStreams;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
@@ -54,6 +55,10 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+
/**
* Implementation of SourcesManager that stores sources locally and gets only updated files over virtual file system RESt API.
*
@@ -215,9 +220,9 @@ private void download(String downloadUrl, java.io.File downloadTo) throws IOExce
conn.setConnectTimeout(CONNECT_TIMEOUT);
conn.setReadTimeout(READ_TIMEOUT);
if (!md5sums.isEmpty()) {
- conn.setRequestMethod("POST");
- conn.setRequestProperty("Content-type", "text/plain");
- conn.setRequestProperty("Accept", "multipart/form-data");
+ conn.setRequestMethod(HttpMethod.POST);
+ conn.setRequestProperty("Content-type", MediaType.TEXT_PLAIN);
+ conn.setRequestProperty(HttpHeaders.ACCEPT, MediaType.MULTIPART_FORM_DATA);
conn.setDoOutput(true);
try (OutputStream output = conn.getOutputStream();
Writer writer = new OutputStreamWriter(output)) {
@@ -232,7 +237,7 @@ private void download(String downloadUrl, java.io.File downloadTo) throws IOExce
final int responseCode = conn.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
final String contentType = conn.getHeaderField("content-type");
- if (contentType.startsWith("multipart/form-data")) {
+ if (contentType.startsWith(MediaType.MULTIPART_FORM_DATA)) {
final HeaderParameterParser headerParameterParser = new HeaderParameterParser();
final String boundary = headerParameterParser.parse(contentType).get("boundary");
try (InputStream in = conn.getInputStream()) {
diff --git a/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/notification/Messages.java b/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/notification/Messages.java
index df363b40e..0573f9477 100644
--- a/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/notification/Messages.java
+++ b/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/notification/Messages.java
@@ -11,7 +11,6 @@
package org.eclipse.che.api.core.notification;
import org.eclipse.che.commons.lang.NameGenerator;
-
import org.everrest.core.impl.provider.json.JsonGenerator;
import org.everrest.core.impl.provider.json.JsonParser;
import org.everrest.core.impl.provider.json.JsonValue;
@@ -27,6 +26,9 @@
import java.io.StringWriter;
import java.io.Writer;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.core.MediaType;
+
/**
* @author andrew00x
*/
@@ -34,9 +36,9 @@ class Messages {
static InputMessage clientMessage(Object event) throws Exception {
RESTfulInputMessage message = new RESTfulInputMessage();
message.setBody(toJson(event));
- message.setMethod("POST");
+ message.setMethod(HttpMethod.POST);
message.setHeaders(new org.everrest.websockets.message.Pair[]{
- new org.everrest.websockets.message.Pair("Content-type", "application/json")});
+ new org.everrest.websockets.message.Pair("Content-type", MediaType.APPLICATION_JSON)});
message.setUuid(NameGenerator.generate(null, 8));
message.setPath("/event-bus");
return message;
diff --git a/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/HttpJsonHelper.java b/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/HttpJsonHelper.java
index 759b9e1e9..934173cc3 100644
--- a/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/HttpJsonHelper.java
+++ b/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/HttpJsonHelper.java
@@ -21,10 +21,14 @@
import org.eclipse.che.commons.lang.Pair;
import org.eclipse.che.commons.user.User;
import org.eclipse.che.dto.server.DtoFactory;
+
import com.google.common.io.CharStreams;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -206,12 +210,12 @@ public static List requestArray(Class dtoInterface,
*/
public static DTO get(Class dtoInterface, String url, Pair... parameters)
throws IOException, ServerException, NotFoundException, ForbiddenException, UnauthorizedException, ConflictException {
- return request(dtoInterface, url, "GET", null, parameters);
+ return request(dtoInterface, url, HttpMethod.GET, null, parameters);
}
public static DTO get(Class dtoInterface, int timeout, String url, Pair... parameters)
throws IOException, ServerException, NotFoundException, ForbiddenException, UnauthorizedException, ConflictException {
- return request(dtoInterface, timeout, url, "GET", null, parameters);
+ return request(dtoInterface, timeout, url, HttpMethod.GET, null, parameters);
}
/**
@@ -235,12 +239,12 @@ public static DTO get(Class dtoInterface, int timeout, String url, Pa
*/
public static DTO post(Class dtoInterface, String url, Object body, Pair... parameters)
throws IOException, ServerException, NotFoundException, ForbiddenException, UnauthorizedException, ConflictException {
- return request(dtoInterface, url, "POST", body, parameters);
+ return request(dtoInterface, url, HttpMethod.POST, body, parameters);
}
public static DTO post(Class dtoInterface, int timeout, String url, Object body, Pair... parameters)
throws IOException, ServerException, NotFoundException, ForbiddenException, UnauthorizedException, ConflictException {
- return request(dtoInterface, timeout, url, "POST", body, parameters);
+ return request(dtoInterface, timeout, url, HttpMethod.POST, body, parameters);
}
/**
@@ -264,12 +268,12 @@ public static DTO post(Class dtoInterface, int timeout, String url, O
*/
public static DTO put(Class dtoInterface, String url, Object body, Pair... parameters)
throws IOException, ServerException, NotFoundException, ForbiddenException, UnauthorizedException, ConflictException {
- return request(dtoInterface, url, "PUT", body, parameters);
+ return request(dtoInterface, url, HttpMethod.PUT, body, parameters);
}
public static DTO put(Class dtoInterface, int timeout, String url, Object body, Pair... parameters)
throws IOException, ServerException, NotFoundException, ForbiddenException, UnauthorizedException, ConflictException {
- return request(dtoInterface, timeout, url, "PUT", body, parameters);
+ return request(dtoInterface, timeout, url, HttpMethod.PUT, body, parameters);
}
/**
@@ -291,12 +295,12 @@ public static DTO put(Class dtoInterface, int timeout, String url, Ob
*/
public static DTO options(Class dtoInterface, String url, Pair... parameters)
throws IOException, ServerException, NotFoundException, ForbiddenException, UnauthorizedException, ConflictException {
- return request(dtoInterface, url, "OPTIONS", null, parameters);
+ return request(dtoInterface, url, HttpMethod.OPTIONS, null, parameters);
}
public static DTO options(Class dtoInterface, int timeout, String url, Pair... parameters)
throws IOException, ServerException, NotFoundException, ForbiddenException, UnauthorizedException, ConflictException {
- return request(dtoInterface, timeout, url, "OPTIONS", null, parameters);
+ return request(dtoInterface, timeout, url, HttpMethod.OPTIONS, null, parameters);
}
/**
@@ -318,12 +322,12 @@ public static DTO options(Class dtoInterface, int timeout, String url
*/
public static DTO delete(Class dtoInterface, String url, Pair... parameters)
throws IOException, ServerException, NotFoundException, ForbiddenException, UnauthorizedException, ConflictException {
- return request(dtoInterface, url, "DELETE", null, parameters);
+ return request(dtoInterface, url, HttpMethod.DELETE, null, parameters);
}
public static DTO delete(Class dtoInterface, int timeout, String url, Pair... parameters)
throws IOException, ServerException, NotFoundException, ForbiddenException, UnauthorizedException, ConflictException {
- return request(dtoInterface, timeout, url, "DELETE", null, parameters);
+ return request(dtoInterface, timeout, url, HttpMethod.DELETE, null, parameters);
}
private HttpJsonHelper() {
@@ -424,12 +428,12 @@ public String requestString(int timeout,
try {
conn.setRequestMethod(method);
if (body != null) {
- conn.addRequestProperty("content-type", "application/json");
+ conn.addRequestProperty("content-type", MediaType.APPLICATION_JSON);
conn.setDoOutput(true);
- if ("DELETE".equals(method)) { //to avoid jdk bug described here http://bugs.java.com/view_bug.do?bug_id=7157360
- conn.setRequestMethod("POST");
- conn.setRequestProperty("X-HTTP-Method-Override", "DELETE");
+ if (HttpMethod.DELETE.equals(method)) { //to avoid jdk bug described here http://bugs.java.com/view_bug.do?bug_id=7157360
+ conn.setRequestMethod(HttpMethod.POST);
+ conn.setRequestProperty("X-HTTP-Method-Override", HttpMethod.DELETE);
}
try (OutputStream output = conn.getOutputStream()) {
@@ -446,7 +450,7 @@ public String requestString(int timeout,
final InputStream fIn = in;
final String str = CharStreams.toString(new InputStreamReader(fIn));
final String contentType = conn.getContentType();
- if (contentType != null && contentType.startsWith("application/json")) {
+ if (contentType != null && contentType.startsWith(MediaType.APPLICATION_JSON)) {
final ServiceError serviceError = DtoFactory.getInstance().createDtoFromJson(str, ServiceError.class);
if (serviceError.getMessage() != null) {
if (responseCode == Response.Status.FORBIDDEN.getStatusCode()) {
@@ -468,7 +472,7 @@ public String requestString(int timeout,
UriBuilder.fromUri(url).replaceQuery("token").build(), method, responseCode, str));
}
final String contentType = conn.getContentType();
- if (!(contentType == null || contentType.startsWith("application/json"))) {
+ if (!(contentType == null || contentType.startsWith(MediaType.APPLICATION_JSON))) {
throw new IOException("We received an error response from the Codenvy server." +
" Retry the request. If this issue continues, contact. support.");
}
diff --git a/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/HttpServletProxyResponse.java b/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/HttpServletProxyResponse.java
index 4f436079c..4c0d6af06 100644
--- a/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/HttpServletProxyResponse.java
+++ b/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/HttpServletProxyResponse.java
@@ -13,6 +13,8 @@
import org.eclipse.che.commons.lang.Pair;
import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.core.HttpHeaders;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -45,7 +47,7 @@ public void setStatus(int status) {
@Override
public void setContentType(String contentType) {
- setHttpHeader("Content-Type", contentType);
+ setHttpHeader(HttpHeaders.CONTENT_TYPE, contentType);
}
@Override
diff --git a/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/RemoteServiceDescriptor.java b/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/RemoteServiceDescriptor.java
index 42dd1152b..7aaadd689 100644
--- a/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/RemoteServiceDescriptor.java
+++ b/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/RemoteServiceDescriptor.java
@@ -26,6 +26,8 @@
import java.util.ArrayList;
import java.util.List;
+import javax.ws.rs.HttpMethod;
+
/**
* Provides basic functionality to access remote {@link Service Service}. Basically provides next information about {@code Service}:
*
@@ -114,7 +116,7 @@ public boolean isAvailable() {
conn = (HttpURLConnection)baseUrlURL.openConnection();
conn.setConnectTimeout(3 * 1000);
conn.setReadTimeout(3 * 1000);
- conn.setRequestMethod("OPTIONS");
+ conn.setRequestMethod(HttpMethod.OPTIONS);
return 200 == conn.getResponseCode();
} catch (IOException e) {
return false;
diff --git a/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/annotations/OPTIONS.java b/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/annotations/OPTIONS.java
index 685bf5dd4..8dbe207f6 100644
--- a/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/annotations/OPTIONS.java
+++ b/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/annotations/OPTIONS.java
@@ -21,6 +21,6 @@
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
-@HttpMethod("OPTIONS")
+@HttpMethod(HttpMethod.OPTIONS)
public @interface OPTIONS {
}
diff --git a/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/annotations/Valid.java b/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/annotations/Valid.java
index e1264dd19..2833694c6 100644
--- a/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/annotations/Valid.java
+++ b/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/rest/annotations/Valid.java
@@ -49,7 +49,7 @@
* "href":"${base_uri}/echo/say",
* "produces":"plain/text",
* "rel":"message",
- * "method":"GET",
+ * "method":HttpMethod.GET,
* "parameters":[
* {
* "name":"message",
diff --git a/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/util/ContentTypeGuesser.java b/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/util/ContentTypeGuesser.java
index c9cdfa4ca..f32f4ccb3 100644
--- a/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/util/ContentTypeGuesser.java
+++ b/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/util/ContentTypeGuesser.java
@@ -18,6 +18,8 @@
import java.net.URL;
import java.util.Properties;
+import javax.ws.rs.core.MediaType;
+
/**
* Helps getting content type of file.
*
@@ -26,7 +28,7 @@
public class ContentTypeGuesser {
private static final Logger LOG = LoggerFactory.getLogger(ContentTypeGuesser.class);
- private static String defaultContentType = "application/octet-stream";
+ private static String defaultContentType = MediaType.APPLICATION_OCTET_STREAM;
public synchronized static void setDefaultContentType(String myDefaultContentType) {
defaultContentType = myDefaultContentType;
diff --git a/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/util/HttpDownloadPlugin.java b/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/util/HttpDownloadPlugin.java
index 9e44a37f7..d659771d1 100644
--- a/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/util/HttpDownloadPlugin.java
+++ b/platform-api/che-core-api-core/src/main/java/org/eclipse/che/api/core/util/HttpDownloadPlugin.java
@@ -11,7 +11,6 @@
package org.eclipse.che.api.core.util;
import org.eclipse.che.commons.lang.NameGenerator;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -23,6 +22,8 @@
import java.nio.file.StandardCopyOption;
import java.util.concurrent.TimeUnit;
+import javax.ws.rs.core.HttpHeaders;
+
/**
* DownloadPlugin that downloads single file.
*
@@ -45,7 +46,7 @@ public void download(String downloadUrl, java.io.File downloadTo, Callback callb
if (responseCode != 200) {
throw new IOException(String.format("Invalid response status %d from remote server. ", responseCode));
}
- final String contentDisposition = conn.getHeaderField("Content-Disposition");
+ final String contentDisposition = conn.getHeaderField(HttpHeaders.CONTENT_DISPOSITION);
String fileName = null;
if (contentDisposition != null) {
int fNameStart = contentDisposition.indexOf("filename=");
diff --git a/platform-api/che-core-api-core/src/main/java/org/eclipse/che/everrest/ETagResponseFilter.java b/platform-api/che-core-api-core/src/main/java/org/eclipse/che/everrest/ETagResponseFilter.java
index 2d87ec007..0cc2c433e 100644
--- a/platform-api/che-core-api-core/src/main/java/org/eclipse/che/everrest/ETagResponseFilter.java
+++ b/platform-api/che-core-api-core/src/main/java/org/eclipse/che/everrest/ETagResponseFilter.java
@@ -23,10 +23,12 @@
import org.everrest.core.ResponseFilter;
import org.everrest.core.impl.ApplicationContextImpl;
+import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
+
import java.nio.charset.Charset;
import java.util.List;
@@ -76,7 +78,7 @@ public void doFilter(GenericContainerResponse containerResponse) {
Request request = applicationContext.getRequest();
// manage only GET requests
- if (!"GET".equals(request.getMethod())) {
+ if (!HttpMethod.GET.equals(request.getMethod())) {
return;
}
diff --git a/platform-api/che-core-api-core/src/test/java/org/eclipse/che/api/core/rest/ServiceDescriptorTest.java b/platform-api/che-core-api-core/src/test/java/org/eclipse/che/api/core/rest/ServiceDescriptorTest.java
index 7cd62e6e0..a043ba0f5 100644
--- a/platform-api/che-core-api-core/src/test/java/org/eclipse/che/api/core/rest/ServiceDescriptorTest.java
+++ b/platform-api/che-core-api-core/src/test/java/org/eclipse/che/api/core/rest/ServiceDescriptorTest.java
@@ -18,7 +18,6 @@
import org.eclipse.che.api.core.rest.shared.dto.Link;
import org.eclipse.che.api.core.rest.shared.dto.LinkParameter;
import org.eclipse.che.api.core.rest.shared.dto.ServiceDescriptor;
-
import org.everrest.core.ResourceBinder;
import org.everrest.core.impl.ApplicationContextImpl;
import org.everrest.core.impl.ApplicationProviderBinder;
@@ -35,10 +34,13 @@
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
+import javax.ws.rs.HttpMethod;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -55,7 +57,7 @@ public static class EchoService extends Service {
@GET
@Path("my_method")
@GenerateLink(rel = "echo")
- @Produces("text/plain")
+ @Produces(MediaType.TEXT_PLAIN)
public String echo(@Description("some text") @Required @Valid({"a", "b"}) @DefaultValue("a") @QueryParam("text") String test) {
return test;
}
@@ -114,9 +116,9 @@ public void testLinkAvailable() throws Exception {
@Test
public void testLinkInfo() throws Exception {
Link link = getLink("echo");
- Assert.assertEquals(link.getMethod(), "GET");
+ Assert.assertEquals(link.getMethod(), HttpMethod.GET);
Assert.assertEquals(link.getHref(), SERVICE_URI + "/my_method");
- Assert.assertEquals(link.getProduces(), "text/plain");
+ Assert.assertEquals(link.getProduces(), MediaType.TEXT_PLAIN);
}
@Test
@@ -148,7 +150,7 @@ private Link getLink(String rel) throws Exception {
private ServiceDescriptor getDescriptor() throws Exception {
String path = SERVICE_URI;
- ContainerResponse response = launcher.service("OPTIONS", path, BASE_URI, null, null, null, null);
+ ContainerResponse response = launcher.service(HttpMethod.OPTIONS, path, BASE_URI, null, null, null, null);
Assert.assertEquals(response.getStatus(), 200);
return (ServiceDescriptor)response.getEntity();
}
diff --git a/platform-api/che-core-api-core/src/test/java/org/eclipse/che/everrest/ETagResponseFilterTest.java b/platform-api/che-core-api-core/src/test/java/org/eclipse/che/everrest/ETagResponseFilterTest.java
index 6616798ee..818146cc8 100644
--- a/platform-api/che-core-api-core/src/test/java/org/eclipse/che/everrest/ETagResponseFilterTest.java
+++ b/platform-api/che-core-api-core/src/test/java/org/eclipse/che/everrest/ETagResponseFilterTest.java
@@ -26,10 +26,13 @@
import org.testng.annotations.Test;
import javax.ws.rs.GET;
+import javax.ws.rs.HttpMethod;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.EntityTag;
+import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
+
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
@@ -85,7 +88,7 @@ public String getMember() {
@Produces(APPLICATION_JSON)
public Response modifyHeader() {
return Response.ok("helloContent")
- .header("Content-Disposition", "attachment; filename=my.json")
+ .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=my.json")
.build();
}
@@ -130,7 +133,7 @@ public void before() throws Exception {
@Test
public void filterListEntityTest() throws Exception {
- final ContainerResponse response = resourceLauncher.service("GET", SERVICE_PATH + "/list", BASE_URI, null, null, null);
+ final ContainerResponse response = resourceLauncher.service(HttpMethod.GET, SERVICE_PATH + "/list", BASE_URI, null, null, null);
assertEquals(response.getStatus(), OK.getStatusCode());
// check entity
Assert.assertEquals(response.getEntity(), Arrays.asList("a", "b", "c"));
@@ -147,7 +150,7 @@ public void filterListEntityTest() throws Exception {
@Test
public void useExistingHeaders() throws Exception {
- final ContainerResponse response = resourceLauncher.service("GET", SERVICE_PATH + "/modify", BASE_URI, null, null, null);
+ final ContainerResponse response = resourceLauncher.service(HttpMethod.GET, SERVICE_PATH + "/modify", BASE_URI, null, null, null);
assertEquals(response.getStatus(), OK.getStatusCode());
// check entity
Assert.assertEquals(response.getEntity(), "helloContent");
@@ -156,7 +159,7 @@ public void useExistingHeaders() throws Exception {
Assert.assertEquals(response.getHttpHeaders().keySet().size(), 3);
// Check custom header
- List