Skip to content

Commit a2cbefd

Browse files
committed
Add getters and setters for HangingServiceRequestBase.logAllWireBytes
1 parent 75b5429 commit a2cbefd

2 files changed

Lines changed: 33 additions & 61 deletions

File tree

src/main/java/microsoft/exchange/webservices/data/core/request/HangingServiceRequestBase.java

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@
2828
import microsoft.exchange.webservices.data.core.ExchangeService;
2929
import microsoft.exchange.webservices.data.core.enumeration.misc.HangingRequestDisconnectReason;
3030
import microsoft.exchange.webservices.data.core.enumeration.misc.TraceFlags;
31-
import microsoft.exchange.webservices.data.core.exception.misc.ArgumentException;
3231
import microsoft.exchange.webservices.data.core.exception.http.EWSHttpException;
33-
import microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException;
34-
import microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException;
32+
import microsoft.exchange.webservices.data.core.exception.misc.ArgumentException;
3533
import microsoft.exchange.webservices.data.core.exception.service.local.ServiceVersionException;
3634
import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlDeserializationException;
35+
import microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException;
3736
import microsoft.exchange.webservices.data.core.exception.xml.XmlException;
3837
import microsoft.exchange.webservices.data.misc.HangingTraceStream;
3938
import microsoft.exchange.webservices.data.security.XmlNodeType;
@@ -62,6 +61,7 @@ public abstract class HangingServiceRequestBase<T> extends ServiceRequestBase<T>
6261

6362
private static final Log LOG = LogFactory.getLog(HangingServiceRequestBase.class);
6463

