Chapter 52. Box Component


Available as of Camel version 2.14

The Box component provides access to all of the Box.com APIs accessible using https://github.com/box/box-java-sdk. It allows producing messages to upload and download files, create, edit, and manage folders, etc. It also supports APIs that allow polling for updates to user accounts and even changes to enterprise accounts, etc.

Box.com requires the use of OAuth2.0 for all client application authentication. In order to use camel-box with your account, you’ll need to create a new application within Box.com at https://developer.box.com. The Box application’s client id and secret will allow access to Box APIs which require a current user. A user access token is generated and managed by the API for an end user.

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-box</artifactId>
    <version>${camel-version}</version>
</dependency>

52.1. Connection Authentication Types

The Box component supports three different types of authenticated connections.

52.1.1. Standard Authentication

Standard Authentication uses the OAuth 2.0 three-legged authentication process to authenticate its connections with Box.com. This type of authentication enables Box managed users and external users to access, edit, and save their Box content through the Box component.

52.1.2. App Enterprise Authentication

App Enterprise Authentication uses the OAuth 2.0 with JSON Web Tokens (JWT) to authenticate its connections as a Service Account for a Box Application. This type of authentication enables a service account to access, edit, and save the Box content of its Box Application through the Box component.

52.1.3. App User Authentication

App User Authentication uses the OAuth 2.0 with JSON Web Tokens (JWT) to authenticate its connections as an App User for a Box Application. This type of authentication enables app users to access, edit, and save their Box content in its Box Application through the Box component.

52.2. Box Options

The Box component supports 2 options which are listed below.

NameDescriptionDefaultType

configuration (common)

To use the shared configuration

 

BoxConfiguration

resolveProperty Placeholders (advanced)

Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders.

true

boolean

The Box endpoint is configured using URI syntax:

box:apiName/methodName

with the following path and query parameters:

52.2.1. Path Parameters (2 parameters):

NameDescriptionDefaultType

apiName

Required What kind of operation to perform

 

BoxApiName

methodName

Required What sub operation to use for the selected operation

 

String

52.2.2. Query Parameters (20 parameters):

NameDescriptionDefaultType

clientId (common)

Box application client ID

 

String

enterpriseId (common)

The enterprise ID to use for an App Enterprise.

 

String

inBody (common)

Sets the name of a parameter to be passed in the exchange In Body

 

String

userId (common)

The user ID to use for an App User.

 

String

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

exceptionHandler (consumer)

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer)

Sets the exchange pattern when the consumer creates an exchange.

 

ExchangePattern

httpParams (advanced)

Custom HTTP params for settings like proxy host

 

Map

synchronous (advanced)

Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported).

false

boolean

accessTokenCache (security)

Custom Access Token Cache for storing and retrieving access tokens.

 

IAccessTokenCache

clientSecret (security)

Box application client secret

 

String

encryptionAlgorithm (security)

The type of encryption algorithm for JWT. Supported Algorithms: RSA_SHA_256 RSA_SHA_384 RSA_SHA_512

RSA_SHA_256

EncryptionAlgorithm

maxCacheEntries (security)

The maximum number of access tokens in cache.

100

int

authenticationType (authentication)

The type of authentication for connection. Types of Authentication: STANDARD_AUTHENTICATION - OAuth 2.0 (3-legged) SERVER_AUTHENTICATION - OAuth 2.0 with JSON Web Tokens

APP_USER_AUTHENTICATION

String

privateKeyFile (security)

The private key for generating the JWT signature.

 

String

privateKeyPassword (security)

The password for the private key.

 

String

publicKeyId (security)

The ID for public key for validating the JWT signature.

 

String

sslContextParameters (security)

To configure security using SSLContextParameters.

 

SSLContextParameters

userName (security)

Box user name, MUST be provided

 

String

userPassword (security)

Box user password, MUST be provided if authSecureStorage is not set, or returns null on first call

 

String

52.3. URI format

box:apiName/methodName

apiName can be one of:

  • collaborations
  • comments
  • event-logs
  • files
  • folders
  • groups
  • events
  • search
  • tasks
  • users

52.4. Producer Endpoints:

Producer endpoints can use endpoint prefixes followed by endpoint names and associated options described next. A shorthand alias can be used for some endpoints. The endpoint URI MUST contain a prefix.

Endpoint options that are not mandatory are denoted by []. When there are no mandatory options for an endpoint, one of the set of [] options MUST be provided. Producer endpoints can also use a special option inBody that in turn should contain the name of the endpoint option whose value will be contained in the Camel Exchange In message.

