Add example feign core project

add system client api


Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
SirWayne
2016-04-26 16:19:37 +02:00
parent 8addb05f09
commit c2649b4b54
24 changed files with 294 additions and 343 deletions

View File

@@ -15,7 +15,7 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPost;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRest;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetType;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.SoftwareManagement;
@@ -76,24 +76,24 @@ final class MgmtDistributionSetTypeMapper {
return result;
}
static List<MgmtDistributionSetTypeRest> toTypesResponse(final List<DistributionSetType> types) {
final List<MgmtDistributionSetTypeRest> response = new ArrayList<>();
static List<MgmtDistributionSetType> toTypesResponse(final List<DistributionSetType> types) {
final List<MgmtDistributionSetType> response = new ArrayList<>();
for (final DistributionSetType dsType : types) {
response.add(toResponse(dsType));
}
return response;
}
static List<MgmtDistributionSetTypeRest> toListResponse(final List<DistributionSetType> types) {
final List<MgmtDistributionSetTypeRest> response = new ArrayList<>();
static List<MgmtDistributionSetType> toListResponse(final List<DistributionSetType> types) {
final List<MgmtDistributionSetType> response = new ArrayList<>();
for (final DistributionSetType dsType : types) {
response.add(toResponse(dsType));
}
return response;
}
static MgmtDistributionSetTypeRest toResponse(final DistributionSetType type) {
final MgmtDistributionSetTypeRest result = new MgmtDistributionSetTypeRest();
static MgmtDistributionSetType toResponse(final DistributionSetType type) {
final MgmtDistributionSetType result = new MgmtDistributionSetType();
MgmtRestModelMapper.mapNamedToNamed(result, type);
result.setKey(type.getKey());

View File

@@ -14,7 +14,7 @@ import org.eclipse.hawkbit.mgmt.json.model.MgmtId;
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPost;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPut;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRest;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetType;
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleType;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
@@ -56,7 +56,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
private DistributionSetManagement distributionSetManagement;
@Override
public ResponseEntity<PagedList<MgmtDistributionSetTypeRest>> getDistributionSetTypes(
public ResponseEntity<PagedList<MgmtDistributionSetType>> getDistributionSetTypes(
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@@ -79,13 +79,13 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
countModulesAll = distributionSetManagement.countDistributionSetTypesAll();
}
final List<MgmtDistributionSetTypeRest> rest = MgmtDistributionSetTypeMapper
final List<MgmtDistributionSetType> rest = MgmtDistributionSetTypeMapper
.toListResponse(findModuleTypessAll.getContent());
return new ResponseEntity<>(new PagedList<>(rest, countModulesAll), HttpStatus.OK);
}
@Override
public ResponseEntity<MgmtDistributionSetTypeRest> getDistributionSetType(
public ResponseEntity<MgmtDistributionSetType> getDistributionSetType(
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId) {
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
@@ -103,7 +103,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
}
@Override
public ResponseEntity<MgmtDistributionSetTypeRest> updateDistributionSetType(
public ResponseEntity<MgmtDistributionSetType> updateDistributionSetType(
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId,
@RequestBody final MgmtDistributionSetTypeRequestBodyPut restDistributionSetType) {
final DistributionSetType type = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
@@ -121,7 +121,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
}
@Override
public ResponseEntity<List<MgmtDistributionSetTypeRest>> createDistributionSetTypes(
public ResponseEntity<List<MgmtDistributionSetType>> createDistributionSetTypes(
@RequestBody final List<MgmtDistributionSetTypeRequestBodyPost> distributionSetTypes) {
final List<DistributionSetType> createdSoftwareModules = distributionSetManagement.createDistributionSetTypes(

View File

@@ -10,25 +10,26 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.eclipse.hawkbit.artifact.repository.ArtifactRepository;
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
import org.eclipse.hawkbit.cache.CacheConstants;
import org.eclipse.hawkbit.cache.DownloadArtifactCache;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDownloadRestApi;
import org.eclipse.hawkbit.rest.util.RequestResponseContextHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.Cache;
import org.springframework.cache.Cache.ValueWrapper;
import org.springframework.context.annotation.Scope;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.WebApplicationContext;
/**
* A resource for download artifacts.
@@ -37,6 +38,7 @@ import org.springframework.web.bind.annotation.RestController;
*
*/
@RestController
@Scope(value = WebApplicationContext.SCOPE_REQUEST)
public class MgmtDownloadResource implements MgmtDownloadRestApi {
private static final Logger LOGGER = LoggerFactory.getLogger(MgmtDownloadResource.class);
@@ -48,6 +50,9 @@ public class MgmtDownloadResource implements MgmtDownloadRestApi {
@Qualifier(CacheConstants.DOWNLOAD_ID_CACHE)
private Cache cache;
@Autowired
private RequestResponseContextHolder requestResponseContextHolder;
/**
* Handles the GET request for downloading an artifact.
*
@@ -60,8 +65,7 @@ public class MgmtDownloadResource implements MgmtDownloadRestApi {
*/
@Override
@ResponseBody
public ResponseEntity<Void> downloadArtifactByDownloadId(@PathVariable("downloadId") final String downloadId,
final HttpServletResponse response) {
public ResponseEntity<Void> downloadArtifactByDownloadId(@PathVariable("downloadId") final String downloadId) {
try {
final ValueWrapper cacheWrapper = cache.get(downloadId);
if (cacheWrapper == null) {
@@ -87,7 +91,8 @@ public class MgmtDownloadResource implements MgmtDownloadRestApi {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
try {
IOUtils.copy(artifact.getFileInputStream(), response.getOutputStream());
IOUtils.copy(artifact.getFileInputStream(),
requestResponseContextHolder.getHttpServletResponse().getOutputStream());
} catch (final IOException e) {
LOGGER.error("Cannot copy streams", e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();