public class

BoxConnector

extends Object
implements MuleContextAware
java.lang.Object
   ↳ org.mule.modules.boxnet.BoxConnector
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Box.net Cloud Connector Module.

Summary

Constants
String AUTH_URL The url where the user needs to enter his credentials
String BOX_AUTH_TICKET
String BOX_AUTH_TOKEN
Fields
private String apiKey The API key obtained when registering a project with the Box platform.
private AuthCallbackAdapter authCallback
private String authToken
private String callbackPath The url where box.net will direct the authentication callback.
private Integer callbackPort The port where the authentication callback will be listening on Defaults to 8080
private BoxExternalAPI client
private static final Base64Decoder decoder
private Connector httpConnector The http connector to be used when serving the authorization callback.
private static final Logger logger
private MuleContext muleContext
private String postAuthFlow The name of a flow to be invoked after an authorization callback is received.
private Flow postAuthorizationFlow
private String restoreAuthTokenFlow The name of a flow to be executed each time the authentication token needs to be used.
private Flow restoreTokenFlow Actual restore token flow egarly fetched
private String saveAuthTokenFlow The name of a flow to be executed each time an authentication token is received.
private Flow saveTokenFlow Actual save token flow egarly fetched
private boolean usesCallback If true, an http inbound endpoint will be set in place to receive a callback from box.net with the authToken once the user has authenticated.
Public Constructors
BoxConnector()
Public Methods
String addToTag(MuleMessage message, String csvTags, Target target, String targetId)
This processor adds file or folder to tags list.
void authToken(MuleMessage message, String ticket)
After the user authenticates the ticket obtained with the get-ticket processor, there're two ways to get the required auth token:
  1. You can configure box.net to make a callback returning the ticket and authToken, in which case you need to set the usesCallback and callbackPath config attributes accordingly
  2. You can use this processor to obtain the authentication token explicitly.
void authorizeTicket(MuleMessage message, String ticket)
Redirects the browser to box authorization page so that the user can enter his credentials.
CreateFolderResponse createFolder(MuleMessage message, String parentFolderId, String folderName, Boolean share)
Create a new folder
DeleteResponse delete(MuleMessage message, Target target, String targetId)
Deletes a file or folder
byte[] download(MuleMessage message, String fileId)
Downloads a file an returns its contents as a byte[]
String exportTags(MuleMessage message, String encoding)
This processor returns all the user's tags.
String getApiKey()
String getCallbackPath()
Integer getCallbackPort()
GetFileInfoResponse getFileInfo(MuleMessage message, String fileId)
Gets information about a file
Connector getHttpConnector()
String getPostAuthFlow()
String getRestoreAuthTokenFlow()
String getSaveAuthTokenFlow()
String getTicket(MuleMessage message, Boolean redirect)
Get and access ticket using the configured apiKey.
GetAccountTreeResponse getTreeStructure(MuleMessage message, String folderId, String csvParams, String encoding)
This processor is used to get a user's files and folders tree.
void init()
This method initiaes the box client and the auth callback.
boolean isUsesCallback()
LogoutResponse logout(MuleMessage message)
Logs out the user associated with the authorization token
String move(MuleMessage message, Target target, String targetId, String destinationId)
This processor moves a file or folder to another folder.
void onStop()
String privateShare(MuleMessage muleMessage, Target target, String targetId, String csvMails, Boolean notify, String message)
This processor privately shares a file or folder with another user(s).
PublicShareResponse publicShare(MuleMessage muleMessage, Target target, String targetId, String password, String message)
Makes a public share of a file or folder
String publicUnshare(MuleMessage message, Target target, String targetId)
This processor unshares a public shared file or folder
RegisterNewUserResponse registerNewUser(String email, String password)
Create a new user in box.net
String rename(MuleMessage message, Target target, String targetId, String newName)
This processor renames a file or folder.
MuleMessage saveAuthToken(MuleMessage message, String ticket, String authToken)
void setApiKey(String apiKey)
void setCallbackPath(String callbackPath)
void setCallbackPort(Integer callbackPort)
String setDescription(MuleMessage message, Target target, String targetId, String description)
This processor sets a description to a file or folder.
void setHttpConnector(Connector httpConnector)
void setMuleContext(MuleContext context)
void setPostAuthFlow(String postAuthFlow)
void setRestoreAuthTokenFlow(String restoreAuthTokenFlow)
void setSaveAuthTokenFlow(String saveAuthTokenFlow)
void setUsesCallback(boolean usesCallback)
UploadResponse uploadFiles(MuleMessage message, List<String> paths, String folderId)
Receives a comma separated list of paths and uploads the corresponding files.
UploadResponse uploadStream(MuleMessage message, String folderId, String filename, InputStream input)
Receives an input stream and uploads its content as a file
String verifyRegistrationEmail(MuleMessage message, String loginName)
This method is used to verify user registration email
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.mule.api.context.MuleContextAware