Any of the endpoint options can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelBox.<option>. Note that the inBody option overrides message header, i.e. the endpoint option inBody=option would override a CamelBox.option header.

If a value is not provided for the option defaultRequest either in the endpoint URI or in a message header, it will be assumed to be null. Note that the null value will only be used if other options do not satisfy matching endpoints.

In case of Box API errors the endpoint will throw a RuntimeCamelException with a com.box.sdk.BoxAPIException derived exception cause.

52.4.1. Endpoint Prefix collaborations

For more information on Box collaborations see https://developer.box.com/reference#collaboration-object. The following endpoints can be invoked with the prefix collaborations as follows:

box:collaborations/endpoint?[options]
EndpointShorthand AliasOptionsResult Body Type

addFolderCollaboration

add

folderId, collaborator, role

com.box.sdk.BoxCollaboration

addFolderCollaborationByEmail

addByEmail

folderId, email, role

com.box.sdk.BoxCollaboration

deleteCollaboration

delete

collaborationId

 

getFolderCollaborations

collaborations

folderId

java.util.Collection

getPendingCollaborations

pendingCollaborations

 

java.util.Collection

getCollaborationInfo

info

collaborationId

com.box.sdk.BoxCollaboration.Info

updateCollaborationInfo

updateInfo

collaborationId, info

com.box.sdk.BoxCollaboration

URI Options for collaborations

NameType

collaborationId

String

collaborator

com.box.sdk.BoxCollaborator

role

com.box.sdk.BoxCollaboration.Role

folderId

String

email

String

info

com.box.sdk.BoxCollaboration.Info

52.4.2. Endpoint Prefix comments

For more information on Box comments see https://developer.box.com/reference#comment-object. The following endpoints can be invoked with the prefix comments as follows:

box:comments/endpoint?[options]
EndpointShorthand AliasOptionsResult Body Type

addFileComment

add

fileId, message

com.box.sdk.BoxFile

changeCommentMessage

updateMessage

commentId, message

com.box.sdk.BoxComment

deleteComment

delete

commentId

 

getCommentInfo

info

commentId

com.box.sdk.BoxComment.Info

getFileComments

comments

fileId

java.util.List

replyToComment

reply

commentId, message

com.box.sdk.BoxComment

URI Options for collaborations

NameType

commentId

String

fileId

String

message

String

52.4.3. Endpoint Prefix events-logs

For more information on Box event logs see https://developer.box.com/reference#events. The following endpoints can be invoked with the prefix events as follows:

box:event-logs/endpoint?[options]
EndpointShorthand AliasOptionsResult Body Type

getEnterpriseEvents

events

position, after, before, [types]

java.util.List

URI Options for event-logs

NameType

position

String

after

Date

before

Date

types

com.box.sdk.BoxEvent.Types[]

52.4.4. Endpoint Prefix files

For more information on Box files see https://developer.box.com/reference#file-object. The following endpoints can be invoked with the prefix files as follows.

box:files/endpoint?[options]
EndpointShorthand AliasOptionsResult Body Type

uploadFile

upload

parentFolderId, content, fileName, [created], [modified], [size], [listener]

com.box.sdk.BoxFile

downloadFile

download

fileId, output, [rangeStart], [rangeEnd], [listener]

java.io.OutputStream

copyFile

copy

fileId, destinationFolderId, [newName]

com.box.sdk.BoxFile

moveFile

move

fileId, destinationFolderId, [newName]

com.box.sdk.BoxFile

renameFile

rename

fileId, newFileName

com.box.sdk.BoxFile

createFileSharedLink

link

fileId, access, [unshareDate], [permissions]

com.box.sdk.BoxSharedLink

deleteFile

delete

fileId

 

uploadNewFileVersion

uploadVersion

fileId, fileContent, [modified], [fileSize], [listener]

com.box.boxsdk.BoxFile

promoteFileVersion

promoteVersion

fileId, version

com.box.sdk.BoxFileVersion

getFileVersions

versions

fileId

java.util.Collection

downloadPreviousFileVersions

downloadVersion

fileId, version, output, [listener]

java.io.OutputStream

deleteFileVersion

deleteVersion

fileId, version

 

getFileInfo

info

fileId, fields

com.box.sdk.BoxFile.Info

updateFileInfo

updateInfo

fileId, info

com.box.sdk.BoxFile

createFileMetadata

createMetadata

fileId, metadata, [typeName]

com.box.sdk.Metadata

getFileMetadata

metadata

fileId, [typeName]

