CADI.Proxy.Core
Class CachedProxy

java.lang.Object
  extended by CADI.Proxy.Core.CachedProxy

public class CachedProxy
extends java.lang.Object

This class implements a simple transparent proxy. It reads a request sent by a client which is forwarded to the JPIP server waiting for the server response to be forwarded to the client.

Usage example:
  construct
  run

Version:
1.0 2009/08/22
Author:
Group on Interactive Coding of Images (GICI)

Field Summary
private  int cacheDescriptorSubType
           
private  int cacheDescriptorType
           
private  ProxyCacheManagement cacheManagement
           
private  HTTPRequest clientHTTPRequest
          Is the request sent by the client.
private  java.lang.String clientUserAgent
          This attribute is only for debugging and experimental purposes.
private  int EORReasonCode
           
private  java.lang.String EORReasonMessage
           
private  FetchTarget fetchTarget
           
private  HTTPClient httpClient
           
private  HTTPResponse httpResponse
           
private  HTTPResponseSender httpResponseSender
           
private  java.lang.String inCacheText
           
private  JPCParameters jpcParameters
           
private  JPIPMessageEncoder jpipMessageEncoder
           
private  JPIPRequestFields jpipRequestFields
           
private  JPIPResponseFields jpipResponseFields
           
private  ClientSessions listOfClientSessions
          Definition in Scheduler.clientSessions.
private  CADILog log
          It is an object that will be used to log the server process
private  java.lang.String name
          This attribute is only for debugging and experimental purposes.
private  ProxyRequestedWOIs proxyRequestedWOIs
           
private  ViewWindowField responseViewWindow
           
private  java.net.Socket socketToClient
          Contains the client socket of which request is being processed.
private  StopWatch stopWatch
           
 
Constructor Summary
CachedProxy()
          This class' constructor is not allowed.
CachedProxy(ProxyCacheManagement cacheManagement, java.net.Socket socketToClient, HTTPRequest httpRequest, ProxyRequestedWOIs proxyRequestedWOIs, CADILog log)
          Constructor.
 
Method Summary
private  void addMetadaBin0(HTTPResponseSender httpResponseSender, JPIPMessageEncoder jpipMessageEncoder)
          Adds the metadata bin 0 to the response.
private  void addTileHeader(HTTPResponseSender httpResponseSender, JPIPMessageEncoder jpipMessageEncoder)
          Adds the tile-header to the response.
private  void adjustRequestedViewWindow(ViewWindowField adjustedViewWindow)
           
private  void checkJPIPParameters()
          This method tests several JPIP restrictions of the parameters
private  void encodeJPIPResponseFields()
          JPIP HEADERS (See ISO/IEC 15444-9 Annex D)
 java.lang.String getName()
           
private  void logicalTargetsManager(java.lang.String target, java.lang.String tid)
          This method is used to manage the list of loaded targets.
 void run()
          Performs the forwarding of the client request to the server and the forwarding of the server response to the client.
private  void sendData(java.util.ArrayList<SendDataInfo> cacheDescriptor)
           
private  void sendEndOfResponse(HTTPResponseSender httpResponseSender, JPIPMessageEncoder jpipMessageEncoder)
          This method is used to send the End of Response of a JPIP message.
private  void sendHTTPResponseError(int statusCode, java.lang.String reasonPhrase)
          This method will be used to send an HTTP error response to the client.
private  void sendHTTPResponseHeader(HTTPResponse httpResponse)
           
 void sessionsManager()
           
 void setClientUserAgent(java.lang.String clientUserAgent)
           
 void setName(java.lang.String name)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cacheManagement

private ProxyCacheManagement cacheManagement

socketToClient

private java.net.Socket socketToClient
Contains the client socket of which request is being processed.


clientHTTPRequest

private HTTPRequest clientHTTPRequest
Is the request sent by the client.

Definition in HTTPRequest.


proxyRequestedWOIs

private ProxyRequestedWOIs proxyRequestedWOIs

log

private CADILog log
It is an object that will be used to log the server process


listOfClientSessions

private ClientSessions listOfClientSessions
Definition in Scheduler.clientSessions.


name

private java.lang.String name
This attribute is only for debugging and experimental purposes.


jpipRequestFields

private JPIPRequestFields jpipRequestFields

jpcParameters

private JPCParameters jpcParameters

httpResponseSender

private HTTPResponseSender httpResponseSender

jpipMessageEncoder

private JPIPMessageEncoder jpipMessageEncoder