64+
6565
public interface IHandleResponseObject {
6666

6767
/**
@@ -74,13 +74,13 @@ public interface IHandleResponseObject {
7474
}
7575

7676

77-
private static final int BufferSize = 4096;
77+
public static final int BUFFER_SIZE = 4096;
7878

7979
/**
8080
* Test switch to log all bytes that come across the wire.
8181
* Helpful when parsing fails before certain bytes hit the trace logs.
8282
*/
83-
public static boolean logAllWireBytes = false;
83+
private static boolean logAllWireBytes = false;
8484

8585
/**
8686
* Callback delegate to handle response objects
@@ -92,16 +92,6 @@ public interface IHandleResponseObject {
9292
*/
9393
private HttpWebRequest response;
9494

95-
/**
96-
* Request to the server.
97-
*/
98-
private HttpWebRequest request;
99-
100-
/**
101-
* Xml reader used to parse the response.
102-
*/
103-
private EwsServiceMultiResponseXmlReader ewsXmlReader;
104-
10595
/**
10696
* Expected minimum frequency in response, in milliseconds.
10797
*/
@@ -122,6 +112,14 @@ void hangingRequestDisconnectHandler(Object sender,
122112
}
123113

124114

115+
public static boolean isLogAllWireBytes() {
116+
return logAllWireBytes;
117+
}
118+
119+
public static void setLogAllWireBytes(final boolean logAllWireBytes) {
120+
HangingServiceRequestBase.logAllWireBytes = logAllWireBytes;
121+
}
122+
125123
/**
126124
* Disconnect events Occur when the hanging request is disconnected.
127125
*/
@@ -172,7 +170,7 @@ protected HangingServiceRequestBase(ExchangeService service,
172170
/**
173171
* Exectures the request.
174172
*/
175-
public void internalExecute() throws ServiceLocalException, Exception {
173+
public void internalExecute() throws Exception {
176174
synchronized (this) {
177175
this.response = this.validateAndEmitRequest();
178176
this.internalOnConnect();
@@ -200,30 +198,15 @@ private void parseResponses() {
200198
tracingStream.setResponseCopy(responseCopy);
201199
}
202200

203-
//EwsServiceMultiResponseXmlReader ewsXmlReader = EwsServiceMultiResponseXmlReader.create(tracingStream, getService());
204-
205-
206-
207201
while (this.isConnected()) {
208-
T responseObject = null;
202+
T responseObject;
209203
if (traceEWSResponse) {
210-
/*try{*/
211204
EwsServiceMultiResponseXmlReader ewsXmlReader =
212205
EwsServiceMultiResponseXmlReader.create(tracingStream, getService());
213206
responseObject = this.readResponse(ewsXmlReader);
214207
this.responseHandler.handleResponseObject(responseObject);
215-
/* }catch(Exception ex){
216-
this.disconnect(HangingRequestDisconnectReason.Exception, ex);
217-
return;
218-
219-
}
220-
finally{
221-
this.getService().traceXml(TraceFlags.EwsResponse,responseCopy);
222-
if(responseObject!=null)
223-
this.responseHandler.handleResponseObject(responseObject);
224-
}*/
225-
// reset the stream collector.
226208

209+
// reset the stream collector.
227210
responseCopy.close();
228211
responseCopy = new ByteArrayOutputStream();
229212
tracingStream.setResponseCopy(responseCopy);
@@ -238,31 +221,25 @@ private void parseResponses() {
238221
} catch (SocketTimeoutException ex) {
239222
// The connection timed out.
240223
this.disconnect(HangingRequestDisconnectReason.Timeout, ex);
241-
return;
242224
} catch (UnknownServiceException ex) {
243225
// Stream is closed, so disconnect.
244226
this.disconnect(HangingRequestDisconnectReason.Exception, ex);
245-
return;
246227
} catch (ObjectStreamException ex) {
247228
// Stream is closed, so disconnect.
248229
this.disconnect(HangingRequestDisconnectReason.Exception, ex);
249-
return;
250230
} catch (IOException ex) {
251231
// Stream is closed, so disconnect.
252232
this.disconnect(HangingRequestDisconnectReason.Exception, ex);
253-
return;
254233
} catch (UnsupportedOperationException ex) {
255234
LOG.error(ex);
256235
// This is thrown if we close the stream during a
257236
//read operation due to a user method call.
258237
// Trying to delay closing until the read finishes
259238
//simply results in a long-running connection.
260239
this.disconnect(HangingRequestDisconnectReason.UserInitiated, null);
261-
return;
262240
} catch (Exception ex) {
263241
// Stream is closed, so disconnect.
264242
this.disconnect(HangingRequestDisconnectReason.Exception, ex);
265-
return;
266243
} finally {
267244
if (responseCopy != null) {
268245
try {

src/main/java/microsoft/exchange/webservices/data/misc/HangingTraceStream.java

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public class HangingTraceStream extends InputStream {
4343

4444
private static final Log LOG = LogFactory.getLog(HangingTraceStream.class);
4545

46-
private InputStream underlyingStream;
47-
private ExchangeService service;
46+
private final InputStream underlyingStream;
47+
private final ExchangeService service;
4848
private ByteArrayOutputStream responseCopy;
4949

5050
/**
@@ -53,10 +53,9 @@ public class HangingTraceStream extends InputStream {
5353
* @param stream The stream.
5454
* @param service the service.
5555
*/
56-
public HangingTraceStream(InputStream stream, ExchangeService service) {
56+
public HangingTraceStream(final InputStream stream, final ExchangeService service) {
5757
this.underlyingStream = stream;
5858
this.service = service;
59-
6059
}
6160

6261
/**
@@ -114,29 +113,24 @@ public boolean getCanWrite() {
114113
*/
115114
@Override
116115
public int read(byte[] buffer, int offset, int count) throws IOException {
117-
count = 4096;
118-
int retVal = this.underlyingStream.read(buffer, offset, count);
119-
120-
if (HangingServiceRequestBase.logAllWireBytes) {
121-
String readString = new String(buffer, offset, count, "UTF-8");
122-
String logMessage = String.format(
123-
"HangingTraceStream ID [%d] " +
124-
"returned %d bytes. Bytes returned: [%s]",
125-
this.hashCode(),
126-
retVal,
127-
readString);
116+
count = HangingServiceRequestBase.BUFFER_SIZE;
117+
final int retVal = underlyingStream.read(buffer, offset, count);
118+
119+
if (HangingServiceRequestBase.isLogAllWireBytes()) {
120+
final String readString = new String(buffer, offset, count, "UTF-8");
121+
final String logMessage = String.format(
122+
"HangingTraceStream ID [%d] returned %d bytes. Bytes returned: [%s]",
123+
hashCode(), retVal, readString);
128124

129125
try {
130-
this.service.traceMessage(
131-
TraceFlags.DebugMessage,
132-
logMessage);
133-
} catch (XMLStreamException e) {
126+
service.traceMessage(TraceFlags.DebugMessage, logMessage);
127+
} catch (final XMLStreamException e) {
134128
LOG.error(e);
135129
}
136130
}
137131

138-
if (this.responseCopy != null) {
139-
this.responseCopy.write(buffer, offset, retVal);
132+
if (responseCopy != null) {
133+
responseCopy.write(buffer, offset, retVal);
140134
}
141135

142136
return retVal;
@@ -147,13 +141,14 @@ public int read(byte[] buffer, int offset, int count) throws IOException {
147141
*
148142
* @param responseCopy a copy of response
149143
*/
150-
public void setResponseCopy(ByteArrayOutputStream responseCopy) {
144+
public void setResponseCopy(final ByteArrayOutputStream responseCopy) {
151145
this.responseCopy = responseCopy;
152146
}
153147

154148
@Override
155149
public int read() throws IOException {
156150
return 0;
157151
}
152+
158153
}
159154

0 commit comments

Comments
 (0)