com.box.sdk.Metadata

updateFileMetadata

updateMetadata

fileId, metadata

com.box.sdk.Metadata

deleteFileMetadata

deleteMetadata

fileId

 

getDownloadUrl

url

fileId

java.net.URL

getPreviewLink

preview

fileId

java.net.URL

getFileThumbnail

thumbnail

fileId, fileType, minWidth, minHeight, maxWidth, maxHeight

byte[]

URI Options for files

NameType

parentFolderId

String

content

java.io.InputStream

fileName

String

created

Date

modified

Date

size

Long

listener

com.box.sdk.ProgressListener

output

java.io.OutputStream

rangeStart

Long

rangeEnd

Long

outputStreams

java.io.OutputStream[]

destinationFolderId

String

newName

String

fields

String[]

info

com.box.sdk.BoxFile.Info

fileSize

Long

version

Integer

access

com.box.sdk.BoxSharedLink.Access

unshareDate

Date

permissions

com.box.sdk.BoxSharedLink.Permissions

fileType

com.box.sdk.BoxFile.ThumbnailFileType

minWidth

Integer

minHeight

Integer

maxWidth

Integer

maxHeight

Integer

metadata

com.box.sdk.Metadata

typeName

String

52.4.5. Endpoint Prefix folders

For more information on Box folders see https://developer.box.com/reference#folder-object. The following endpoints can be invoked with the prefix folders as follows.

box:folders/endpoint?[options]
EndpointShorthand AliasOptionsResult Body Type

getRootFolder

root

 

com.box.sdk.BoxFolder

createFolder

create

parentFolderId, folderName

com.box.sdk.BoxFolder

createFolder

create

parentFolderId, path

com.box.sdk.BoxFolder

copyFolder

copy

folderId, destinationfolderId, [newName]

com.box.sdk.BoxFolder

moveFolder

move

folderId, destinationFolderId, newName

com.box.sdk.BoxFolder

renameFolder

rename

folderId, newFolderName

com.box.sdk.BoxFolder

createFolderSharedLink

link

folderId, access, [unsharedDate], [permissions]

java.util.List

deleteFolder

delete

folderId

 

getFolder

folder

path

com.box.sdk.BoxFolder

getFolderInfo

info

folderId, fields

com.box.sdk.BoxFolder.Info

getFolderItems

items

folderId, offset, limit, fields

com.box.sdk.BoxFolder

updateFolderInfo

updateInfo

folderId, info

com.box.sdk.BoxFolder

URI Options for folders

NameType

path

String[]

folderId

String

offset

Long

limit

Long

fields

String[]

parentFolderId

String

folderName

String

destinationFolderId

String

newName

String

newFolderName

String

info

String

access

com.box.sdk.BoxSharedLink.Access

unshareDate

Date

permissions

com.box.sdk.BoxSharedLink.Permissions

52.4.6. Endpoint Prefix groups

For more information on Box groups see https://developer.box.com/reference#group-object. The following endpoints can be invoked with the prefix groups as follows:

box:groups/endpoint?[options]
EndpointShorthand AliasOptionsResult Body Type

createGroup

create

name, [provenance, externalSyncIdentifier, description, invitabilityLevel, memberViewabilityLevel]

com.box.sdk.BoxGroup

addGroupMembership

createMembership

groupId, userId, role

com.box.sdk.BoxGroupMembership

deleteGroup

delete

groupId

 

getAllGroups

groups

 

java.util.Collection

getGroupInfo

info

groupId

com.box.sdk.BoxGroup.Info

updateGroupInfo

updateInfo

groupId, groupInfo

com.box.sdk.BoxGroup

addGroupMembership

addMembership

groupId, userId, role

com.box.sdk.BoxGroupMembership

deleteGroupMembership

deleteMembership

groupMembershipId

 

getGroupMemberships

memberships

groupId

java.uti.Collection

getGroupMembershipInfo

membershipInfo

groupMemebershipId

com.box.sdk.BoxGroup.Info

updateGroupMembershipInfo

updateMembershipInfo

groupMemebershipId, info

com.box.sdk.BoxGroupMembership

URI Options for groups

NameType

name

String

groupId

String

userId

String

role

com.box.sdk.BoxGroupMembership.Role

groupMembershipId

String

info

com.box.sdk.BoxGroupMembership.Info

52.4.7. Endpoint Prefix search

For more information on Box search API see https://developer.box.com/reference#searching-for-content. The following endpoints can be invoked with the prefix search as follows:

