org.apache.manifoldcf.agents.output.solr
Class HttpPoster

java.lang.Object
  extended by org.apache.manifoldcf.agents.output.solr.HttpPoster

public class HttpPoster
extends java.lang.Object

Posts an input stream to SOLR

Author:
James Sablatura, modified by Karl Wright

Nested Class Summary
protected static class HttpPoster.ByteBuffer
          Byte buffer class
protected static class HttpPoster.CodeDetails
          Code+details paper object
protected  class HttpPoster.CommitThread
          Killable thread that does a commit.
protected  class HttpPoster.DeleteThread
          Killable thread that does deletions.
protected  class HttpPoster.IngestThread
          Killable thread that does ingestions.
protected static class HttpPoster.LaxTrustManager
          Our own trust manager, which ignores certificate issues
protected  class HttpPoster.StatusThread
          Killable thread that does a status check.
 
Field Summary
static java.lang.String _rcsid
           
protected static byte[] endBytes
           
protected static int HEADER_CHUNK
           
static java.lang.String ingestBufferSizeProperty
          Ingestion buffer size property.
static java.lang.String ingestCredentialsRealm
           
static java.lang.String ingestMaxConnectionsProperty
           
static java.lang.String ingestPasswordProperty
           
static java.lang.String ingestRescheduleInterval
           
static java.lang.String ingestResponseRetryCount
           
static java.lang.String ingestResponseRetryInterval
           
static java.lang.String ingestURIProperty
           
static java.lang.String ingestUserProperty
           
protected static javax.net.ssl.SSLSocketFactory openSecureSocketFactory
          This is the secure socket factory we will use.
protected static byte[] postambleBytes
           
protected static byte[] preambleBytes
           
protected static byte[] separatorBytes
          The multipart separator we're going to use.
 
Constructor Summary
HttpPoster(java.lang.String protocol, java.lang.String server, int port, java.lang.String webappName, java.lang.String updatePath, java.lang.String removePath, java.lang.String statusPath, java.lang.String realm, java.lang.String userID, java.lang.String password, java.lang.String allowAttributeName, java.lang.String denyAttributeName, java.lang.String idAttributeName, org.apache.manifoldcf.core.interfaces.IKeystoreManager keystoreManager)
          Initialized the http poster.
 
Method Summary
 void checkPost()
          Post a check request.
 void commitPost()
          Cause a commit to happen.
protected static java.lang.String[] convertACL(java.lang.String[] acl, java.lang.String authorityNameString, org.apache.manifoldcf.agents.interfaces.IOutputAddActivity activities)
          Convert an unqualified ACL to qualified form.
protected  java.net.Socket createSocket(long responseRetryCount)
          Create a socket in a manner consistent with all of our specified parameters.
 void deletePost(java.lang.String documentURI, org.apache.manifoldcf.agents.interfaces.IOutputRemoveActivity activities)
          Post a delete request.
protected static javax.net.ssl.SSLSocketFactory getOpenSecureSocketFactory()
          Build a secure socket factory based on no keystore and a lax trust manager.
protected  HttpPoster.CodeDetails getResponse(java.io.InputStream in)
          Get the response code of the post
 boolean indexPost(java.lang.String documentURI, org.apache.manifoldcf.agents.interfaces.RepositoryDocument document, java.util.Map arguments, java.util.Map sourceTargets, java.lang.String authorityNameString, org.apache.manifoldcf.agents.interfaces.IOutputAddActivity activities)
          Post the input stream to ingest
protected  int lengthACLs(java.lang.String aclType, java.lang.String[] acl, java.lang.String[] denyAcl)
          Count the size of an acl level
protected static int lengthBoundary(java.lang.String contentType, java.lang.String name, java.lang.String fileName)
          Calculate the length of a boundary
protected static int lengthField(java.lang.String fieldName, java.lang.String fieldValue)
          Calculate the length of a field
protected static int lengthPostamble()
          Calculate the length of the postamble
protected static int lengthPreamble()
          Calculate the length of the preamble
protected static byte[] readInputStream(java.io.InputStream is)
          Read input stream into an in-memory array
protected static java.lang.String readLine(java.io.InputStream in)
          Read an ascii line from an input stream
protected  void writeACLs(java.io.OutputStream out, java.lang.String aclType, java.lang.String[] acl, java.lang.String[] denyAcl)
          Output an acl level
protected static void writeBoundary(java.io.OutputStream out, java.lang.String contentType, java.lang.String name, java.lang.String fileName)
          Write a boundary
protected  void writeCredentials(java.io.OutputStream out)
          Write credentials to output
protected static void writeField(java.io.OutputStream out, java.lang.String fieldName, java.lang.String fieldValue)
          Write a field
