Package com.ibm.commons.util.io.json

Examples of com.ibm.commons.util.io.json.JsonObject


    }

    try {
      // populate list of endpoint/properties
      Map<String, JsonObject> endpoints = populateEndpoints(request);
      JsonObject properties = populateProperties(request);
      minify = !request.isDebug();
      nl = minify ? "" : NL;
      // write response
      HttpServletResponse response = request.getHttpResponse();
      PrintWriter writer = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), UTF8));
View Full Code Here


        if (endpointAlias == null) {
          endpointAlias = endpointName;
        }

        Endpoint theEndpoint = EndpointFactory.getEndpointUnchecked(endpointName);
        JsonObject jsonEndpoint = createJsonForEndpoint(request, theEndpoint, endpointAlias, endpointName);
        jsonEndpoints.put(endpointAlias, jsonEndpoint);
      }
    }

    if (logger.isLoggable(Level.FINEST)) {
View Full Code Here

  protected JsonObject populateProperties(LibraryRequest request) throws ServletException, IOException {
    if (logger.isLoggable(Level.FINEST)) {
      logger.entering(sourceClass, "populateProperties", request);
    }

    JsonObject jsonProperties = new JsonJavaObject();
    // add the built-in properties
    jsonProperties.putJsonProperty(PROP_TOOLKIT_URL, addMakeAbsoluteUrl(request.getToolkitJsUrl()));
    jsonProperties.putJsonProperty(PROP_SERVICE_URL, addMakeAbsoluteUrl(request.getServiceUrl()));
    jsonProperties.putJsonProperty(PROP_LIBRARY_URL, addMakeAbsoluteUrl(request.getLibraryUrl()));

    // add the requested properties
    Property[] properties = request.getEnvironment().getPropertiesArray();
    if (properties != null) {
        Context context = Context.get();
      for (Property property : properties) {
        String value = property.getValue();
        if (StringUtil.isEmpty(value)) {
          value = context.getProperty(property.getName());
        }
        if (value != null) {
          jsonProperties.putJsonProperty(property.getName(), value);
        }
      }
    }

    if (logger.isLoggable(Level.FINEST)) {
View Full Code Here

    if (logger.isLoggable(Level.FINEST)) {
      logger.entering(sourceClass, "createJsonForEndpoint", new Object[] { request, endpoint,
          endpointAlias, endpointName });
    }

    JsonObject jsonEndpoint = new JsonJavaObject();

    // use the base url from the endpoint
    if (isValid(request, endpoint)) {
      // set the endpoint api version
      String apiVersion = endpoint.getApiVersion();
      if (StringUtil.isNotEmpty(apiVersion)) {
        jsonEndpoint.putJsonProperty(PROP_API_VERSION, apiVersion);
      }
      jsonEndpoint.putJsonProperty(PROP_ENDPOINT_ALIAS, endpointAlias);
      // set the endpoint url
      jsonEndpoint.putJsonProperty(PROP_BASE_URL, endpoint.getUrl());
      try {
        jsonEndpoint.putJsonProperty(IS_AUTHENTICATED, endpoint.isAuthenticated());
      } catch (ClientServicesException e) {
        jsonEndpoint.putJsonProperty(IS_AUTHENTICATED, false);
      }
     
      jsonEndpoint.putJsonProperty(PROP_SERVICE_MAPPINGS, endpoint.getServiceMappings());

      // configure endpoint to use proxy
      if (endpoint.isUseProxy()) {
        JsonReference proxyRef = createProxyRef(request, endpoint, endpointName);
        if (proxyRef != null) {
          jsonEndpoint.putJsonProperty(PROP_PROXY, proxyRef);
          String moduleName = getProxy(request, endpoint, endpointName).getModuleName();
          jsonEndpoint.putJsonProperty(PROP_MODULE_PROXY, moduleName);
        }
        String proxyPath = endpoint.getProxyPath(endpointName);
        if (!StringUtil.isEmpty(proxyPath)) {
          jsonEndpoint.putJsonProperty(PROP_PROXY_PATH, proxyPath);
        }
      }

      // configure endpoint to use authenticator
      JsonReference authenticatorRef = createAuthenticatorRef(request, endpoint, endpointName);
      if (authenticatorRef != null) {
        jsonEndpoint.putJsonProperty(PROP_AUTHENTICATOR, authenticatorRef);
        String moduleName = endpoint.getAuthenticator(endpointName, request.getToolkitJsUrl()).getModuleName();
        jsonEndpoint.putJsonProperty(PROP_MODULE_AUTHENTICATOR, moduleName);
      }

      // configure the transport
      JsonReference transportRef = createTransportRef(request, endpoint, endpointName);
      if (transportRef != null) {
        jsonEndpoint.putJsonProperty(PROP_TRANSPORT, transportRef);
        String moduleName = getTransport(request, endpoint, endpointName).getModuleName();
        jsonEndpoint.putJsonProperty(PROP_MODULE_TRANSPORT, moduleName);
      }

      // configure the authentication
      jsonEndpoint.putJsonProperty(PROP_AUTH_TYPE, AuthUtil.INSTANCE.getAuthValue(endpoint));
      if (endpoint.getLoginPage() != null) {
        jsonEndpoint.putJsonProperty(PROP_LOGIN_PAGE, endpoint.getLoginPage());
      }
      if (endpoint.getDialogLoginPage() != null) {
        jsonEndpoint.putJsonProperty(PROP_LOGIN_DIALOG_PAGE, endpoint.getDialogLoginPage());
      }
      if (endpoint.getLoginUi() != null) {
        jsonEndpoint.putJsonProperty(PROP_LOGIN_UI, endpoint.getLoginUi());
      }
      if (endpoint.getAutoAuthenticate() != null) {
        jsonEndpoint.putJsonProperty(PROP_AUTO_AUTHENTICATE, endpoint.getAutoAuthenticate());
      }
      if (endpoint.getPlatform() != null) {
        jsonEndpoint.putJsonProperty(PROP_PLATFORM, endpoint.getPlatform());
      }
      jsonEndpoint.putJsonProperty(PROP_AUTHENTICATION_ERROR_CODE,
          endpoint.getAuthenticationErrorCode());
     
      // configure client properties
      Map<String, Object> params = endpoint.getClientParams();
      Iterator<String> keys = params.keySet().iterator();
      while(keys.hasNext()) {
        String key = keys.next();
        Object value = params.get(key);
        jsonEndpoint.putJsonProperty(key, value);
      }

    } else {
      // set the endpoint url
      jsonEndpoint.putJsonProperty(PROP_INVALID, "true");

      // configure a error transport
      String message = getInvalidEndpointMessage(request, endpoint, endpointName);
      jsonEndpoint.putJsonProperty(PROP_TRANSPORT, new JsonReference("new ErrorTransport('"
          + endpointName + "','" + message + "')"));
    }

    if (logger.isLoggable(Level.FINEST)) {
      logger.exiting(sourceClass, "createJsonForEndpoint", jsonEndpoint);
View Full Code Here

      Iterator<Map.Entry<String, JsonObject>> entrySet = endpoints.entrySet().iterator();
      indentationLevel++;
      while (entrySet.hasNext()) {
        Map.Entry<String, JsonObject> entry = entrySet.next();
        String name = entry.getKey();
        JsonObject endpoint = entry.getValue();
        JsonObject endpointParams = removeModuleProperties(endpoint);
        indent(sb, indentationLevel).append("'").append(toJavaScriptString(name))
            .append("':new Endpoint(").append(toJson(endpointParams)).append(")");
        if (entrySet.hasNext()) {
          sb.append(",").append(newLine());
        } else {
View Full Code Here

   *
   * @param jsonObject
   * @return
   */
  protected JsonObject removeModuleProperties(JsonObject jsonObject) {
    JsonObject params = new JsonJavaObject();
    Iterator<String> properties = jsonObject.getJsonProperties();
    while (properties.hasNext()) {
      // add regular properties
      String property = properties.next();
      if (!property.startsWith(PROP_MODULE_PREFIX)) {
        params.putJsonProperty(property, jsonObject.getJsonProperty(property));
      }
    }
    return params;
  }
View Full Code Here

  @Override
  public void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    String pathInfo = request.getPathInfo();
      Endpoint endpoint = EndpointFactory.getEndpoint(getEndpointName(pathInfo))//remove hardcoded name ..get second token from path info
      PrintWriter writer = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "utf-8"));
    JsonObject jsonResponse = new JsonJavaObject();
      if(getAuthAction(pathInfo).equals(LOG_OUT)){
        boolean logoutSuccessful = true;
        try {
        endpoint.logout();
      } catch (AuthenticationException e) {
        logoutSuccessful = false;
      }
      try {
        if(endpoint.isAuthenticated()){
          logoutSuccessful = false;
        }
      } catch (ClientServicesException e) {
        logoutSuccessful = false;
      }
      if(logoutSuccessful){
        jsonResponse.putJsonProperty("success", true);
        jsonResponse.putJsonProperty("status", 200);
      }else{
        jsonResponse.putJsonProperty("success", false);
        jsonResponse.putJsonProperty("status", 500);
      }
      }
      if(getAuthAction(pathInfo).equals(IS_AUTHENTICATED)){
        try {
          jsonResponse.putJsonProperty("result", endpoint.isAuthenticated());
          jsonResponse.putJsonProperty("status", 200);
        } catch (ClientServicesException e) {
          jsonResponse.putJsonProperty("result", false);
          jsonResponse.putJsonProperty("status", 500);
        }
      }
      if(getAuthAction(pathInfo).equals(IS_AUTHENTICATION_VALID)){
      try {
        jsonResponse.putJsonProperty("result", endpoint.isAuthenticationValid());
        jsonResponse.putJsonProperty("status", 200);
      } catch (ClientServicesException e) {
        jsonResponse.putJsonProperty("result", false);
        jsonResponse.putJsonProperty("status", 500);
      }
  }
        response.setContentType(APPLICATION_JSON);
        writer.write(jsonResponse.toString());
      writer.flush();
  }
View Full Code Here

      return repositoryId;
    }
   
  private String getRepositoryId(String repositoryUrl) throws ClientServicesException {
    Response response = endpoint.getClientService().get(repositoryUrl, ClientService.FORMAT_JSON);
    JsonObject result = (JsonObject) response.getData() ;
    JsonObject entry = (JsonObject) result.getJsonProperty("entry");
    if(entry != null) {
      String repId = (String) ((JsonObject)result.getJsonProperty("entry")).getJsonProperty("id");
      if(StringUtil.isNotEmpty(repId)) {
        repId = "p!" + repId.substring("urn:lsid:lconn.ibm.com:profiles.person:".length());
      }
View Full Code Here

    public void testMimeEmailJson() throws Exception {
        List<JsonObject> eeMimeParts = new ArrayList<JsonObject>();
        eeMimeParts.add(jsonTextPart);
        eeMimeParts.add(jsonHtmlPart);
        eeMimeParts.add(jsonEEPart);
        JsonObject json = new JsonJavaObject();
        json.putJsonProperty(MimeEmail.MIME_PARTS, eeMimeParts);
        new DefaultMimeEmail(json).send();
    }
View Full Code Here

        new MimePart(new JsonJavaObject());
    }
   
    @Test (expected = MimeEmailException.class)
    public void testMimePartJsonNonString() throws Exception {
        JsonObject json = new JsonJavaObject();
        json.putJsonProperty(MimePart.MIME_TYPE, 123);
        new MimePart(json);
    }
View Full Code Here

TOP

Related Classes of com.ibm.commons.util.io.json.JsonObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.