box:search/endpoint?[options]
EndpointShorthand AliasOptionsResult Body Type

searchFolder

search

folderId, query

java.util.Collection

URI Options for search

NameType

folderId

String

query

String

52.4.8. Endpoint Prefix tasks

For information on Box tasks see https://developer.box.com/reference#task-object-1. The following endpoints can be invoked with the prefix tasks as follows:

box:tasks/endpoint?[options]
EndpointShorthand AliasOptionsResult Body Type

addFileTask

add

fileId, action, dueAt, [message]

com.box.sdk.BoxUser

deleteTask

delete

taskId

 

getFileTasks

tasks

fileId

java.util.List

getTaskInfo

info

taskId

com.box.sdk.BoxTask.Info

updateTaskInfo

updateInfo

taskId, info

com.box.sdk.BoxTask

addAssignmentToTask

addAssignment

taskId, assignTo

com.box.sdk.BoxTask

deleteTaskAssignment

deleteAssignment

taskAssignmentId

 

getTaskAssignments

assignments

taskId

java.util.List

getTaskAssignmentInfo

assignmentInfo

taskAssignmentId

com.box.sdk.BoxTaskAssignment.Info

URI Options for tasks

NameType

fileId

String

action

com.box.sdk.BoxTask.Action

dueAt

Date

message

String

taskId

String

info

com.box.sdk.BoxTask.Info

assignTo

com.box.sdk.BoxUser

taskAssignmentId

String

52.4.9. Endpoint Prefix users

For information on Box users see https://developer.box.com/reference#user-object. The following endpoints can be invoked with the prefix users as follows:

box:users/endpoint?[options]
EndpointShorthand AliasOptionsResult Body Type

getCurrentUser

currentUser

 

com.box.sdk.BoxUser

getAllEnterpriseOrExternalUsers

users

filterTerm, [fields]

com.box.sdk.BoxUser

createAppUser

create

name, [params]

com.box.sdk.BoxUser

createEnterpriseUser

create

login, name, [params]

com.box.sdk.BoxUser

deleteUser

delete

userId, notifyUser, force

 

getUserEmailAlias

emailAlias

userId

com.box.sdk.BoxUser

deleteUserEmailAlias

deleteEmailAlias

userId, emailAliasId

java.util.List

getUserInfo

info

userId

com.box.sdk.BoxUser.Info

updateUserInfo

updateInfo

userId, info

com.box.sdk.BoxUser

moveFolderToUser

-

userId, sourceUserId

com.box.sdk.BoxFolder.Info

URI Options for users

NameType

defaultRequest

com.box.restclientv2.requestsbase.BoxDefaultRequestObject

emailAliasRequest

com.box.boxjavalibv2.requests.requestobjects.BoxEmailAliasRequestObject

emailId

String

filterTerm

String

folderId

String

simpleUserRequest

com.box.boxjavalibv2.requests.requestobjects.BoxSimpleUserRequestObject

userDeleteRequest

com.box.boxjavalibv2.requests.requestobjects.BoxUserDeleteRequestObject

userId

String

userRequest

com.box.boxjavalibv2.requests.requestobjects.BoxUserRequestObject

userUpdateLoginRequest

com.box.boxjavalibv2.requests.requestobjects.BoxUserUpdateLoginRequestObject

52.5. Consumer Endpoints:

For more information on Box events see https://developer.box.com/reference#events. Consumer endpoints can only use the endpoint prefix events as shown in the example next.

box:events/endpoint?[options]
EndpointShorthand AliasOptionsResult Body Type

events

 

[startingPosition]

com.box.sdk.BoxEvent

URI Options for events

NameType

startingPosition

Long

52.6. Message header

Any of the options can be provided in a message header for producer endpoints with CamelBox. prefix.

52.7. Message body

All result message bodies utilize objects provided by the Box Java SDK. Producer endpoints can specify the option name for incoming message body in the inBody endpoint parameter.

52.8. Samples

The following route uploads new files to the user’s root folder:

from("file:...")
    .to("box://files/upload/inBody=fileUploadRequest");

The following route polls user’s account for updates:

from("box://events/listen?startingPosition=-1")
    .to("bean:blah");

The following route uses a producer with dynamic header options. The fileId property has the Box file id and the output property has the output stream of the file contents, so they are assigned to the CamelBox.fileId header and CamelBox.output header respectively as follows:

from("direct:foo")
    .setHeader("CamelBox.fileId", header("fileId"))
    .setHeader("CamelBox.output", header("output"))
    .to("box://files/download")
    .to("file://...");
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.