当前位置: 首页>>代码示例>>Java>>正文


Java Response类代码示例

本文整理汇总了Java中org.springframework.extensions.webscripts.connector.Response的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Response类属于org.springframework.extensions.webscripts.connector包,在下文中一共展示了Response类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateModel

import org.springframework.extensions.webscripts.connector.Response; //导入依赖的package包/类
/**
 * Generates the model to send to the FreeMarker engine.
 * 
 * @param itemKind The form itemKind
 * @param itemId The form itemId
 * @param request The WebScriptRequest
 * @param status The response status
 * @param cache Cache control
 * @return Map
 */
protected Map<String, Object> generateModel(String itemKind, String itemId, 
            WebScriptRequest request, Status status, Cache cache)
{
    Map<String, Object> model = null;
    
    // get mode and optional formId
    String modeParam = getParameter(request, MODEL_MODE, DEFAULT_MODE);
    String formId = getParameter(request, PARAM_FORM_ID);
    Mode mode = Mode.modeFromString(modeParam);
    
    if (logger.isDebugEnabled())
        logger.debug("Showing " + mode + " form (id=" + formId + ") for item: [" + itemKind + "]" + itemId);
    
    // get the form configuration and list of fields that are visible (if any)
    FormConfigElement formConfig = getFormConfig(itemId, formId);
    List<String> visibleFields = getVisibleFields(mode, formConfig);
    
    // get the form definition from the form service
    Response formSvcResponse = retrieveFormDefinition(itemKind, itemId, visibleFields, formConfig);
    if (formSvcResponse.getStatus().getCode() == Status.STATUS_OK)
    {
        model = generateFormModel(request, mode, formSvcResponse, formConfig);
    }
    else if (formSvcResponse.getStatus().getCode() == Status.STATUS_UNAUTHORIZED)
    {
        // set status to 401 and return null model
        status.setCode(Status.STATUS_UNAUTHORIZED);
        status.setRedirect(true);
    }
    else
    {
        String errorKey = getParameter(request, PARAM_ERROR_KEY);
        model = generateErrorModel(formSvcResponse, errorKey);
    }
    
    return model;
}
 
开发者ID:ecm4u,项目名称:ecm4u-alfresco-bugpatches,代码行数:48,代码来源:FormUIGet.java

示例2: retrieveFormDefinition

import org.springframework.extensions.webscripts.connector.Response; //导入依赖的package包/类
/**
 * Retrieves the form definition from the repository FormService for the
 * given item.
 * 
 * @param itemKind The form item kind
 * @param itemId The form item id
 * @param visibleFields The list of field names to return or null
 *        to return all fields
 * @param formConfig The form configuration
 * @return Response object from the remote call
 */
protected Response retrieveFormDefinition(String itemKind, String itemId, 
            List<String> visibleFields, FormConfigElement formConfig)
{
    Response response = null;
    
    try
    {
        // setup the connection
        ConnectorService connService = FrameworkUtil.getConnectorService();
        RequestContext requestContext = ThreadLocalRequestContext.getRequestContext();
        String currentUserId = requestContext.getUserId();
        HttpSession currentSession = ServletUtil.getSession(true);
        Connector connector = connService.getConnector(ENDPOINT_ID, currentUserId, currentSession);
        ConnectorContext context = new ConnectorContext(HttpMethod.POST, null, buildDefaultHeaders());
        context.setContentType("application/json");
        
        // call the form service
        response = connector.call("/api/formdefinitions", context, generateFormDefPostBody(itemKind,
                    itemId, visibleFields, formConfig));
        
        if (logger.isDebugEnabled())
            logger.debug("Response status: " + response.getStatus().getCode());
    }
    catch (Exception e)
    {
        if (logger.isErrorEnabled())
            logger.error("Failed to get form definition: ", e);
    }
    
    return response;
}
 
开发者ID:ecm4u,项目名称:ecm4u-alfresco-bugpatches,代码行数:43,代码来源:FormUIGet.java

示例3: generateFormModel

import org.springframework.extensions.webscripts.connector.Response; //导入依赖的package包/类
/**
 * Generates the "form" model passed to the FreeMarker engine.
 * 
 * @param request The WebScriptRequest
 * @param mode The mode of the form
 * @param formSvcResponse Response representing the form definition
 * @param formConfig The form configuration
 * @return Map representing the "form" model
 */