Constants

private static final String AUTH_URL

The url where the user needs to enter his credentials

Constant Value: "https://www.box.net/api/1.0/auth/"

private static final String BOX_AUTH_TICKET

Constant Value: "boxAuthTicket"

private static final String BOX_AUTH_TOKEN

Constant Value: "boxAuthToken"

Fields

private String apiKey

The API key obtained when registering a project with the Box platform. For more information about this field please refer to http://developers.box.net/

private AuthCallbackAdapter authCallback

private String authToken

private String callbackPath

The url where box.net will direct the authentication callback. For more info look at http://developers.box.net/w/page/12923915/ApiAuthentication Defaults to box_auth_callback

private Integer callbackPort

The port where the authentication callback will be listening on Defaults to 8080

private BoxExternalAPI client

private static final Base64Decoder decoder

private Connector httpConnector

The http connector to be used when serving the authorization callback. If usesCallback is false then this connector is not used. If not provided, the default http connector will be used. However, specifying an https connector instead is adviced.

private static final Logger logger

private MuleContext muleContext

private String postAuthFlow

The name of a flow to be invoked after an authorization callback is received. If usesCallback is false then this flow will never be invoked. This flow will receive a copy of the current mule message carrying two additional invocation variables:

  • boxAuthTicket: The ticket for which the authorization token was generated
  • boxAuthToken: The obtained authorization token
For example: <box:config apiKey="${apiKey}" restoreAuthTokenFlow="restoreTokenFlow" saveAuthTokenFlow="saveTokenFlow"/> <flow name="restoreTokenFlow"> <objectstore:retrieve key="flowVars['currentUserId']"/> </flow> <flow name="save"> <objectstore:store key="flowVars['currentUserId']" value-ref="#[flowVars['boxAuthToken']]"/> </flow> This flow will receive the same mule message the auth callback receives. If additionaly you also provided a saveAuthTokenFlow, then any mutations done to the message there are also available in this flow

private Flow postAuthorizationFlow

private String restoreAuthTokenFlow

The name of a flow to be executed each time the authentication token needs to be used. If this attribute is specified, then a flow with this named will be fetch on the registry and invoked every time the auth token is needed. This flow will receive a copy of the current mule message and must set the payload to a valid auth token. If the flow fails to accomplish that, an exception will be thrown For example: <box:config apiKey="${apiKey}" restoreAuthTokenFlow="restoreTokenFlow" saveAuthTokenFlow="saveTokenFlow"/> <flow name="restoreTokenFlow"> <objectstore:retrieve key="flowVars['currentUserId']"/> </flow> <flow name="save"> <objectstore:store key="flowVars['currentUserId']" value-ref="#[flowVars['boxAuthToken']]"/> </flow> If this attribute is not specified, then the token will be fetched from memory. Notice that this means the token won't survive an application restart and that the connector would be incapable of handling two different concurrent accounts

private Flow restoreTokenFlow

Actual restore token flow egarly fetched

private String saveAuthTokenFlow

