Project Report: fawkez

Packagesummary org.jcoderz.commons.connector.http

org.jcoderz.commons.connector.http.HttpConnectorSessionImpl

LineHitsNoteSource
1  /*
2   * $Id: HttpConnectorSessionImpl.java 1011 2008-06-16 17:57:36Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.commons.connector.http;
34  
35  import java.rmi.RemoteException;
36  import javax.resource.ResourceException;
37  import org.jcoderz.commons.connector.ConnectorException;
38  import org.jcoderz.commons.connector.http.transport.ConnectorContext;
39  import org.jcoderz.commons.connector.http.transport.HttpConnectorEventListener;
40  import org.jcoderz.commons.connector.http.transport.HttpRequestResponseHeader;
41  import org.jcoderz.commons.types.Url;
42  
43  
44  
45  /**
46   * Session bean using the http connector.
47   *
48   */
490(1)public class HttpConnectorSessionImpl
50        implements HttpConnectorSessionInterface,
51                   HttpConnectorEventListener
52  {
530    private long mSendTime = 0;
540    private long mReceivedTime = 0;
550    private int mTryCounter = 1;
56  
57     /** {@inheritDoc} */
58     public ConnectorResponse sendAndReceive (
59           byte[] request, Url target,
60           HttpRequestResponseHeader header)
61 (2)         throws RemoteException, ResourceException, ConnectorException
62     {
630       reset();
640       final HttpConnectionSpec spec = new HttpConnectionSpec(this, target);
650       final HttpConnection connection
66              = HttpConnectionUtil.getHttpConnection(spec);
670       connection.setEventListener(
680(3)(4)            ((HttpConnectorEventListener) this), new ConnectorContext() { });
690       connection.setRequestResponseHeader(header);
70        final byte[] response;
71        try
72        {
730          response = connection.sendAndReceive(
74              "this is a message".getBytes());
75        }
760       catch (ConnectorException cex)
77        {
780          cex.log();
790          throw cex;
800       }
810       connection.close();
820       return new ConnectorResponse(
83              calculatedRequestTime(), mTryCounter, response);
84     }
85  
86     /** {@inheritDoc} */
87     public void requestSend (ConnectorContext context)
88     {
890       if (mSendTime > 0)
90        {
910          mTryCounter++;
92        }
930       mSendTime = System.currentTimeMillis();
940    }
95  
96     /** {@inheritDoc} */
97     public void responseReceived (
98           int resultCode, byte[] response, ConnectorContext context)
99     {
1000       mReceivedTime = System.currentTimeMillis();
1010    }
102  
103     private long calculatedRequestTime ()
104     {
105        long result;
1060       if (mReceivedTime == 0)
107        {
1080          result = -1;
109        }
1100       else if (mReceivedTime <= mSendTime)
111        {
1120          result = 0;
113        }
114        else
115        {
1160          result = mReceivedTime - mSendTime;
117        }
1180       return result;
119     }
120  
121     private void reset ()
122     {
1230       mSendTime = 0;
1240       mReceivedTime = 0;
1250       mTryCounter = 1;
1260    }
127  
128     /** {@inheritDoc} */
129     public void requestSendWithRetry (ConnectorContext context)
130     {
131        // nop
1320    }
133  
134     /** {@inheritDoc} */
135     public void responseReceivedAfterRetry (int numberOfRetries,
136             byte[] responseData, ConnectorContext context)
137     {
138        // nop
1390    }
140  }

Findings in this File

c (1) 49 : 0 Type Javadoc comment is missing an @author tag.
c (2) 61 : 34 Unable to get class information for ResourceException.
i (3) 68 : 0 org.jcoderz.commons.connector.http.HttpConnectorSessionImpl$1 is serializable but also an inner class of a non-serializable class (test code) Decreased severity from 'warning' for testcode.
i (4) 68 : 0 The class org.jcoderz.commons.connector.http.HttpConnectorSessionImpl$1 could be refactored into a named _static_ inner class (test code)