protected Map<String, Object> generateFormModel(WebScriptRequest request, Mode mode, 
            Response formSvcResponse, FormConfigElement formConfig)
{
    try
    {
        String jsonResponse = formSvcResponse.getResponse();
        
        if (logger.isDebugEnabled())
            logger.debug("form definition JSON = \n" + jsonResponse);
            
        // create JSON representation of form defintion from response
        JSONObject formDefinition = new JSONObject(new JSONTokener(jsonResponse));
    
        // create model to return
        Map<String, Object> model = new HashMap<String, Object>(1);
        model.put(MODEL_FORM, generateFormUIModel(new ModelContext(request, mode, formDefinition, formConfig)));
        return model;
    }
    catch (JSONException je)
    {
        if (logger.isErrorEnabled())
            logger.error(je);
        
        return null;
    }
}
 
开发者ID:ecm4u,项目名称:ecm4u-alfresco-bugpatches,代码行数:36,代码来源:FormUIGet.java

示例4: processFieldContent

import org.springframework.extensions.webscripts.connector.Response; //导入依赖的package包/类
/**
 * Processes the field for content. This method is used when a content field 
 * is being used in a form where JavaScript is disabled and thus AJAX is 
 * unavailable to retrieve the content, it must therefore be done server side.
 * 
 * @param context The context
 * @param field The field to be processed
 * @param fieldDefinition The definition of the field to be processed
 * @param fieldConfig The configuration of the field to be processed
 * @throws JSONException
 */
protected void processFieldContent(ModelContext context, Field field, 
            JSONObject fieldDefinition, FormField fieldConfig) throws JSONException
{
    // if the field is a content field and JavaScript is disabled
    // we need to retrieve the content here and store in model
    if (context.getFormUIModel().get(MODEL_CAPABILITIES) != null && "content".equals(field.getDataType()))
    {
        // NOTE: In the future when other capabilties are added the 'javascript'
        //       flag will need to be checked, for now it's the only reason
        //       the capabilities object will be present so a check is redundant
       
        if (logger.isDebugEnabled())
            logger.debug("Retrieving content for \"" + field.getConfigName() + "\" as JavaScript is disabled");
       
        // get the nodeRef of the content and then the content itself
        String nodeRef = getParameter(context.getRequest(), "itemId");
       
        try
        {
            ConnectorService connService = FrameworkUtil.getConnectorService();
            RequestContext requestContext = ThreadLocalRequestContext.getRequestContext();
            String currentUserId = requestContext.getUserId();
            HttpSession currentSession = ServletUtil.getSession(true);
            Connector connector = connService.getConnector(ENDPOINT_ID, currentUserId, currentSession);
           
            // call the form service
            Response response = connector.call("/api/node/content/" + nodeRef.replace("://", "/"));
            if (response.getStatus().getCode() == Status.STATUS_OK)
            {
                field.setContent(response.getText());
            }
        }
        catch (Exception e)
        {
            if (logger.isErrorEnabled())
                logger.error("Failed to get field content: ", e);
        }
    }
}
 
开发者ID:ecm4u,项目名称:ecm4u-alfresco-bugpatches,代码行数:51,代码来源:FormUIGet.java

示例5: isTicketValid

import org.springframework.extensions.webscripts.connector.Response; //导入依赖的package包/类
private boolean isTicketValid(ConnectorSession connectorSession, String ticket) {
  if (StringUtils.isBlank(ticket)) {
    return false;
  }

  if (StringUtils.isNotBlank(connectorSession.getParameter("ALWAYS_VALID"))) {
    return true;
  }

  try {
    Connector connector = FrameworkUtil.getConnector("alfresco");

    ConnectorSession fakeSession = clone(connectorSession);

    fakeSession.setParameter(CS_PARAM_ALF_TICKET, ticket);
    fakeSession.setParameter("ALWAYS_VALID", "true");
    connector.setConnectorSession(fakeSession);

    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("alf_ticket", ticket);
    
    Map<String, String> headers = Collections.emptyMap();
    ConnectorContext context = new ConnectorContext(parameters, headers);
    
    Response response = connector.call("/api/metadata", context);

    return response.getStatus().getCode() == Status.STATUS_OK;
  } catch (Exception ex) {
    return false;
  }
}
 
开发者ID:Redpill-Linpro,项目名称:share-ticket-login,代码行数:32,代码来源:AlfrescoTicketAuthenticator.java

示例6: evaluate