protected static void writePostamble(java.io.OutputStream out)
          Write the postamble
protected static void writePreamble(java.io.OutputStream out)
          Write the preamble
protected static java.lang.String xmlEncode(java.lang.String input)
          XML encoding
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_rcsid

public static final java.lang.String _rcsid
See Also:
Constant Field Values

ingestBufferSizeProperty

public static java.lang.String ingestBufferSizeProperty
Ingestion buffer size property.


ingestCredentialsRealm

public static java.lang.String ingestCredentialsRealm

ingestResponseRetryCount

public static java.lang.String ingestResponseRetryCount

ingestResponseRetryInterval

public static java.lang.String ingestResponseRetryInterval

ingestRescheduleInterval

public static java.lang.String ingestRescheduleInterval

ingestURIProperty

public static java.lang.String ingestURIProperty

ingestUserProperty

public static java.lang.String ingestUserProperty

ingestPasswordProperty

public static java.lang.String ingestPasswordProperty

ingestMaxConnectionsProperty

public static java.lang.String ingestMaxConnectionsProperty

HEADER_CHUNK

protected static final int HEADER_CHUNK
See Also:
Constant Field Values

separatorBytes

protected static byte[] separatorBytes
The multipart separator we're going to use. I was thinking of including a random number, but that would wreck repeatability


endBytes

protected static byte[] endBytes

postambleBytes

protected static byte[] postambleBytes

preambleBytes

protected static byte[] preambleBytes

openSecureSocketFactory

protected static javax.net.ssl.SSLSocketFactory openSecureSocketFactory
This is the secure socket factory we will use. I'm presuming it's thread-safe, but if not, synchronization blocks are in order when it's used.

Constructor Detail

HttpPoster

public HttpPoster(java.lang.String protocol,
                  java.lang.String server,
                  int port,
                  java.lang.String webappName,
                  java.lang.String updatePath,
                  java.lang.String removePath,
                  java.lang.String statusPath,
                  java.lang.String realm,
                  java.lang.String userID,
                  java.lang.String password,
                  java.lang.String allowAttributeName,
                  java.lang.String denyAttributeName,
                  java.lang.String idAttributeName,
                  org.apache.manifoldcf.core.interfaces.IKeystoreManager keystoreManager)
           throws org.apache.manifoldcf.core.interfaces.ManifoldCFException
Initialized the http poster.

Parameters:
userID - is the unencoded user name, or null.
password - is the unencoded password, or null.
Throws:
org.apache.manifoldcf.core.interfaces.ManifoldCFException
Method Detail

commitPost

public void commitPost()
                throws org.apache.manifoldcf.core.interfaces.ManifoldCFException,
                       org.apache.manifoldcf.agents.interfaces.ServiceInterruption
Cause a commit to happen.

Throws:
org.apache.manifoldcf.core.interfaces.ManifoldCFException
org.apache.manifoldcf.agents.interfaces.ServiceInterruption

indexPost

public boolean indexPost(java.lang.String documentURI,
                         org.apache.manifoldcf.agents.interfaces.RepositoryDocument document,
                         java.util.Map arguments,
                         java.util.Map sourceTargets,
                         java.lang.String authorityNameString,
                         org.apache.manifoldcf.agents.interfaces.IOutputAddActivity activities)
                  throws org.apache.manifoldcf.core.interfaces.ManifoldCFException,
                         org.apache.manifoldcf.agents.interfaces.ServiceInterruption
Post the input stream to ingest

Parameters:
documentURI - is the document's uri.
document - is the document structure to ingest.
arguments - are the configuration arguments to pass in the post. Key is argument name, value is a list of the argument values.
authorityNameString - is the name of the governing authority for this document's acls, or null if none.
activities - is the activities object, so we can report what's happening.
Returns:
true if the ingestion was successful, or false if the ingestion is illegal.
Throws:
ManifoldCFException, - ServiceInterruption
org.apache.manifoldcf.core.interfaces.ManifoldCFException
org.apache.manifoldcf.agents.interfaces.ServiceInterruption

checkPost

public void checkPost()
               throws org.apache.manifoldcf.core.interfaces.ManifoldCFException,
                      org.apache.manifoldcf.agents.interfaces.ServiceInterruption
Post a check request.

Throws:
org.apache.manifoldcf.core.interfaces.ManifoldCFException
org.apache.manifoldcf.agents.interfaces.ServiceInterruption

deletePost

public void deletePost(java.lang.String documentURI,
                       org.apache.manifoldcf.agents.interfaces.IOutputRemoveActivity activities)
                throws org.apache.manifoldcf.core.interfaces.ManifoldCFException,
                       org.apache.manifoldcf.agents.interfaces.ServiceInterruption
