Package org.wymiwyg.wrhapi

Examples of org.wymiwyg.wrhapi.HandlerException


    Date moment = null;
    String[] momentParameterStrings = request.getRequestURI()
        .getParameterValues("moment");
    if (momentParameterStrings != null) {
      if (momentParameterStrings.length != 1) {
        throw new HandlerException(
            "only one get parameter \"moment\" supported");
      }
      String momentString = momentParameterStrings[0];
      String datePattern = "yyyyMMddHHmmssSSS";
      try {
        SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern
            .substring(0, momentString.length()));
        dateFormat.setTimeZone(utcTZ);
        moment = dateFormat.parse(momentString);
      } catch (ParseException e) {
        throw new HandlerException(e);
      }
      ;
    }
    if (moment == null) {
      moment = new Date();
View Full Code Here


      String passwordSha1 = Util.sha1(password);
      String mboxSha1 = Util.sha1("mbox" + email);
      Resource user = getUserByUsername(username);
      if (user != null) {
        if (!user.hasProperty(FOAF.mbox_sha1sum, mboxSha1)) {
          throw new HandlerException(
              "user already exists with a differen email address");
        } else {
          log
              .info("Username/Email combination exist, will delete exitisting on confirmation");
        }
      }

      LoginData loginData = new LoginData(username, passwordSha1,
          mboxSha1);
      String verificationKey = Util.createRandomString(28);
      verificationMap.put(verificationKey, loginData);
      log.info("sending login link to " + email);
      loginLinkSender.sendLoginLink(email, getVerificationLink(request,
          verificationKey));
      response.setResponseStatus(ResponseStatus.MOVED_TEMPORARILY);
      response.setHeader(HeaderName.LOCATION,
          "/application/verification-sent");
    } else {
      String[] verificationParameters = request.getRequestURI()
          .getParameterValues("verification");
      if (verificationParameters != null) {
        if (verificationParameters.length == 1) {
          LoginData loginData = verificationMap
              .get(verificationParameters[0]);
          if (loginData == null) {
            throw new HandlerException(
                "Verification string not found, probably expired");
          }
          Graph graph = new SimpleGraph();
          addUser(loginData, graph, request);
          response
              .setDefaultStylesheet("/application/stylesheets/verification-result");
          response.setBody(graph);
          Resource user = getUserByUsernameInIdentityGOT(loginData.userName);
          FCAGraph revokeGraphTmp = null;
          if (user != null) {
            log
                .info("Username already exist, removing previous password");
            Model revokeModel = ModelFactory.createDefaultModel();
            revokeModel.add(user
                .listProperties(ACCOUNTMANAGER.passwordSha1));
            revokeModel.add(user.listProperties(FOAF.mbox_sha1sum));
            revokeModel.add(user
                .listProperties(ACCOUNTMANAGER.userName));
            revokeGraphTmp = new FCAGraphImpl(revokeModel);
            // store.revokeGraph(identity, new
            // FCAGraphImpl(revokeModel), now);
          }
          final FCAGraph revokeGraph = revokeGraphTmp;
          final FCAGraph assertGraph = new FCAGraphImpl(graph);
          // store.assertGraph(identity, new FCAGraphImpl(graph),
          // now);
          store.perform(identity, new StoreTransaction() {

            public void execute(SourceStoreView storeView) {
              if (revokeGraph != null)
                storeView.revokeGraph(revokeGraph);
              storeView.assertGraph(assertGraph);
            }

          });
        } else {
          throw new HandlerException(
              "Invalid request: needs exactly one verification-parameter");
        }
      } else {
        // login
        if (!loginValid(username, password)) {
View Full Code Here

  private String getHost(Request request) throws HandlerException {
    String host;
    try {
      host = request.getHeaderValues(HeaderName.HOST)[0];
    } catch (ArrayIndexOutOfBoundsException e) {
      throw new HandlerException("No host header");
    }

    int colonPos = host.indexOf(':');

    if (colonPos != -1) {
View Full Code Here

        return;
      } else {
        currentBrowseNode = currentBrowseNode.getSubPath(currentToken);
      }
    }
    throw new HandlerException(ResponseStatus.NOT_FOUND, "file "+path+" not found");

  }
View Full Code Here

        return false;
      }
    });
    //childStrings is null if the directory doesn't exist
    if ((childStrings == null) || (childStrings.length == 0)) {
      throw new HandlerException(ResponseStatus.NOT_FOUND, "file "+baseName+" not found");
    }
    // TODO content negotiation
    String fileName = childStrings[0];
    MimeType mimeType = MediaTypesUtil.getDefaultInstance().getTypeForExtension(getExtension(fileName));
    if (mimeType != null) {
      response.addHeader(HeaderName.CONTENT_TYPE, mimeType.toString());
    }
    PathNode resultNode = pathNode.getSubPath(fileName);
    final InputStream dataInputStream;
    try {
      //log.info("getting stream from"+fileName+" in "+pathNode+"("+resultNode+")");
      dataInputStream = resultNode.getInputStream();
    } catch (IOException e) {
      throw new HandlerException(e);
    }
    response.setBody(new MessageBody2Read() {

      public ReadableByteChannel read() throws IOException {
        return Channels.newChannel(dataInputStream);
View Full Code Here

    Model bodyModel = ModelFactory.createDefaultModel();
    try {
      bodyModel.read(Channels.newInputStream(request.getMessageBody()
          .read()), source.getURIRef());
    } catch (Exception e) {
      throw new HandlerException(e);
    }
    final FCAGraph graph = new FCAGraphImpl(bodyModel);
    if (resourceURIStrings != null) {

      final Set<GroundedNode> onlyForGroundedNodes = new HashSet<GroundedNode>(
View Full Code Here

          logger.info("AccessControlException (will rethrow)", exception);
        }
        throw (RuntimeException) exception;
      }
      logger.warn("Exception (with no exception mapper)", exception);
      throw new HandlerException(exception);
    }
  }
View Full Code Here

        countParameters = count; //update max parameters size found so far
      }
    }

    if (constructor == null) {
      throw new HandlerException(
          "No constructor found for resource class: " + resourceClass.getName());
    }

    logger.debug("Constructor found, injecting parameters...");

    Class<?>[] parameterClasses = constructor.getParameterTypes();
    boolean encodingDisabledForConstructor = encodingDisabled
        || (constructor.getAnnotation(Encoded.class) != null);
    Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();
    Object[] parameters = new Object[parameterClasses.length];

    for (int i = 0; i < parameterClasses.length; i++) {

      Annotation[] as = parameterAnnotations[i];

      if (as.length == 0) {
        //TODO make sure another constructor is tried
        throw new HandlerException(
            "Class has constructor with arguments we cannot unterstand: " +
            "(the parameter of type " + parameterClasses[i]
            + " has no annotation)");
      }

      Object paramValue = getInjectionValueForAnnotation(request,
          pathParams, providers, as,
          parameterClasses[i], encodingDisabledForConstructor);
      parameters[i] = paramValue;
    }
   
   
    logger.debug("Calling constructor {} with parameters: {}", constructor, parameters);
    try {
      instance = constructor.newInstance(parameters);
    } catch (Exception e) {
      throw new HandlerException("Error in initializing: " + e, e);
    }
    injectFields(request, pathParams, providers, instance);

    return instance;
  }