EORReasonCode

private int EORReasonCode

EORReasonMessage

private java.lang.String EORReasonMessage

httpResponse

private HTTPResponse httpResponse

jpipResponseFields

private JPIPResponseFields jpipResponseFields

responseViewWindow

private ViewWindowField responseViewWindow

cacheDescriptorType

private int cacheDescriptorType

cacheDescriptorSubType

private int cacheDescriptorSubType

fetchTarget

private FetchTarget fetchTarget

httpClient

private HTTPClient httpClient

stopWatch

private StopWatch stopWatch

clientUserAgent

private java.lang.String clientUserAgent
This attribute is only for debugging and experimental purposes.


inCacheText

private java.lang.String inCacheText
Constructor Detail

CachedProxy

public CachedProxy()
This class' constructor is not allowed.


CachedProxy

public CachedProxy(ProxyCacheManagement cacheManagement,
                   java.net.Socket socketToClient,
                   HTTPRequest httpRequest,
                   ProxyRequestedWOIs proxyRequestedWOIs,
                   CADILog log)
Constructor.

Parameters:
cacheManagement - definition in cacheManagement.
clientSocket - definition in socketToClient.
httpRequest - definition in #httpRequest.
log - definition in log.
Method Detail

run

public void run()
         throws ErrorException,
                WarningException,
                java.io.IOException
Performs the forwarding of the client request to the server and the forwarding of the server response to the client.

Throws:
java.io.IOException
ErrorException
WarningException

setName

public void setName(java.lang.String name)
Parameters:
name -

getName

public java.lang.String getName()
Returns:

setClientUserAgent

public void setClientUserAgent(java.lang.String clientUserAgent)

sendData

private void sendData(java.util.ArrayList<SendDataInfo> cacheDescriptor)
               throws java.io.IOException
Throws:
java.io.IOException

adjustRequestedViewWindow

private void adjustRequestedViewWindow(ViewWindowField adjustedViewWindow)
Parameters:
viewWindow -

addMetadaBin0

private void addMetadaBin0(HTTPResponseSender httpResponseSender,
                           JPIPMessageEncoder jpipMessageEncoder)
                    throws java.io.IOException
Adds the metadata bin 0 to the response.

It is a temporal method while metadata are not supported.

Throws:
java.io.IOException

addTileHeader

private void addTileHeader(HTTPResponseSender httpResponseSender,
                           JPIPMessageEncoder jpipMessageEncoder)
                    throws java.io.IOException
Adds the tile-header to the response.

It is a temporal method while tiles are not supported.

Throws:
java.io.IOException

sendEndOfResponse

private void sendEndOfResponse(HTTPResponseSender httpResponseSender,
                               JPIPMessageEncoder jpipMessageEncoder)
                        throws java.io.IOException
This method is used to send the End of Response of a JPIP message.

Parameters:
httpResponseSender -
jpipMessageEncoder -
Throws:
java.io.IOException

sendHTTPResponseHeader

private void sendHTTPResponseHeader(HTTPResponse httpResponse)
                             throws WarningException
Parameters:
httpResponse -
Throws:
WarningException

encodeJPIPResponseFields

private void encodeJPIPResponseFields()
JPIP HEADERS (See ISO/IEC 15444-9 Annex D)


checkJPIPParameters

private void checkJPIPParameters()
                          throws WarningException
This method tests several JPIP restrictions of the parameters

Throws:
WarningException

sendHTTPResponseError

private void sendHTTPResponseError(int statusCode,
                                   java.lang.String reasonPhrase)
This method will be used to send an HTTP error response to the client.

Parameters:
statusCode - definition in StatusCodes.
reasonPhrase - a reason phrase related with the status code.

sessionsManager

public void sessionsManager()
                     throws WarningException
Throws:
WarningException

logicalTargetsManager

private void logicalTargetsManager(java.lang.String target,
                                   java.lang.String tid)
                            throws WarningException
This method is used to manage the list of loaded targets. The targed will be passed through the jpip target field, the jpip tid field, or both.

If the requested target has been loaded in a previous request, it will be in the list of loaded targets. So, its parameters will be recovered from that list.

Otherwise, target will be searched in disk. And if it is in disk, it will be loaded to the list.

Parameters:
target - definition in TargetField.target
tid - definition in TargetField.tid
Throws:
WarningException


CADI - Copyright (C) 2007
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Group on Interactive Coding of Images (GICI) (contact)