From f4f7b9d019aa99edcdf9b915be0fa2d7cd085044 Mon Sep 17 00:00:00 2001 From: Erik van Paassen Date: Tue, 2 Sep 2014 17:46:09 +0200 Subject: [PATCH 1/2] Remove unused methods from ServiceRequestBase. - ServiceRequestBase.emit() is unused. - ServiceRequestBase.endGetEwsHttpWebResponse() is unused, but also incorrect: Why would one compare an HTTP status code with an enum ordinal?! --- .../webservices/data/ServiceRequestBase.java | 109 ------------------ 1 file changed, 109 deletions(-) diff --git a/src/main/java/microsoft/exchange/webservices/data/ServiceRequestBase.java b/src/main/java/microsoft/exchange/webservices/data/ServiceRequestBase.java index 07568653b..663be3cea 100644 --- a/src/main/java/microsoft/exchange/webservices/data/ServiceRequestBase.java +++ b/src/main/java/microsoft/exchange/webservices/data/ServiceRequestBase.java @@ -316,69 +316,6 @@ private String getRequestedServiceVersionString() { } } - /** - * Send request and get response. - * - * @return HttpWebRequest object from which response stream can be read. - * @throws Exception - * the exception - */ - protected HttpWebRequest emit(OutParam request) - throws Exception { - request.setParam(this.getService().prepareHttpWebRequest()); - this.getService().traceHttpRequestHeaders( - TraceFlags.EwsRequestHttpHeaders, request.getParam()); - - // If tracing is enabled, we generate the request in-memory so that we - // can pass it along to the ITraceListener. Then we copy the stream to - // the request stream. - if (this.service.isTraceEnabledFor(TraceFlags.EwsRequest)) { - ByteArrayOutputStream memoryStream = new ByteArrayOutputStream(); - EwsServiceXmlWriter writer = new EwsServiceXmlWriter(this.service, - memoryStream); - this.writeToXml(writer); - this.service.traceXml(TraceFlags.EwsRequest, memoryStream); - OutputStream urlOutStream = request.getParam().getOutputStream(); - // request.getParam().write(memoryStream); - // System.out.println("Actual XML : "+new - // String(memoryStream.toByteArray())+": end of XML"); - - memoryStream.writeTo(urlOutStream); - urlOutStream.flush(); - urlOutStream.close(); - writer.dispose(); - memoryStream.close(); - } else { - // ByteArrayOutputStream bos = new ByteArrayOutputStream(); - // ObjectOutputStream urlOutStream = new ObjectOutputStream(bos); - OutputStream urlOutStream = request.getParam().getOutputStream(); - EwsServiceXmlWriter writer = new EwsServiceXmlWriter(this.service, - urlOutStream); - this.writeToXml(writer); - // request.getParam().write(bos); - urlOutStream.flush(); - urlOutStream.close(); - writer.dispose(); - } - // Closing and flushing stream does not ensure xml data is posted. Hence - // try to get response code. This will force the xml data to be posted. - request.getParam().executeRequest(); - - if (request.getParam().getResponseCode() >= 400) { - throw new HttpErrorException( - "The remote server returned an error: (" - + request.getParam().getResponseCode() + ")" - + request.getParam().getResponseText(), request - .getParam().getResponseCode()); - // throw new - // Exception("The remote server returned an error: ("+request.getParam().getResponseCode()+")"+request.getParam().getResponseText()); - - } - - return request.getParam(); - - } - /** * Get the request stream * @@ -578,52 +515,6 @@ private void readSoapHeader(EwsServiceXmlReader reader) throws Exception { XmlElementNames.SOAPHeaderElementName)); } - /** - * Ends getting the specified async HttpWebRequest object from the specified - * IEwsHttpWebRequest object with exception handling. - * - * @param request - * The specified HttpWebRequest - * @param asyncResult - * An IAsyncResult that references the asynchronous request. - * @return An HttpWebResponse instance - */ - protected HttpWebRequest endGetEwsHttpWebResponse( - OutParam request, AsyncRequestResult asyncResult) - throws Exception { - - try { - // Note that this call may throw ArgumentException if the - // HttpWebRequest instance is not the original one, - // and we just let it out - request.getParam().executeRequest(); - if (request.getParam().getResponseCode() >= 400) { - throw new HttpErrorException( - "The remote server returned an error: (" - + request.getParam().getResponseCode() + ")" - + request.getParam().getResponseText(), request - .getParam().getResponseCode()); - // throw new - // Exception("The remote server returned an error: ("+request.getParam().getResponseCode()+")"+request.getParam().getResponseText()); - - } - return request.getParam(); - } catch (HttpErrorException ex) { - if (ex.getHttpErrorCode() == WebExceptionStatus.ProtocolError - .ordinal()) { - this.processWebException(ex, request.getParam()); - } - - // Wrap exception if the above code block didn't throw - throw new ServiceRequestException(String.format( - Strings.ServiceRequestFailed, ex.getMessage()), ex); - } catch (IOException e) { - // Wrap exception. - throw new ServiceRequestException(String.format( - Strings.ServiceRequestFailed, e.getMessage()), e); - } - } - /** * Processes the web exception. * From 1df5c0161582098941f423b659e0fdcce2dd170f Mon Sep 17 00:00:00 2001 From: Erik van Paassen Date: Wed, 3 Sep 2014 11:07:34 +0200 Subject: [PATCH 2/2] Remove commented call to ServiceRequestBase.endGetEwsHttpWebResponse(). Also removed a getter call without assignment and some other commented code in SimpleServiceRequestBase that made no sense. --- .../data/SimpleServiceRequestBase.java | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/main/java/microsoft/exchange/webservices/data/SimpleServiceRequestBase.java b/src/main/java/microsoft/exchange/webservices/data/SimpleServiceRequestBase.java index fa8394be4..8e46aa8a7 100644 --- a/src/main/java/microsoft/exchange/webservices/data/SimpleServiceRequestBase.java +++ b/src/main/java/microsoft/exchange/webservices/data/SimpleServiceRequestBase.java @@ -72,29 +72,17 @@ protected Object internalExecute() } } - - /** - * Ends executing this async request. - * - * @param asyncResult The async result - * @return Service response object. - */ - protected Object endInternalExecute(IAsyncResult asyncResult)throws Exception - { - // We have done enough validation before - // AsyncRequestResult asyncRequestResult = - // (AsyncRequestResult)asyncResult; - /* - * HttpWebRequest request =((AsyncRequestResult) - * asyncResult).getHttpWebRequest(); OutParam outparam = - * new OutParam(); outparam.setParam(request); - */ - FutureTask task = ((AsyncRequestResult) asyncResult).getTask(); - // HttpWebRequest response = this.endGetEwsHttpWebResponse(outparam, - // (AsyncRequestResult) asyncRequestResult.getWebAsyncResult());*/ + + /** + * Ends executing this async request. + * + * @param asyncResult The async result + * @return Service response object. + */ + protected Object endInternalExecute(IAsyncResult asyncResult) throws Exception { HttpWebRequest response = (HttpWebRequest) asyncResult.get(); return this.readResponse(response); - } + } /** * Begins executing this async request.