Author: ilgrosso Date: Tue Feb 5 17:05:59 2013 New Revision: 1442663 URL: http://svn.apache.org/viewvc?rev=1442663&view=rev Log: Centralizing stream handling (db and report export) in SpringServiceProxy + Various small fixes
Modified: syncope/trunk/client/src/main/java/org/apache/syncope/client/rest/utils/RestClientExceptionMapper.java syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ConfigurationServiceProxy.java syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ReportServiceProxy.java syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/SpringServiceProxy.java syncope/trunk/common/src/main/java/org/apache/syncope/common/SyncopeConstants.java syncope/trunk/common/src/main/java/org/apache/syncope/common/types/ReportExecExportFormat.java syncope/trunk/console/src/main/java/org/apache/syncope/console/commons/HttpResourceStream.java syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/Configuration.java syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/ReportExecResultDownloadModalPage.java syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/ReportModalPage.java syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/ConfigurationRestClient.java syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/ReportRestClient.java syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/AjaxDropDownChoicePanel.java syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/FieldPanel.java syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/ReportExecResultDownloadModalPage.html syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationJob.java syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationManager.java syncope/trunk/core/src/main/java/org/apache/syncope/core/report/ReportJob.java syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ConfigurationController.java syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ReportController.java syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ImportExport.java syncope/trunk/core/src/main/java/org/apache/syncope/core/util/XMLSerializer.java syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConfigurationTestITCase.java syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ReportTestITCase.java Modified: syncope/trunk/client/src/main/java/org/apache/syncope/client/rest/utils/RestClientExceptionMapper.java URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/rest/utils/RestClientExceptionMapper.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/client/src/main/java/org/apache/syncope/client/rest/utils/RestClientExceptionMapper.java (original) +++ syncope/trunk/client/src/main/java/org/apache/syncope/client/rest/utils/RestClientExceptionMapper.java Tue Feb 5 17:05:59 2013 @@ -23,13 +23,11 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; - import javax.ws.rs.BadRequestException; import javax.ws.rs.core.Response; import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.Provider; import javax.xml.ws.WebServiceException; - import org.apache.cxf.jaxrs.client.ResponseExceptionMapper; import org.apache.http.HttpStatus; import org.apache.syncope.common.types.SyncopeClientExceptionType; @@ -83,8 +81,7 @@ public class RestClientExceptionMapper i private SyncopeClientCompositeErrorException checkCompositeException(final Response response) { final int statusCode = response.getStatus(); - List<Object> exTypesInHeaders = response.getHeaders().get( - SyncopeClientErrorHandler.EXCEPTION_TYPE_HEADER); + List<Object> exTypesInHeaders = response.getHeaders().get(SyncopeClientErrorHandler.EXCEPTION_TYPE_HEADER); if (exTypesInHeaders == null) { LOG.debug("No " + SyncopeClientErrorHandler.EXCEPTION_TYPE_HEADER + " provided"); return null; Modified: syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ConfigurationServiceProxy.java URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ConfigurationServiceProxy.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ConfigurationServiceProxy.java (original) +++ syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ConfigurationServiceProxy.java Tue Feb 5 17:05:59 2013 @@ -18,7 +18,6 @@ */ package org.apache.syncope.client.services.proxy; -import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URLEncoder; @@ -28,18 +27,6 @@ import java.util.List; import java.util.Set; import javax.ws.rs.InternalServerErrorException; import javax.ws.rs.core.Response; -import org.apache.http.HttpEntity; -import org.apache.http.HttpHost; -import org.apache.http.HttpResponse; -import org.apache.http.HttpStatus; -import org.apache.http.auth.AuthScope; -import org.apache.http.client.AuthCache; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.protocol.ClientContext; -import org.apache.http.impl.auth.BasicScheme; -import org.apache.http.impl.client.BasicAuthCache; -import org.apache.http.protocol.BasicHttpContext; -import org.apache.syncope.client.http.PreemptiveAuthHttpRequestFactory; import org.apache.syncope.common.SyncopeConstants; import org.apache.syncope.common.services.ConfigurationService; import org.apache.syncope.common.to.ConfigurationTO; @@ -108,36 +95,6 @@ public class ConfigurationServiceProxy e @Override public Response dbExport() { - final AuthScope scope = ((PreemptiveAuthHttpRequestFactory) getRestTemplate().getRequestFactory()). - getAuthScope(); - final HttpHost targetHost = new HttpHost(scope.getHost(), scope.getPort(), scope.getScheme()); - final BasicHttpContext localcontext = new BasicHttpContext(); - final AuthCache authCache = new BasicAuthCache(); - authCache.put(targetHost, new BasicScheme()); - localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache); - - final HttpGet getMethod = new HttpGet(baseUrl + "configuration/dbexport"); - try { - final HttpResponse httpResponse = - ((PreemptiveAuthHttpRequestFactory) getRestTemplate().getRequestFactory()). - getHttpClient().execute(targetHost, getMethod, localcontext); - - Response response; - if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { - HttpEntity entity = httpResponse.getEntity(); - response = Response.ok(entity.getContent(), entity.getContentType().getValue()). - location(getMethod.getURI()). - header("Content-Disposition", httpResponse.getLastHeader("Content-Disposition").getValue()). - build(); - } else { - response = Response.noContent().status(httpResponse.getStatusLine().getStatusCode()). - location(getMethod.getURI()). - build(); - } - - return response; - } catch (IOException e) { - throw new InternalServerErrorException(e); - } + return handleStream(baseUrl + "configuration/dbexport"); } } Modified: syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ReportServiceProxy.java URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ReportServiceProxy.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ReportServiceProxy.java (original) +++ syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ReportServiceProxy.java Tue Feb 5 17:05:59 2013 @@ -18,13 +18,10 @@ */ package org.apache.syncope.client.services.proxy; -import java.io.InputStream; import java.net.URI; import java.util.Arrays; import java.util.List; - import javax.ws.rs.core.Response; - import org.apache.syncope.common.SyncopeConstants; import org.apache.syncope.common.services.ReportService; import org.apache.syncope.common.services.ReportletConfClasses; @@ -92,12 +89,10 @@ public class ReportServiceProxy extends @Override public Response exportExecutionResult(final Long executionId, final ReportExecExportFormat fmt) { - String format = (fmt != null) - ? "?fmt=" + fmt.toString() - : ""; - InputStream stream = getRestTemplate().getForObject(baseUrl + "report/execution/export/{executionId}" + format, - InputStream.class, executionId); - return Response.ok(stream).build(); + final String format = fmt == null + ? "" + : "?fmt=" + fmt.toString(); + return handleStream(baseUrl + "report/execution/export/" + executionId + format); } @Override Modified: syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/SpringServiceProxy.java URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/SpringServiceProxy.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/SpringServiceProxy.java (original) +++ syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/SpringServiceProxy.java Tue Feb 5 17:05:59 2013 @@ -18,6 +18,22 @@ */ package org.apache.syncope.client.services.proxy; +import java.io.IOException; +import javax.ws.rs.InternalServerErrorException; +import javax.ws.rs.core.Response; +import org.apache.http.HttpEntity; +import org.apache.http.HttpHost; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.auth.AuthScope; +import org.apache.http.client.AuthCache; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.protocol.ClientContext; +import org.apache.http.impl.auth.BasicScheme; +import org.apache.http.impl.client.BasicAuthCache; +import org.apache.http.protocol.BasicHttpContext; +import org.apache.syncope.client.http.PreemptiveAuthHttpRequestFactory; +import org.apache.syncope.common.SyncopeConstants; import org.springframework.web.client.RestTemplate; public abstract class SpringServiceProxy { @@ -38,4 +54,39 @@ public abstract class SpringServiceProxy public RestTemplate getRestTemplate() { return restTemplate; } + + protected Response handleStream(final String url) { + final AuthScope scope = ((PreemptiveAuthHttpRequestFactory) getRestTemplate().getRequestFactory()). + getAuthScope(); + final HttpHost targetHost = new HttpHost(scope.getHost(), scope.getPort(), scope.getScheme()); + final BasicHttpContext localcontext = new BasicHttpContext(); + final AuthCache authCache = new BasicAuthCache(); + authCache.put(targetHost, new BasicScheme()); + localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache); + + final HttpGet getMethod = new HttpGet(url); + try { + final HttpResponse httpResponse = + ((PreemptiveAuthHttpRequestFactory) getRestTemplate().getRequestFactory()). + getHttpClient().execute(targetHost, getMethod, localcontext); + + Response response; + if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + HttpEntity entity = httpResponse.getEntity(); + response = Response.ok(entity.getContent(), entity.getContentType().getValue()). + location(getMethod.getURI()). + header(SyncopeConstants.CONTENT_DISPOSITION_HEADER, + httpResponse.getLastHeader(SyncopeConstants.CONTENT_DISPOSITION_HEADER).getValue()). + build(); + } else { + response = Response.noContent().status(httpResponse.getStatusLine().getStatusCode()). + location(getMethod.getURI()). + build(); + } + + return response; + } catch (IOException e) { + throw new InternalServerErrorException(e); + } + } } Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/SyncopeConstants.java URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/SyncopeConstants.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/common/src/main/java/org/apache/syncope/common/SyncopeConstants.java (original) +++ syncope/trunk/common/src/main/java/org/apache/syncope/common/SyncopeConstants.java Tue Feb 5 17:05:59 2013 @@ -18,7 +18,6 @@ */ package org.apache.syncope.common; - public class SyncopeConstants { public static final String[] DATE_PATTERNS = { @@ -32,12 +31,18 @@ public class SyncopeConstants { public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd'T'HH:mm:ssZ"; /** - * This constant will be used to identify HTTP header key to look for object ID assigned - * to an object after its creation. HTTP Response after PUT operation should contain this - * key with resource id as its value. + * This constant will be used to identify HTTP header key to look for object ID assigned to an object after its + * creation. HTTP Response after PUT operation should contain this key with resource id as its value. */ public static final String REST_HEADER_ID = "org.apache.syncope.resource.id"; + /** + * This constant is not defined in javax.ws.rs.core.HttpHeaders. + * + * @see javax.ws.rs.core.HttpHeaders + */ + public static final String CONTENT_DISPOSITION_HEADER = "Content-Disposition"; + public static final String DEFAULT_ENCODING = "UTF-8"; } Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/types/ReportExecExportFormat.java URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/types/ReportExecExportFormat.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/common/src/main/java/org/apache/syncope/common/types/ReportExecExportFormat.java (original) +++ syncope/trunk/common/src/main/java/org/apache/syncope/common/types/ReportExecExportFormat.java Tue Feb 5 17:05:59 2013 @@ -26,10 +26,6 @@ public enum ReportExecExportFormat { XML, HTML, PDF, - RTF; - - public static ReportExecExportFormat fromString(String value) { - return ReportExecExportFormat.valueOf(value.toUpperCase()); - } + RTF } Modified: syncope/trunk/console/src/main/java/org/apache/syncope/console/commons/HttpResourceStream.java URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/commons/HttpResourceStream.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/console/src/main/java/org/apache/syncope/console/commons/HttpResourceStream.java (original) +++ syncope/trunk/console/src/main/java/org/apache/syncope/console/commons/HttpResourceStream.java Tue Feb 5 17:05:59 2013 @@ -21,145 +21,81 @@ package org.apache.syncope.console.commo import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.net.URI; -import java.net.URISyntaxException; -import org.apache.http.Header; -import org.apache.http.HttpEntity; -import org.apache.http.HttpHost; -import org.apache.http.HttpResponse; -import org.apache.http.ProtocolVersion; -import org.apache.http.auth.AuthScope; -import org.apache.http.client.AuthCache; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.protocol.ClientContext; -import org.apache.http.entity.BasicHttpEntity; -import org.apache.http.impl.auth.BasicScheme; -import org.apache.http.impl.client.BasicAuthCache; -import org.apache.http.message.BasicHttpResponse; -import org.apache.http.protocol.BasicHttpContext; -import org.apache.syncope.client.http.PreemptiveAuthHttpRequestFactory; -import org.apache.syncope.console.SyncopeSession; -import org.apache.wicket.util.lang.Args; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.apache.commons.lang.StringUtils; +import org.apache.http.HttpStatus; +import org.apache.syncope.common.SyncopeConstants; +import org.apache.wicket.util.lang.Bytes; import org.apache.wicket.util.resource.AbstractResourceStream; import org.apache.wicket.util.resource.IFixedLocationResourceStream; import org.apache.wicket.util.resource.ResourceStreamNotFoundException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.MediaType; public class HttpResourceStream extends AbstractResourceStream implements IFixedLocationResourceStream { private static final long serialVersionUID = 5811207817876330189L; - private static final Logger LOG = LoggerFactory.getLogger(HttpResourceStream.class); + private transient InputStream inputStream; - private final URI uri; + private String location; - private transient HttpEntity responseEntity; + private String contentType; - private transient String contentType; + private String filename; - private transient String filename; - - public HttpResourceStream(final String uri) - throws URISyntaxException { - this.uri = new URI(Args.notNull(uri, "uri")); - } - - private HttpResponse buildFakeResponse(final String errorMessage) { - ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); - BasicHttpEntity entity = new BasicHttpEntity(); - entity.setContent(bais); - entity.setContentLength(0); - entity.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); - - BasicHttpResponse response = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), 400, "Exception: " - + errorMessage); - response.setEntity(entity); - - response.addHeader("Content-Disposition", "attachment; filename=error"); - - return response; - } - - private void execute() { - if (responseEntity != null) { - return; - } - - final AuthScope scope = ((PreemptiveAuthHttpRequestFactory) SyncopeSession.get().getRestTemplate(). - getRequestFactory()).getAuthScope(); - final HttpHost targetHost = new HttpHost(scope.getHost(), scope.getPort(), scope.getScheme()); - BasicHttpContext localcontext = new BasicHttpContext(); - // Generate BASIC scheme object and add it to the local auth cache - AuthCache authCache = new BasicAuthCache(); - authCache.put(targetHost, new BasicScheme()); - localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache); - - HttpGet getMethod = new HttpGet(this.uri); - HttpResponse response; - try { - response = ((PreemptiveAuthHttpRequestFactory) SyncopeSession.get().getRestTemplate().getRequestFactory()). - getHttpClient().execute(targetHost, getMethod, localcontext); - } catch (Exception e) { - LOG.error("Unexpected exception while executing HTTP method to {}", this.uri, e); - response = buildFakeResponse(e.getMessage()); - } - if (response.getStatusLine().getStatusCode() != 200) { - LOG.error("Unsuccessful HTTP method to {} {}", this.uri, response); - response = buildFakeResponse("HTTP status " + response.getStatusLine().getStatusCode()); - } - - responseEntity = response.getEntity(); - - Header[] headers = response.getHeaders("Content-Disposition"); - if (headers != null && headers.length > 0) { - String value = headers[0].getValue(); - String[] splitted = value.split("="); - if (splitted != null && splitted.length > 1) { - filename = splitted[1].trim(); + public HttpResourceStream(final Response response) { + Object entity = response.getEntity(); + if (response.getStatus() == HttpStatus.SC_OK && (entity instanceof InputStream)) { + this.inputStream = (InputStream) entity; + this.location = response.getLocation().toString(); + this.contentType = response.getHeaderString(HttpHeaders.CONTENT_TYPE); + String contentDisposition = response.getHeaderString(SyncopeConstants.CONTENT_DISPOSITION_HEADER); + if (StringUtils.isNotBlank(contentDisposition)) { + String[] splitted = contentDisposition.split("="); + if (splitted != null && splitted.length > 1) { + this.filename = splitted[1].trim(); + } } - } else { - LOG.warn("Could not find Content-Disposition HTTP header"); } - - contentType = responseEntity.getContentType().getValue(); } @Override public InputStream getInputStream() throws ResourceStreamNotFoundException { - try { - execute(); - return responseEntity.getContent(); - } catch (Exception e) { - throw new ResourceStreamNotFoundException(e); - } + return inputStream == null + ? new ByteArrayInputStream(new byte[0]) + : inputStream; } @Override - public void close() - throws IOException { - // Nothing needed here, because we are using HttpComponents HttpClient + public Bytes length() { + return inputStream == null + ? Bytes.bytes(0) + : null; + } + + @Override + public void close() throws IOException { + // No need for explict closing } @Override public String locationAsString() { - return uri.toString(); + return location; } @Override public String getContentType() { - execute(); - return contentType == null - ? MediaType.APPLICATION_OCTET_STREAM_VALUE + ? MediaType.APPLICATION_OCTET_STREAM : contentType; } public String getFilename() { - execute(); - return filename; + return filename == null + ? "error" + : filename; } } Modified: syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/Configuration.java URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/Configuration.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/Configuration.java (original) +++ syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/Configuration.java Tue Feb 5 17:05:59 2013 @@ -337,7 +337,7 @@ public class Configuration extends BaseP @Override public void onClick() { try { - HttpResourceStream stream = new HttpResourceStream(baseURL + "configuration/dbexport"); + HttpResourceStream stream = new HttpResourceStream(confRestClient.dbExport()); ResourceStreamRequestHandler rsrh = new ResourceStreamRequestHandler(stream); rsrh.setFileName(stream.getFilename() == null ? "content.xml" : stream.getFilename()); @@ -540,7 +540,7 @@ public class Configuration extends BaseP Collections.sort(list, comparator); - return list.subList((int)first, (int)first + (int)count).iterator(); + return list.subList((int) first, (int) first + (int) count).iterator(); } @Override @@ -563,7 +563,7 @@ public class Configuration extends BaseP } } - private class NotificationProvider extends SortableDataProvider<NotificationTO,String> { + private class NotificationProvider extends SortableDataProvider<NotificationTO, String> { private static final long serialVersionUID = -276043813563988590L; @@ -581,7 +581,7 @@ public class Configuration extends BaseP Collections.sort(list, comparator); - return list.subList((int)first, (int)first + (int)count).iterator(); + return list.subList((int) first, (int) first + (int) count).iterator(); } @Override Modified: syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/ReportExecResultDownloadModalPage.java URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/ReportExecResultDownloadModalPage.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/ReportExecResultDownloadModalPage.java (original) +++ syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/ReportExecResultDownloadModalPage.java Tue Feb 5 17:05:59 2013 @@ -34,7 +34,8 @@ public class ReportExecResultDownloadMod public ReportExecResultDownloadModalPage(final ModalWindow window, final PageReference callerPageRef) { - final AjaxDropDownChoicePanel<ReportExecExportFormat> format = new AjaxDropDownChoicePanel<ReportExecExportFormat>( + final AjaxDropDownChoicePanel<ReportExecExportFormat> format = + new AjaxDropDownChoicePanel<ReportExecExportFormat>( "format", "format", new Model<ReportExecExportFormat>()); format.setChoices(Arrays.asList(ReportExecExportFormat.values())); @@ -61,7 +62,9 @@ public class ReportExecResultDownloadMod @Override protected void onUpdate(final AjaxRequestTarget target) { - ((ReportModalPage) callerPageRef.getPage()).setExportFormat(format.getField().getInput()); + format.getField(); + + ((ReportModalPage) callerPageRef.getPage()).setExportFormat(format.getField().getModelObject()); window.close(target); } }); Modified: syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/ReportModalPage.java URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/ReportModalPage.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/ReportModalPage.java (original) +++ syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/ReportModalPage.java Tue Feb 5 17:05:59 2013 @@ -26,6 +26,7 @@ import org.apache.syncope.common.report. import org.apache.syncope.common.report.ReportletConf; import org.apache.syncope.common.to.ReportExecTO; import org.apache.syncope.common.to.ReportTO; +import org.apache.syncope.common.types.ReportExecExportFormat; import org.apache.syncope.common.types.ReportExecStatus; import org.apache.syncope.common.validation.SyncopeClientCompositeErrorException; import org.apache.syncope.console.commons.DateFormatROModel; @@ -105,7 +106,7 @@ public class ReportModalPage extends Bas private Form<ReportTO> form; - private String exportFormat; + private ReportExecExportFormat exportFormat; private long exportExecId; @@ -560,7 +561,7 @@ public class ReportModalPage extends Bas executions.add(reload); } - public void setExportFormat(final String exportFormat) { + public void setExportFormat(final ReportExecExportFormat exportFormat) { this.exportFormat = exportFormat; } @@ -616,35 +617,20 @@ public class ReportModalPage extends Bas private static final long serialVersionUID = 3109256773218160485L; - private final String exportFormat; + private final ReportExecExportFormat exportFormat; private final long exportExecId; - private String url; - private HttpResourceStream stream; - public AjaxExportDownloadBehavior(final String exportFormat, final long exportExecId) { + public AjaxExportDownloadBehavior(final ReportExecExportFormat exportFormat, final long exportExecId) { this.exportFormat = exportFormat; this.exportExecId = exportExecId; } private void createResourceStream() { - StringBuilder urlBuilder = new StringBuilder(); - urlBuilder.append(baseURL).append("report/execution/export/").append(exportExecId); - if (exportFormat != null) { - urlBuilder.append("?fmt=").append(exportFormat); - } - - if (this.url != null && this.url.equals(urlBuilder.toString())) { - return; - } - this.url = urlBuilder.toString(); - - try { - stream = new HttpResourceStream(this.url); - } catch (Exception e) { - LOG.error("While contacting target URL", e); + if (stream == null) { + stream = new HttpResourceStream(restClient.exportExecutionResult(exportExecId, exportFormat)); } } Modified: syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/ConfigurationRestClient.java URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/ConfigurationRestClient.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/ConfigurationRestClient.java (original) +++ syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/ConfigurationRestClient.java Tue Feb 5 17:05:59 2013 @@ -19,7 +19,7 @@ package org.apache.syncope.console.rest; import java.util.List; - +import javax.ws.rs.core.Response; import org.apache.syncope.common.services.ConfigurationService; import org.apache.syncope.common.to.ConfigurationTO; import org.springframework.stereotype.Component; @@ -68,4 +68,8 @@ public class ConfigurationRestClient ext getService(ConfigurationService.class).delete(key); return response; } + + public Response dbExport() { + return getService(ConfigurationService.class).dbExport(); + } } Modified: syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/ReportRestClient.java URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/ReportRestClient.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/ReportRestClient.java (original) +++ syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/ReportRestClient.java Tue Feb 5 17:05:59 2013 @@ -20,13 +20,12 @@ package org.apache.syncope.console.rest; import java.util.ArrayList; import java.util.List; - import javax.ws.rs.core.Response; - import org.apache.syncope.common.services.ReportService; import org.apache.syncope.common.services.ReportletConfClasses; import org.apache.syncope.common.to.ReportExecTO; import org.apache.syncope.common.to.ReportTO; +import org.apache.syncope.common.types.ReportExecExportFormat; import org.apache.syncope.common.validation.SyncopeClientCompositeErrorException; import org.springframework.stereotype.Component; @@ -109,4 +108,8 @@ public class ReportRestClient extends Ba public List<ReportExecTO> listExecutions() { return getService(ReportService.class).listExecutions(); } + + public Response exportExecutionResult(final Long executionId, final ReportExecExportFormat fmt) { + return getService(ReportService.class).exportExecutionResult(executionId, fmt); + } } Modified: syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/AjaxDropDownChoicePanel.java URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/AjaxDropDownChoicePanel.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/AjaxDropDownChoicePanel.java (original) +++ syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/AjaxDropDownChoicePanel.java Tue Feb 5 17:05:59 2013 @@ -18,6 +18,7 @@ */ package org.apache.syncope.console.wicket.markup.html.form; +import java.io.Serializable; import java.util.Collections; import java.util.List; import org.apache.wicket.ajax.AjaxRequestTarget; @@ -28,7 +29,7 @@ import org.apache.wicket.markup.html.for import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; -public class AjaxDropDownChoicePanel<T> extends FieldPanel implements Cloneable { +public class AjaxDropDownChoicePanel<T extends Serializable> extends FieldPanel<T> implements Cloneable { private static final long serialVersionUID = -4716376580659196095L; Modified: syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/FieldPanel.java URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/FieldPanel.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/FieldPanel.java (original) +++ syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/FieldPanel.java Tue Feb 5 17:05:59 2013 @@ -32,7 +32,7 @@ public abstract class FieldPanel<T exten private static final long serialVersionUID = -198988924922541273L; - protected FormComponent field = null; + protected FormComponent<T> field = null; final protected String id; @@ -54,11 +54,11 @@ public abstract class FieldPanel<T exten setOutputMarkupId(true); } - public FormComponent getField() { + public FormComponent<T> getField() { return field; } - public FieldPanel setTitle(String title) { + public FieldPanel setTitle(final String title) { field.add(AttributeModifier.replace("title", title != null ? title : "")); Modified: syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/ReportExecResultDownloadModalPage.html URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/ReportExecResultDownloadModalPage.html?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/ReportExecResultDownloadModalPage.html (original) +++ syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/ReportExecResultDownloadModalPage.html Tue Feb 5 17:05:59 2013 @@ -17,7 +17,7 @@ specific language governing permissions under the License. --> <wicket:extend> - <div id="dialog"> - <wicket:message key="downloadAs"/> <span wicket:id="format" class="small_dynamicsize">[format]</span> - </div> + <div id="dialog"> + <wicket:message key="downloadAs"/> <span wicket:id="format" class="small_dynamicsize">[format]</span> + </div> </wicket:extend> Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationJob.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationJob.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationJob.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationJob.java Tue Feb 5 17:05:59 2013 @@ -21,10 +21,9 @@ package org.apache.syncope.core.notifica import java.io.PrintWriter; import java.io.StringWriter; import java.util.Date; - import javax.mail.internet.MimeMessage; - import org.apache.commons.lang.StringUtils; +import org.apache.syncope.common.SyncopeConstants; import org.apache.syncope.common.types.AuditElements.Category; import org.apache.syncope.common.types.AuditElements.NotificationSubCategory; import org.apache.syncope.common.types.AuditElements.Result; @@ -147,7 +146,7 @@ public class NotificationJob implements JavaMailSenderImpl sender = new JavaMailSenderImpl(); sender.setHost(smtpHost); sender.setPort(smtpPort); - sender.setDefaultEncoding("UTF-8"); + sender.setDefaultEncoding(SyncopeConstants.DEFAULT_ENCODING); if (StringUtils.isNotBlank(smtpUsername)) { sender.setUsername(smtpUsername); } Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationManager.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationManager.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationManager.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationManager.java Tue Feb 5 17:05:59 2013 @@ -24,7 +24,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; - +import org.apache.syncope.common.SyncopeConstants; import org.apache.syncope.common.to.UserTO; import org.apache.syncope.common.types.AttributableType; import org.apache.syncope.common.types.IntMappingType; @@ -171,9 +171,9 @@ public class NotificationManager { String textBody; try { htmlBody = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "mailTemplates/" - + notification.getTemplate() + ".html.vm", "UTF-8", model); + + notification.getTemplate() + ".html.vm", SyncopeConstants.DEFAULT_ENCODING, model); textBody = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "mailTemplates/" - + notification.getTemplate() + ".txt.vm", "UTF-8", model); + + notification.getTemplate() + ".txt.vm", SyncopeConstants.DEFAULT_ENCODING, model); } catch (VelocityException e) { LOG.error("Could not get mail body", e); Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/report/ReportJob.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/report/ReportJob.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/report/ReportJob.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/report/ReportJob.java Tue Feb 5 17:05:59 2013 @@ -35,6 +35,7 @@ import javax.xml.transform.Transformer; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.stream.StreamResult; +import org.apache.syncope.common.SyncopeConstants; import org.apache.syncope.common.report.ReportletConf; import org.apache.syncope.common.types.ReportExecStatus; import org.apache.syncope.core.persistence.beans.Report; @@ -125,7 +126,7 @@ public class ReportJob implements Job { SAXTransformerFactory tFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); handler = tFactory.newTransformerHandler(); Transformer serializer = handler.getTransformer(); - serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + serializer.setOutputProperty(OutputKeys.ENCODING, SyncopeConstants.DEFAULT_ENCODING); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); // a single ZipEntry in the ZipOutputStream Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ConfigurationController.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ConfigurationController.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ConfigurationController.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ConfigurationController.java Tue Feb 5 17:05:59 2013 @@ -26,6 +26,8 @@ import java.util.List; import java.util.Set; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.core.MediaType; +import org.apache.syncope.common.SyncopeConstants; import org.apache.syncope.common.to.ConfigurationTO; import org.apache.syncope.common.types.AuditElements.Category; import org.apache.syncope.common.types.AuditElements.ConfigurationSubCategory; @@ -42,7 +44,6 @@ import org.apache.syncope.core.util.Impo import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.Resource; import org.springframework.core.io.support.ResourcePatternResolver; -import org.springframework.http.MediaType; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; @@ -210,8 +211,9 @@ public class ConfigurationController ext @RequestMapping(method = RequestMethod.GET, value = "/dbexport") @Transactional(readOnly = true) public void dbExport(final HttpServletResponse response) { - response.setContentType(MediaType.TEXT_XML_VALUE); - response.setHeader("Content-Disposition", "attachment; filename=" + ImportExport.CONTENT_FILE); + response.setContentType(MediaType.TEXT_XML); + response.setHeader(SyncopeConstants.CONTENT_DISPOSITION_HEADER, + "attachment; filename=" + ImportExport.CONTENT_FILE); try { dbExportInternal(response.getOutputStream()); } catch (IOException e) { Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ReportController.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ReportController.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ReportController.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ReportController.java Tue Feb 5 17:05:59 2013 @@ -29,10 +29,9 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.zip.ZipInputStream; - import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; - +import javax.ws.rs.core.MediaType; import org.apache.cocoon.optional.pipeline.components.sax.fop.FopSerializer; import org.apache.cocoon.pipeline.NonCachingPipeline; import org.apache.cocoon.pipeline.Pipeline; @@ -40,6 +39,7 @@ import org.apache.cocoon.sax.SAXPipeline import org.apache.cocoon.sax.component.XMLGenerator; import org.apache.cocoon.sax.component.XMLSerializer; import org.apache.cocoon.sax.component.XSLTTransformer; +import org.apache.syncope.common.SyncopeConstants; import org.apache.syncope.common.report.ReportletConf; import org.apache.syncope.common.to.ReportExecTO; import org.apache.syncope.common.to.ReportTO; @@ -65,7 +65,6 @@ import org.quartz.JobKey; import org.quartz.Scheduler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.scheduling.quartz.SchedulerFactoryBean; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; @@ -280,21 +279,23 @@ public class ReportController extends Ab ServletOutputStream os; try { os = response.getOutputStream(); - } catch (IOException e1) { - throw new RuntimeException("Could not retrieve stream", e1); + } catch (IOException e) { + throw new RuntimeException("Could not retrieve stream", e); } ReportExec reportExec = getAndCheckReportExecInternal(executionId); ReportExecExportFormat format = (fmt == null) ? ReportExecExportFormat.XML : fmt; - response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); - response.addHeader("Content-Disposition", "attachment; filename=" + reportExec.getReport().getName() + "." - + format.name().toLowerCase()); + response.setContentType(MediaType.APPLICATION_OCTET_STREAM); + response.addHeader(SyncopeConstants.CONTENT_DISPOSITION_HEADER, + "attachment; filename=" + reportExec.getReport().getName() + "." + format.name().toLowerCase()); exportExecutionResultInternal(os, reportExec, format); } - public void exportExecutionResultInternal(OutputStream os, ReportExec reportExec, ReportExecExportFormat format) { + public void exportExecutionResultInternal(final OutputStream os, final ReportExec reportExec, + final ReportExecExportFormat format) { + LOG.debug("Exporting result of {} as {}", reportExec, format); // streaming SAX handler from a compressed byte array stream @@ -361,6 +362,7 @@ public class ReportController extends Ab public ReportExec getAndCheckReportExecInternal(final Long executionId) throws NotFoundException { + ReportExec reportExec = reportExecDAO.find(executionId); if (reportExec == null) { throw new NotFoundException("Report execution " + executionId); Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ImportExport.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ImportExport.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ImportExport.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ImportExport.java Tue Feb 5 17:05:59 2013 @@ -486,7 +486,7 @@ public class ImportExport extends Defaul TransformerHandler handler = transformerFactory.newTransformerHandler(); Transformer serializer = handler.getTransformer(); - serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + serializer.setOutputProperty(OutputKeys.ENCODING, SyncopeConstants.DEFAULT_ENCODING); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); handler.setResult(streamResult); handler.startDocument(); Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/XMLSerializer.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/XMLSerializer.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/util/XMLSerializer.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/util/XMLSerializer.java Tue Feb 5 17:05:59 2013 @@ -18,15 +18,14 @@ */ package org.apache.syncope.core.util; +import com.thoughtworks.xstream.XStream; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; - +import org.apache.syncope.common.SyncopeConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.thoughtworks.xstream.XStream; - /** * Helper class for serialization and deserialization of configuration objects, empowering XStream. * @@ -42,7 +41,7 @@ public final class XMLSerializer { XStream xstream = new XStream(); xstream.registerConverter(new GuardedStringConverter()); try { - result = URLEncoder.encode(xstream.toXML(object), "UTF-8"); + result = URLEncoder.encode(xstream.toXML(object), SyncopeConstants.DEFAULT_ENCODING); } catch (UnsupportedEncodingException e) { LOG.error("During serialization", e); } @@ -57,7 +56,7 @@ public final class XMLSerializer { XStream xstream = new XStream(); xstream.registerConverter(new GuardedStringConverter()); try { - result = (T) xstream.fromXML(URLDecoder.decode(serialized, "UTF-8")); + result = (T) xstream.fromXML(URLDecoder.decode(serialized, SyncopeConstants.DEFAULT_ENCODING)); } catch (UnsupportedEncodingException e) { LOG.error("During deserialization", e); } Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConfigurationTestITCase.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConfigurationTestITCase.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConfigurationTestITCase.java (original) +++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConfigurationTestITCase.java Tue Feb 5 17:05:59 2013 @@ -27,14 +27,16 @@ import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.util.List; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.apache.commons.io.IOUtils; +import org.apache.syncope.common.SyncopeConstants; import org.apache.syncope.common.to.ConfigurationTO; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.web.client.HttpStatusCodeException; @FixMethodOrder(MethodSorters.JVM) @@ -55,7 +57,6 @@ public class ConfigurationTestITCase ext @Test public void delete() throws UnsupportedEncodingException { - try { configurationService.delete("nonExistent"); } catch (HttpStatusCodeException e) { @@ -113,9 +114,10 @@ public class ConfigurationTestITCase ext public void dbExport() throws IOException { Response response = configurationService.dbExport(); assertNotNull(response); + assertEquals(HttpStatus.OK.value(), response.getStatus()); assertNotNull(response.getLocation()); - assertTrue(response.getHeaderString("Content-Type").startsWith(MediaType.TEXT_XML_VALUE)); - assertNotNull(response.getHeaderString("Content-Disposition")); + assertTrue(response.getHeaderString(HttpHeaders.CONTENT_TYPE).startsWith(MediaType.TEXT_XML)); + assertNotNull(response.getHeaderString(SyncopeConstants.CONTENT_DISPOSITION_HEADER)); Object entity = response.getEntity(); assertTrue(entity instanceof InputStream); Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ReportTestITCase.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ReportTestITCase.java?rev=1442663&r1=1442662&r2=1442663&view=diff ============================================================================== --- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ReportTestITCase.java (original) +++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ReportTestITCase.java Tue Feb 5 17:05:59 2013 @@ -25,17 +25,16 @@ import static org.junit.Assert.assertTru import static org.junit.Assert.fail; import java.io.IOException; -import java.io.StringWriter; -import java.net.HttpURLConnection; -import java.net.URL; +import java.io.InputStream; import java.util.List; import javax.ws.rs.core.Response; -import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.IOUtils; +import org.apache.syncope.common.SyncopeConstants; import org.apache.syncope.common.report.UserReportletConf; import org.apache.syncope.common.services.ReportletConfClasses; import org.apache.syncope.common.to.ReportExecTO; import org.apache.syncope.common.to.ReportTO; +import org.apache.syncope.common.types.ReportExecExportFormat; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; @@ -155,32 +154,18 @@ public class ReportTestITCase extends Ab } } - private void checkExport(final long execId, final String fmt, final String encodedAuth) - throws IOException { - - URL url = new URL(BASE_URL + "report/execution/export/" + execId + "?fmt=" + fmt); - int responseCode = 0; - String export = null; - HttpURLConnection connection = null; - try { - connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - connection.setRequestProperty("Authorization", "Basic " + encodedAuth); - - StringWriter writer = new StringWriter(); - IOUtils.copy(connection.getInputStream(), writer); - export = writer.toString(); - responseCode = connection.getResponseCode(); - } catch (IOException e) { - LOG.error("This should be a temporary exception: ignore", e); - } finally { - if (connection != null) { - connection.disconnect(); - } - } - assertEquals(200, responseCode); - assertNotNull(export); - assertFalse(export.isEmpty()); + private void checkExport(final Long execId, final ReportExecExportFormat fmt) throws IOException { + final Response response = reportService.exportExecutionResult(execId, fmt); + assertNotNull(response); + assertEquals(HttpStatus.OK.value(), response.getStatus()); + assertNotNull(response.getLocation()); + assertNotNull(response.getHeaderString(SyncopeConstants.CONTENT_DISPOSITION_HEADER)); + assertTrue(response.getHeaderString(SyncopeConstants.CONTENT_DISPOSITION_HEADER). + endsWith("." + fmt.name().toLowerCase())); + + Object entity = response.getEntity(); + assertTrue(entity instanceof InputStream); + assertFalse(IOUtils.toString((InputStream) entity, "UTF-8").isEmpty()); } @Test @@ -205,55 +190,14 @@ public class ReportTestITCase extends Ab maxit--; } while (reportTO.getExecutions().isEmpty() && maxit > 0); + assertEquals(1, reportTO.getExecutions().size()); long execId = reportTO.getExecutions().iterator().next().getId(); - // Export - String encodedAuth = Base64.encodeBase64String((ADMIN_UID + ":" + ADMIN_PWD).getBytes()); - URL url = new URL(BASE_URL + "report/execution/export/" + execId); - - // 1. XML - maxit = 30; - int responseCode = 0; - String export = null; - do { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - } - - maxit--; - - HttpURLConnection connection = null; - try { - connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - connection.setRequestProperty("Authorization", "Basic " + encodedAuth); - - StringWriter writer = new StringWriter(); - IOUtils.copy(connection.getInputStream(), writer); - export = writer.toString(); - responseCode = connection.getResponseCode(); - } catch (IOException e) { - LOG.error("This should be a temporary exception: ignore", e); - } finally { - if (connection != null) { - connection.disconnect(); - } - } - } while (responseCode != 200 && maxit > 0); - assertEquals(200, responseCode); - assertNotNull(export); - assertFalse(export.isEmpty()); - - // 2. HTML - checkExport(execId, "HTML", encodedAuth); - - // 3. PDF - checkExport(execId, "PDF", encodedAuth); - - // 4. RTF - checkExport(execId, "RTF", encodedAuth); + checkExport(execId, ReportExecExportFormat.XML); + checkExport(execId, ReportExecExportFormat.HTML); + checkExport(execId, ReportExecExportFormat.PDF); + checkExport(execId, ReportExecExportFormat.RTF); } @Test