public class RecordingResponse extends Object implements Response
Response
that simply records the
values it receives, and implements the interface semantics of the
methods that must be called last. This implementation is not
thread-safe.
Methods that return collections all return unmodifiable views of
the recorded values. The collections cannot be changed directly,
but they will reflect changes to the recorded values that are made
through the Response
interface.
Modifier and Type | Class and Description |
---|---|
static class |
RecordingResponse.AnchorMap
An unmodifiable view of the accumulated anchors as a multimap
that supports duplicate, ordered key-value pairs.
|
static class |
RecordingResponse.State
Response states based on calls to the
respondXXX and
getOutputStream methods. |
Constructor and Description |
---|
RecordingResponse()
Constructs a mock
Response with a ByteArrayOutputStream . |
RecordingResponse(OutputStream os)
Constructs a mock
Response with the given OutputStream . |
Modifier and Type | Method and Description |
---|---|
void |
addAnchor(URI uri,
String text)
Add a hyperlink for the GSA to follow without modifying the document
contents.
|
void |
addMetadata(String key,
String value)
Add metadata element that applies to the document.
|
Acl |
getAcl() |
RecordingResponse.AnchorMap |
getAnchors()
Gets an unmodifiable view of the accumulated anchors as a multimap.
|
String |
getContentType() |
URI |
getDisplayUrl() |
MetadataTransform.TransmissionDecision |
getForcedTransmissionDecision() |
Date |
getLastModified() |
Metadata |
getMetadata()
Gets an unmodifiable view of the accumulated
Metadata . |
Map<String,Acl> |
getNamedResources()
Gets an unmodifiable view of the named resources as a
Map
from URI fragments to ACLs. |
OutputStream |
getOutputStream()
Get stream to write document contents to.
|
Map<String,String> |
getParams()
Gets an unmodifiable view of the accumulated params as a
Map . |
RecordingResponse.State |
getState() |
boolean |
isCrawlOnce() |
boolean |
isLock() |
boolean |
isNoArchive() |
boolean |
isNoFollow() |
boolean |
isNoIndex() |
boolean |
isSecure() |
void |
putNamedResource(String fragment,
Acl acl)
Provide alternative ACLs for this document, uniquely identified by
response document's
DocId and fragment . |
void |
respondNoContent()
Respond to the GSA that it already has the latest content
of a file but not necessarily the latest ACLs or metadata;
Respond to non GSA client that it already has the latest version
of a file.
|
void |
respondNotFound()
Respond to the GSA or other client that the request document does not
exist.
|
void |
respondNotModified()
Respond to the GSA or other client that it already has the latest version
of a file and its metadata.
|
void |
setAcl(Acl acl)
Provide the document's ACLs for early-binding security on the GSA.
|
void |
setContentType(String contentType)
Describe the content type of the document.
|
void |
setCrawlOnce(boolean crawlOnce)
Instruct the GSA to not recrawl the document after the initial
retrieval.
|
void |
setDisplayUrl(URI displayUrl)
Set the URI to be displayed in search results.
|
void |
setForcedTransmissionDecision(MetadataTransform.TransmissionDecision decision)
Set a forced
MetadataTransform.TransmissionDecision that can override transmission
decisions made by MetadataTransforms . |
void |
setLastModified(Date lastModified)
Provide the last modification time of the document.
|
void |
setLock(boolean lock)
Instruct the GSA to "lock" the document into its index.
|
void |
setNoArchive(boolean noArchive)
Whether the GSA should show the "Cached" link in search results for this
document.
|
void |
setNoFollow(boolean noFollow)
Whether the GSA should follow the links within the document to find other
documents.
|
void |
setNoIndex(boolean noIndex)
Whether the GSA should index the content for searching.
|
void |
setParam(String key,
String value)
Adds a parameter to a Map for use by
MetadataTransforms when making
transforms or decisions. |
void |
setSecure(boolean secure)
Mark the document as secure, for use with late-binding security.
|
public RecordingResponse()
Response
with a ByteArrayOutputStream
.public RecordingResponse(OutputStream os)
Response
with the given OutputStream
.os
- the output stream that will be returned from
getOutputStream()
public void respondNotModified() throws IOException
Response
If called, this must be the last call to this interface. Once you call this method, for the rest of the processing, exceptions may no longer be communicated to clients cleanly.
respondNotModified
in interface Response
IOException
- if communicating with client failspublic void respondNotFound() throws IOException
Response
If called, this must be the last call to this interface. Once you call this method, for the rest of the processing, exceptions may no longer be communicated to the clients cleanly.
respondNotFound
in interface Response
IOException
- if communicating with client failspublic void respondNoContent() throws IOException
Response
If called, this must be the last call to this interface. Once you call this method, for the rest of the processing, exceptions may no longer be communicated to the clients cleanly.
respondNoContent
in interface Response
IOException
- if communicating with client failspublic OutputStream getOutputStream()
Response
OutputStream
when done.
If called, this must be the last call to this interface (although, for convenience, you may call this method multiple times). Once you call this method, for the rest of the processing, exceptions may no longer be communicated to clients cleanly.
getOutputStream
in interface Response
public void setContentType(String contentType)
Response
setContentType
in interface Response
contentType
- to set in response headerspublic void setLastModified(Date lastModified)
Response
setLastModified
in interface Response
lastModified
- to send in response headerspublic void addMetadata(String key, String value)
Response
addMetadata
in interface Response
key
- the key of metadata elementvalue
- the value of metadata elementpublic void setAcl(Acl acl)
Response
null
, which means the document
is public if the document isn't marked as secure via Response.setSecure(boolean)
.public void putNamedResource(String fragment, Acl acl)
Response
DocId
and fragment
.putNamedResource
in interface Response
fragment
- disambiguating name when document has multiple ACLsacl
- access controls for document being sentpublic void setSecure(boolean secure)
Response
false
, which means the document
is public if there are no ACLs. ACLs should be used, if possible, instead
of setting this option to true
. When true
, the GSA needs to
be correctly configured to issue a SAML request to the Adaptor.
Setting ACLs to non-null will override setSecure and send secure indicator
to GSA.public void addAnchor(URI uri, String text)
Response
<a href='$uri'>$text</a>
. If you want to link to a DocId
, then you
may use the DocIdEncoder
provided by AdaptorContext.getDocIdEncoder()
to produce an appropriate URI.public void setNoIndex(boolean noIndex)
Response
true
,
the document will not be visible in search results. This does not change
the GSA's behavior of following links within the document to find other
documents. By default, the GSA will index the document (a value of false
).setNoIndex
in interface Response
noIndex
- true
when the GSA shouldn't index this documentpublic void setNoFollow(boolean noFollow)
Response
false
).setNoFollow
in interface Response
noFollow
- true
when the GSA shouldn't follow links from this
document to find other documentspublic void setNoArchive(boolean noArchive)
Response
false
).setNoArchive
in interface Response
noArchive
- true
when the GSA shouldn't show the "Cached"
link in search resultspublic void setDisplayUrl(URI displayUrl)
Response
null
, then the
crawl URI representing the DocId
is used. The default is null
.setDisplayUrl
in interface Response
displayUrl
- URI to be used for this document in search resultspublic void setCrawlOnce(boolean crawlOnce)
Response
false
.setCrawlOnce
in interface Response
crawlOnce
- if true
, the document does not need to be
recrawled periodicallypublic void setLock(boolean lock)
Response
false
.public void setForcedTransmissionDecision(MetadataTransform.TransmissionDecision decision)
Response
MetadataTransform.TransmissionDecision
that can override transmission
decisions made by MetadataTransforms
.
Some connectors send content that must be preserved in order for the connector to function properly, and transforms that decide to drop that content essentially break the connector. For instance, dropping folders disrupts graph traverser type connectors.
setForcedTransmissionDecision
in interface Response
decision
- a
TransmissionDecision
public void setParam(String key, String value)
Response
MetadataTransforms
when making
transforms or decisions. Params are data associated with the document,
but might not be indexed and searchable. Before the metadata transforms are
called, the params
are seeded with the document's DocId
,
and values from setLock
, setCrawlOnce
,
setDisplayUrl
, setContentType
, and setLastModified
.
To avoid possible name conflicts with parameter entries supplied by the
library, the key of a connector-supplied parameter must start with
X-
.
Example:
response.setParam("X-LastAccessDate", ISO8601.format(lastAccessDate));
public RecordingResponse.State getState()
public String getContentType()
public Date getLastModified()
public Metadata getMetadata()
Metadata
.Metadata
public Acl getAcl()
public Map<String,Acl> getNamedResources()
Map
from URI fragments to ACLs.public boolean isSecure()
public RecordingResponse.AnchorMap getAnchors()
public boolean isNoIndex()
public boolean isNoFollow()
public boolean isNoArchive()
public URI getDisplayUrl()
public boolean isCrawlOnce()
public boolean isLock()
public MetadataTransform.TransmissionDecision getForcedTransmissionDecision()