import org.springframework.extensions.webscripts.connector.Response; //导入依赖的package包/类
@Override
public boolean evaluate(JSONObject jsonObject) {
   try
   {
      String username = getUserId();
      JSONObject modifier =(JSONObject) getProperty(jsonObject,"cm:modifier");
      
      if (username.equalsIgnoreCase((String)modifier.get("userName")))
      {
          return true;
      }
      
      
      
      String siteName = getSiteId(jsonObject);
      
      if (siteName == null)
      {
         // It's not a site, so we have no opinion on access
         return true;
      }

      // Fetch the membership information for the site
      RequestContext rc = ThreadLocalRequestContext.getRequestContext();
      Connector conn = rc.getServiceRegistry().getConnectorService().getConnector(
            "alfresco", username, ServletUtil.getSession());
      Response response = conn.call("/api/sites/"+siteName+"/memberships/"+username);
      
      if (response.getStatus().getCode() == Status.STATUS_OK)
      {
         // Convert the response text to jsonobject
         JSONObject responsetext = (JSONObject)new JSONParser().parse(response.getResponse());
         
         // Get the user role and compare with required role
         return requiredRole.equalsIgnoreCase(this.getUserRole(responsetext));         
      }
      else if (response.getStatus().getCode() == Status.STATUS_NOT_FOUND)
      {
         // Not a member of the site / site not found / etc
         // Shouldn't be showing in this case
         return false;
      }
      else
      {
         logger.warn("Invalid response fetching memberships for " + username + " in " + siteName + " - " + response);
         return false;
      }
   }
   catch (Exception err)
   {
      throw new AlfrescoRuntimeException("Failed to run UI evaluator: " + err.getMessage());
   }
 }
 
开发者ID:muralidharand,项目名称:alfresco-disable-enable-download-action,代码行数:54,代码来源:DownloadActionEvaluator.java

示例7: generateErrorModel

import org.springframework.extensions.webscripts.connector.Response; //导入依赖的package包/类
/**
* Generates the "error" model used when an error occurs.
*
* @param errorResponse Response object representing the error
* @param errorKey String
* @return The "error" model
*/
protected Map<String, Object> generateErrorModel(Response errorResponse, String errorKey)
{
    String error = "";
    
    // retrieve and log the error
    try
    {
        JSONObject json = new JSONObject(new JSONTokener(errorResponse.getResponse()));
        if (json.has(MODEL_MESSAGE))
        {
            error = json.getString(MODEL_MESSAGE);
            
            // Common AccessDeniedException is reported as a 500 server error from the repository
            if ((error.indexOf("org.alfresco.repo.security.permissions.AccessDeniedException") == -1) &&
                    (errorKey == null || errorKey.isEmpty()))
            {
               if (logger.isErrorEnabled())
                   logger.error(error);
            }
        }
    }
    catch (JSONException je)
    {
        error= "";
    }
    
    if (errorKey == null || errorKey.isEmpty())
    {
        errorKey = MSG_DEFAULT_FORM_ERROR;
    }
    String id = errorKey + "." + errorResponse.getStatus().getCode();
    error = retrieveMessage(id);
    if (error.equals(id))
    {
        // use key if key+"."+status is not found
        error = retrieveMessage(errorKey);
    }

    // create model with error
    Map<String, Object> model = new HashMap<String, Object>(1);
    model.put(MODEL_ERROR, error);
    return model;
}
 
开发者ID:ecm4u,项目名称:ecm4u-alfresco-bugpatches,代码行数:51,代码来源:FormUIGet.java

示例8: getProbeSettings

import org.springframework.extensions.webscripts.connector.Response; //导入依赖的package包/类
@Override
protected Settings getProbeSettings(final WebScriptRequest req) {
  try {
    Pair<String, String> parseRequestedTransformation = parseRequestedTransformation(req);
    final RequestContext requestContext = ThreadLocalRequestContext.getRequestContext();

    final ConnectorService connService = requestContext.getServiceRegistry().getConnectorService();

    final String currentUserId = requestContext.getUserId();

    final HttpSession currentSession = ServletUtil.getSession(true);

    final Connector connector = connService.getConnector(ENDPOINT_ID, currentUserId, currentSession);

    final String alfrescoURL = "/org/redpill/alfresco/clusterprobe/probe/transform/" + parseRequestedTransformation.getFirst() + "/" + parseRequestedTransformation.getSecond();

    final Response response = connector.call(alfrescoURL);

    return new Settings(response.getResponse(), response.getStatus().getCode());
  } catch (final Exception ex) {
    LOG.error(ex.getMessage(), ex);
    final StringBuilder sb = new StringBuilder();

    StackTraceUtil.buildStackTrace(ex.getMessage(), ex.getStackTrace(), sb, 0);

    return new Settings("Couldn't get settings from repo server.\n" + sb.toString(), 500);
  }
}
 