The name of a flow to be executed each time an authentication token is received. If this attribute is specified, then a flow with this name will be fetch on the registry and invoked every time the auth token is obtained. This flow will receive a copy of the current mule message carrying two additional invocation variables:

  • boxAuthTicket: The ticket for which the authorization token was generated
  • boxAuthToken: The obtained authorization token
For example: <box:config apiKey="${apiKey}" restoreAuthTokenFlow="restoreTokenFlow" saveAuthTokenFlow="saveTokenFlow"/> <flow name="restoreTokenFlow"> <objectstore:retrieve key="flowVars['currentUserId']"/> </flow> <flow name="save"> <objectstore:store key="flowVars['currentUserId']" value-ref="#[flowVars['boxAuthToken']]"/> </flow> If this attribute is not specified, then the token will be stored in memory. Notice that this means the token won't survive an application restart and that the connector would be incapable of handling two different concurrent accounts

private Flow saveTokenFlow

Actual save token flow egarly fetched

private boolean usesCallback

If true, an http inbound endpoint will be set in place to receive a callback from box.net with the authToken once the user has authenticated. If this callback is in place, there's no need for you to manually invoke the get-auth-token processor. For more info look at http://developers.box.net/w/page/12923915/ApiAuthentication Defaults to false

Public Constructors

public BoxConnector ()

Public Methods

public String addToTag (MuleMessage message, String csvTags, Target target, String targetId)

This processor adds file or folder to tags list.

Parameters
message The current mule message
csvTags Comma separated list of tags
target Can be either 'file' or 'folder' depending on what do you want to add
targetId The id of a file or folder to be added
Returns
  • 'addtotag_ok' if successful. Otherwise addtotag_error.

public void authToken (MuleMessage message, String ticket)

After the user authenticates the ticket obtained with the get-ticket processor, there're two ways to get the required auth token:

  1. You can configure box.net to make a callback returning the ticket and authToken, in which case you need to set the usesCallback and callbackPath config attributes accordingly
  2. You can use this processor to obtain the authentication token explicitly.
Either way, this connector will retain the authToken in memory and will use it in all operations. For more info look at http://developers.box.net/w/page/12923915/ApiAuthentication

Parameters
message The current mule message
ticket The ticket to authenticate against.
Throws
IllegalArgumentException if the ticket does not match a logged user

public void authorizeTicket (MuleMessage message, String ticket)

Redirects the browser to box authorization page so that the user can enter his credentials. The new location will be https://www.box.net/api/1.0/auth/<<ticket>>

Parameters
message The current mule message
ticket The ticket to be authorized

public CreateFolderResponse createFolder (MuleMessage message, String parentFolderId, String folderName, Boolean share)

Create a new folder

Parameters
message The current mule message
parentFolderId The id of the parent folder
folderName The name of the folder you want to create
share Specifies if the folder is shared. This parameter is optional and defaults to false
Returns
  • an instance of CreateFolderResponse with data about the operation status and info about the newly created folder (if successful)

public DeleteResponse delete (MuleMessage message, Target target, String targetId)

Deletes a file or folder

Parameters
message The current mule message
target The type of item to be shared. This can be set as 'file' or 'folder'. Any other value will throw a IllegalArgumentException
targetId The id of the item you wish to delete. If the target is a folder, this will be the folder_id. If the target is a file, this will be the file_id.
Returns

public byte[] download (MuleMessage message, String fileId)

Downloads a file an returns its contents as a byte[]

Parameters
message The current mule message
fileId The id of the file we want to download
Returns
  • the file's contents as a byte array

public String exportTags (MuleMessage message, String encoding)

This processor returns all the user's tags. On successful you will get an xml representing the tags that looks like this: music mp3 If the result wasn't successful, status field can be: not_logged_id, application_restricted.

Parameters
message The current mule message
encoding Encoding to use when decoding from BASE64. Optional, defaults to UTF-8
Returns
  • a String xml representing the tags

public String getApiKey ()

public String getCallbackPath ()

public Integer getCallbackPort ()

public GetFileInfoResponse getFileInfo (MuleMessage message, String fileId)

Gets information about a file

Parameters
message The current mule message
fileId The id of the file you want info about
Returns