View Full Code Here

          fields[i].getType(), encodingDisabledForField);
      if (fieldValue != null) {
        try {
          fields[i].set(instance, fieldValue);
        } catch (IllegalAccessException iae) {
          throw new HandlerException("setting "+fields[i]+" to "+fieldValue, iae);
        }
        logger.debug("set field value: {} to {}", fields[i], fieldValue);
      }
    }

    logger.debug("Fields checked.");

    // check setter methods
    for (Method method : MethodUtil.getAnnotatedMethods(resourceClass)){
     
      int searchMod = Modifier.PUBLIC;
      int mods = accessModifiers(method.getModifiers());
      boolean modMatch = (searchMod == mods);

      if ((method.getName().startsWith("set")) && (modMatch)
          && (method.getParameterTypes().length == 1)
          && (method.getReturnType().equals(Void.TYPE))) {
       
        logger.debug("Method {} is a setter.", method);

        Annotation[] as = method.getAnnotations();
        if (as.length == 0) {
          continue;
        }
       
        boolean encodingDisabledForSetter = encodingDisabled
            || (method.getAnnotation(Encoded.class) != null);
        final Object value = getInjectionValueForAnnotation(request,
            pathParams, providers, as,
            method.getGenericParameterTypes()[0],
            encodingDisabledForSetter);

        if (value == null) {
          continue;
        }

        Object[] valuesToSet = {value};

        try {
          method.invoke(instance, valuesToSet);
        } catch (IllegalAccessException illegalAccessException) {
          throw new HandlerException(illegalAccessException);
        } catch (IllegalArgumentException illegalArgumentException) {
          throw new HandlerException(illegalArgumentException);
        } catch (InvocationTargetException invocationTargetException) {
          throw new HandlerException(invocationTargetException);
        }
      }
    }
  }
View Full Code Here

      Set<MediaType> methodProducibleMediaTypes = processableResponse.getMethodProducibleTypes();

      processJaxResponse(request, response, processableResponse, annotations,
          methodProducibleMediaTypes);
    } catch (IOException ex) {
      throw new HandlerException(ex);
    }

  }
View Full Code Here

TOP

Related Classes of org.wymiwyg.wrhapi.HandlerException

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.