开发者ID:Redpill-Linpro,项目名称:alfresco-cluster-probe,代码行数:29,代码来源:ProbeTransform.java

示例9: getProbeSettings

import org.springframework.extensions.webscripts.connector.Response; //导入依赖的package包/类
@Override
protected Settings getProbeSettings(final WebScriptRequest req) {
  try {

    final RequestContext requestContext = ThreadLocalRequestContext.getRequestContext();

    final ConnectorService connService = requestContext.getServiceRegistry().getConnectorService();

    final String currentUserId = requestContext.getUserId();

    final HttpSession currentSession = ServletUtil.getSession(true);

    final Connector connector = connService.getConnector(ENDPOINT_ID, currentUserId, currentSession);

    final String alfrescoURL = "/org/redpill/alfresco/clusterprobe/probe/search";

    final Response response = connector.call(alfrescoURL);

    return new Settings(response.getResponse(), response.getStatus().getCode());
  } catch (final Exception ex) {
    LOG.error(ex.getMessage(), ex);
    final StringBuilder sb = new StringBuilder();

    StackTraceUtil.buildStackTrace(ex.getMessage(), ex.getStackTrace(), sb, 0);

    return new Settings("Couldn't get settings from repo server.\n" + sb.toString(), 500);
  }
}
 
开发者ID:Redpill-Linpro,项目名称:alfresco-cluster-probe,代码行数:29,代码来源:ProbeSearch.java

示例10: getProbeSettings

import org.springframework.extensions.webscripts.connector.Response; //导入依赖的package包/类
@Override
protected Settings getProbeSettings(final WebScriptRequest req) {
  try {
    final String server = getServer();

    final RequestContext requestContext = ThreadLocalRequestContext.getRequestContext();

    final ConnectorService connService = requestContext.getServiceRegistry().getConnectorService();

    final String currentUserId = requestContext.getUserId();

    final HttpSession currentSession = ServletUtil.getSession(true);

    final Connector connector = connService.getConnector(ENDPOINT_ID, currentUserId, currentSession);

    final String alfrescoURL = "/org/redpill/alfresco/clusterprobe/settings?server=" + server;

    final Response response = connector.call(alfrescoURL);

    final String jsonResponse = response.getResponse();

    final JSONObject json = new JSONObject(new JSONTokener(jsonResponse));

    return new Settings(json.getString("text"), json.getInt("code"));
  } catch (final Exception ex) {
    LOG.error(ex.getMessage(), ex);
    final StringBuilder sb = new StringBuilder();

    StackTraceUtil.buildStackTrace(ex.getMessage(), ex.getStackTrace(), sb, 0);

    return new Settings("Couldn't get settings from repo server.\n" + sb.toString(), 500);
  }
}
 
开发者ID:Redpill-Linpro,项目名称:alfresco-cluster-probe,代码行数:34,代码来源:ProbeGet.java

示例11: getProbeSettings

import org.springframework.extensions.webscripts.connector.Response; //导入依赖的package包/类
@Override
protected Settings getProbeSettings(final WebScriptRequest req) {
  try {

    final RequestContext requestContext = ThreadLocalRequestContext.getRequestContext();

    final ConnectorService connService = requestContext.getServiceRegistry().getConnectorService();

    final String currentUserId = requestContext.getUserId();

    final HttpSession currentSession = ServletUtil.getSession(true);

    final Connector connector = connService.getConnector(ENDPOINT_ID, currentUserId, currentSession);

    final String alfrescoURL = "/org/redpill/alfresco/clusterprobe/probe";

    final Response response = connector.call(alfrescoURL);

    return new Settings(response.getResponse(), response.getStatus().getCode());
  } catch (final Exception ex) {
    LOG.error(ex.getMessage(), ex);
    final StringBuilder sb = new StringBuilder();

    StackTraceUtil.buildStackTrace(ex.getMessage(), ex.getStackTrace(), sb, 0);

    return new Settings("Couldn't get settings from repo server.\n" + sb.toString(), 500);
  }
}
 
开发者ID:Redpill-Linpro,项目名称:alfresco-cluster-probe,代码行数:29,代码来源:ProbeRepoGet.java


注:本文中的org.springframework.extensions.webscripts.connector.Response类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。