public Connector getHttpConnector ()

public String getPostAuthFlow ()

public String getRestoreAuthTokenFlow ()

public String getSaveAuthTokenFlow ()

public String getTicket (MuleMessage message, Boolean redirect)

Get and access ticket using the configured apiKey. Optionally, you can ask the connector to automatically redirect the browser to box authorization page so that the user can enter his credentials. This is done by invoking org.mule.modules.boxnet.BoxConnector.authorizeTicket(MuleMessage, String) Otherwise, the user needs to manually go to https://www.box.net/api/1.0/auth/<<ticket>> Either way, the connector WILL NOT be responsible for storing this ticket. For more info look at http://developers.box.net/w/page/12923915/ApiAuthentication

Parameters
message The current mule message
redirect If true, then the browser will be automatically redirected to https://www.box.net/api/1.0/auth/<<ticket>>
Returns
  • the obtained ticket

public GetAccountTreeResponse getTreeStructure (MuleMessage message, String folderId, String csvParams, String encoding)

This processor is used to get a user's files and folders tree. 'folderId' param defines root folder from which the tree begins. 'csvParams' is comma separated list where you can set additional parameters, which are: onelevel - make a tree of one level depth, so you will get only files and folders stored in folder which folder_id you have provided. nofiles - include folders only in result tree, no files. nozip - do not zip tree xml. On successful result you will receive 'listing_ok' as status and the tree xml. if you haven't set 'nozip' as a parameter (it's set by default), then you have to unzip it. Then you will get xml like this: (note that updatedand createdare UNIX timestamps in PST).

Parameters
message The current mule message
folderId The ID of the root folder from which the tree begins. If this value is "0", the user's full account tree is returned. Defaults to zero
csvParams Comma separated list of params. This is optional and defaults to 'nozip'
encoding Optional parameter to specify the encoding to use when decoding BASE64. Defaults to UTF-8
Returns
  • an instance of GetAccountTreeResponse with data about the operation status and info about the inspected folder (if successful)

public void init ()

This method initiaes the box client and the auth callback. Also, it fetches the save/restore flows (if specified). If those are specified but don't exist in the registry, then IllegalArgumentException is thrown

Throws
IllegalArgumentException if restore/save token flows are specified but don't exist
MuleException

public boolean isUsesCallback ()

public LogoutResponse logout (MuleMessage message)

Logs out the user associated with the authorization token

Parameters
message The current mule message
Returns

public String move (MuleMessage message, Target target, String targetId, String destinationId)

This processor moves a file or folder to another folder. On a successful result, status will be 's_move_node'. If the result wasn't successful, status field can be: 'e_move_node', 'not_logged_in', 'application_restricted'.

Parameters
message The current mule message
target Can be either 'file' or 'folder' depending on what do you
targetId Is the id of a file or folder to be moved
destinationId Is the destination folder id.
Returns
  • if successful 's_move_node'. Otherwise it can be 'e_move_node', 'not_logged_in', 'application_restricted'.

public void onStop ()

Throws
MuleException

public String privateShare (MuleMessage muleMessage, Target target, String targetId, String csvMails, Boolean notify, String message)

This processor privately shares a file or folder with another user(s). 'target' param, 'target_id' is . 'emails' params is an array of emails of users' to share files with. if 'notify' param is , 'message' param . Note: currently only files can be shared privately.

Parameters
muleMessage The current mule message
target Should be either 'file' or 'folder'
targetId The id of the file or folder to be shared
csvMails Comma separated list of email addresses of the users that will receive the share
notify If true, then a notification email will be sent to users. Optional parameter, defaults to true
message Is a message to be included in the notification email. Optional parameter, defaults to an empty string
Returns
  • if successful will be 'private_share_ok'. Otherwise can be: 'private_share_error', 'wrong_node', 'not_logged_in', 'application_restricted'.

public PublicShareResponse publicShare (MuleMessage muleMessage, Target target, String targetId, String password, String message)

Makes a public share of a file or folder

Parameters
muleMessage The current mule message
target The type of item to be shared. This can be set as 'file' or 'folder'. Any other value will throw a IllegalArgumentException
targetId The id of the item you wish to share. If the target is a folder, this will be the folder_id. If the target is a file, this will be the file_id.
password The password to protect the folder or file.
message An message to be included in a notification email.
Returns
  • an instance of PublicShareResponse with data about the operation status and info about the shared folder (if successful)

public String publicUnshare (MuleMessage message, Target target, String targetId)

This processor unshares a public shared file or folder

Parameters
message The current mule message
target Shoud be either 'file' or 'folder'
targetId Is id of a file or folder to be unshared
Returns
  • On a successful result, the status will be 'unshare_ok'. If the result wasn't successful, the status field can be: 'unshare_error', 'wrong_node', 'not_logged_in', 'application_restricted'.

public RegisterNewUserResponse registerNewUser (String email, String password)

Create a new user in box.net

Parameters
email The user's email
password The user's password
Returns
  • an instance of RegisterNewUserResponse with data about the operation status and info about the newly created user (if successful)

public String rename (MuleMessage message, Target target, String targetId, String newName)

This processor renames a file or folder.

Parameters
message The current mule message
target Can be either 'file' or 'folder' depending on what you want to rename
targetId Is the id of a file or folder to be renamed
newName Is the new name for a file or folder
Returns
  • if successful will be 's_rename_node'. Otherwise it can be: 'e_rename_node', 'not_logged_in', 'application_restricted'

public MuleMessage saveAuthToken (MuleMessage message, String ticket, String authToken)

Parameters
message
ticket
authToken

public void setApiKey (String apiKey)

Parameters
apiKey

public void setCallbackPath (String callbackPath)

Parameters
callbackPath

public void setCallbackPort (Integer callbackPort)

Parameters
callbackPort

public String setDescription (MuleMessage message, Target target, String targetId, String description)

This processor sets a description to a file or folder.

Parameters
message The current mule message
target Can be either 'file' or 'folder'
targetId The id of the folder/file you want to modify
description The description you want to set
Returns
  • 's_set_description' if successful. 'e_set_description' otherwise.

public void setHttpConnector (Connector httpConnector)

Parameters
httpConnector

public void setMuleContext (MuleContext context)

Parameters
context

public void setPostAuthFlow (String postAuthFlow)

Parameters
postAuthFlow

public void setRestoreAuthTokenFlow (String restoreAuthTokenFlow)

Parameters
restoreAuthTokenFlow

public void setSaveAuthTokenFlow (String saveAuthTokenFlow)

Parameters
saveAuthTokenFlow

public void setUsesCallback (boolean usesCallback)

Parameters
usesCallback

public UploadResponse uploadFiles (MuleMessage message, List<String> paths, String folderId)

Receives a comma separated list of paths and uploads the corresponding files.

Parameters
message The current mule message
paths A List of Strings with the paths where the files are. Defaults to payload
folderId The id of the parent folder. Defaults to 0 (the root folder)
Returns
  • an instance of UploadResponse with data about the operation status and info about the newly uploaded files (if successful)

public UploadResponse uploadStream (MuleMessage message, String folderId, String filename, InputStream input)

Receives an input stream and uploads its content as a file

Parameters
message The current mule message
folderId The id of the parent folder. Defaults to 0 which is the root folder
filename The name we want the file to have on box.net
input InputStream with the contents of the file. Defaults to the message payload.
Returns
  • an instance of UploadResponse with data about the operation status and info about the newly uploaded file (if successful)

public String verifyRegistrationEmail (MuleMessage message, String loginName)

This method is used to verify user registration email

Parameters
message The current mule message
loginName The login username of the user for which you would like to verify registration.
Returns
  • Upon a successful registration, the return value will be 'email_ok'. If registration was not successful, it can be: 'email_invalid' - The login provided is not a valid email address. 'email_already_registered' - The login provided is already registered by another user. 'application_restricted'- You provided an invalid api_key, or the api_key is restricted from calling this function.