Post a delete request.

Parameters:
documentURI - is the document's URI.
Throws:
org.apache.manifoldcf.core.interfaces.ManifoldCFException
org.apache.manifoldcf.agents.interfaces.ServiceInterruption

convertACL

protected static java.lang.String[] convertACL(java.lang.String[] acl,
                                               java.lang.String authorityNameString,
                                               org.apache.manifoldcf.agents.interfaces.IOutputAddActivity activities)
                                        throws org.apache.manifoldcf.core.interfaces.ManifoldCFException
Convert an unqualified ACL to qualified form.

Parameters:
acl - is the initial, unqualified ACL.
authorityNameString - is the name of the governing authority for this document's acls, or null if none.
activities - is the activities object, so we can report what's happening.
Returns:
the modified ACL.
Throws:
org.apache.manifoldcf.core.interfaces.ManifoldCFException

readLine

protected static java.lang.String readLine(java.io.InputStream in)
                                    throws java.io.IOException
Read an ascii line from an input stream

Throws:
java.io.IOException

getResponse

protected HttpPoster.CodeDetails getResponse(java.io.InputStream in)
                                      throws org.apache.manifoldcf.core.interfaces.ManifoldCFException,
                                             org.apache.manifoldcf.agents.interfaces.ServiceInterruption
Get the response code of the post

Parameters:
in - the stream the response is going to come from
Returns:
the response details.
Throws:
org.apache.manifoldcf.core.interfaces.ManifoldCFException
org.apache.manifoldcf.agents.interfaces.ServiceInterruption

readInputStream

protected static byte[] readInputStream(java.io.InputStream is)
                                 throws java.io.IOException
Read input stream into an in-memory array

Throws:
java.io.IOException

writeCredentials

protected void writeCredentials(java.io.OutputStream out)
                         throws java.io.IOException
Write credentials to output

Throws:
java.io.IOException

getOpenSecureSocketFactory

protected static javax.net.ssl.SSLSocketFactory getOpenSecureSocketFactory()
                                                                    throws org.apache.manifoldcf.core.interfaces.ManifoldCFException
Build a secure socket factory based on no keystore and a lax trust manager. This allows use of SSL for privacy but not identification.

Throws:
org.apache.manifoldcf.core.interfaces.ManifoldCFException

createSocket

protected java.net.Socket createSocket(long responseRetryCount)
                                throws java.io.IOException,
                                       org.apache.manifoldcf.core.interfaces.ManifoldCFException
Create a socket in a manner consistent with all of our specified parameters.

Throws:
java.io.IOException
org.apache.manifoldcf.core.interfaces.ManifoldCFException

lengthPreamble

protected static int lengthPreamble()
                             throws java.io.IOException
Calculate the length of the preamble

Throws:
java.io.IOException

lengthBoundary

protected static int lengthBoundary(java.lang.String contentType,
                                    java.lang.String name,
                                    java.lang.String fileName)
                             throws java.io.IOException
Calculate the length of a boundary

Throws:
java.io.IOException

lengthPostamble

protected static int lengthPostamble()
                              throws java.io.IOException
Calculate the length of the postamble

Throws:
java.io.IOException

lengthField

protected static int lengthField(java.lang.String fieldName,
                                 java.lang.String fieldValue)
                          throws java.io.IOException
Calculate the length of a field

Throws:
java.io.IOException

lengthACLs

protected int lengthACLs(java.lang.String aclType,
                         java.lang.String[] acl,
                         java.lang.String[] denyAcl)
                  throws java.io.IOException
Count the size of an acl level

Throws:
java.io.IOException

writePreamble

protected static void writePreamble(java.io.OutputStream out)
                             throws java.io.IOException
Write the preamble

Throws:
java.io.IOException

writeBoundary

protected static void writeBoundary(java.io.OutputStream out,
                                    java.lang.String contentType,
                                    java.lang.String name,
                                    java.lang.String fileName)
                             throws java.io.IOException
Write a boundary

Throws:
java.io.IOException

writePostamble

protected static void writePostamble(java.io.OutputStream out)
                              throws java.io.IOException
Write the postamble

Throws:
java.io.IOException

writeField

protected static void writeField(java.io.OutputStream out,
                                 java.lang.String fieldName,
                                 java.lang.String fieldValue)
                          throws java.io.IOException
Write a field

Throws:
java.io.IOException

writeACLs

protected void writeACLs(java.io.OutputStream out,
                         java.lang.String aclType,
                         java.lang.String[] acl,
                         java.lang.String[] denyAcl)
                  throws java.io.IOException
Output an acl level

Throws:
java.io.IOException

xmlEncode

protected static java.lang.String xmlEncode(java.lang.String input)
XML encoding