Examples of HandlerException


Examples of org.wymiwyg.wrhapi.HandlerException

    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

Examples of org.wymiwyg.wrhapi.HandlerException

          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

Examples of org.wymiwyg.wrhapi.HandlerException

        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

Examples of org.wymiwyg.wrhapi.HandlerException

          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

Examples of org.wymiwyg.wrhapi.HandlerException

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

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

  }
View Full Code Here

Examples of org.wymiwyg.wrhapi.HandlerException

    if (uri != null) {
      try {
        //try to create a new resource itemOrTopic
        itemOrTopic = model.createResource(new URL(baseURL, uri).toString());
      } catch (MalformedURLException e) {
        throw new HandlerException(e);
      }
    }
   
    //retrieve parameters from body:
   
    String language = requestBody.getParameter("language");
    String title = requestBody.getParameter("title");
    String summary = requestBody.getParameter("description");
    if (!"yes".equals(requestBody.getParameter("custom_summary"))) {
      summary = null;
    }
    String creator = requestBody.getParameter("creator");
    String date = requestBody.getParameter("date");
    String content = requestBody.getParameter("body");
   
    String[] permissions = requestBody.getParameterValues("permission");
    String[] maxShowInlineLength = requestBody.getParameterValues("maxShowInlineLength");
    if ((maxShowInlineLength != null) && (maxShowInlineLength.length > 0)) {
      Literal maxShowInlineLengthLiteral = model.createTypedLiteral(maxShowInlineLength[0], XSDDatatype.XSDdecimal);
      itemOrTopic.removeAll(KNOBOT.maxShowInlineLength);
      itemOrTopic.addProperty(KNOBOT.maxShowInlineLength, maxShowInlineLengthLiteral);
    }
    addPermissions(itemOrTopic, permissions);
    //shop
    boolean shop = "checked".equals(requestBody.getParameter("shop"));
    String priceString = requestBody.getParameter("price");
    String articleID = requestBody.getParameter("articleID");
    boolean commentable = "yes"
        .equals(requestBody.getParameter("comments"));
    float price = 0;
    if ((priceString != null) && (!priceString.equals(""))) {
      price = Float.parseFloat(priceString);
    }
   
    //custom shipping costs parameter (has to be float):
    String customShippingCostsString = requestBody.getParameter("customShippingCosts");
    String useDefaultShippingCosts = requestBody.getParameter("useShippingCosts");
    float customShippingCosts = 0;
    if ((customShippingCostsString != null) && (!customShippingCostsString.equals(""))) {
      customShippingCosts = Float.parseFloat(customShippingCostsString);
    }
   

   
    summary = tidy(summary);
    content = tidy(content);
   

    try {
      deletePropertiesByLanguage(itemOrTopic, RSS.title, language);
    } catch (Exception ex) {
    }
    try {
      deletePropertiesByLanguage(itemOrTopic, RSS.description, language);
    } catch (Exception ex) {
    }
    try {
      deletePropertiesByLanguage(itemOrTopic, CONTENT.encoded, language);
    } catch (Exception ex) {
    }
    try {
      // the author may want to write his name differently in different
      // languages
      deletePropertiesByLanguage(itemOrTopic, DC.creator, language);
    } catch (Exception ex) {
    }
    try {
      itemOrTopic.getProperty(DC.date).remove();
    } catch (Exception ex) {
    }
    if ((language == null) || (language.equals(""))) {
      throw new HandlerException("must specify a language");
    }
    model
        .createStatement(
            itemOrTopic,
            RDF.type,
View Full Code Here

Examples of org.wymiwyg.wrhapi.HandlerException

    Date[] eventStartDts;
    try {
      eventStartDts = getDateTimes(eventStartDateStrings,
          eventStartTimeStrings);
    } catch (ParseException e) {
      throw new HandlerException("Invalid start date", e);
    }
    Date[] eventEndDts;
    try {
      eventEndDts = getDateTimes(eventEndDateStrings, eventEndTimeStrings);
    } catch (ParseException e) {
      throw new HandlerException("Invalid start date", e);
    }
   
    Map existingMap = getExistingEventsMap(target);
    Set newEventSet = new HashSet();
    target.removeAll(KNOBOT.announcesEvent);
View Full Code Here

Examples of org.wymiwyg.wrhapi.HandlerException

        if (originalUrls[i] != null) {
          try {
            originalUrls[i] = new URL(baseURL, originalUrls[i])
                .toString();
          } catch (MalformedURLException e) {
            throw new HandlerException(e);
          }
        }
      }
      Collection originalUrlCol = Arrays.asList(originalUrls);
      Map originalLabelsMap = new HashMap();
      // this contains langugage specific attachments in other languages
      // as value and their poisition-Integer as key.
      Map untouchedAttachments = new HashMap();

      Statement attachStmt = target.getProperty(ATTACH.attachments);
      if (attachStmt != null) {
        Seq attachSeq = attachStmt.getSeq();
        for (int i = 1; i <= attachSeq.size(); i++) {
          Resource currentAttachment;
          try {
            currentAttachment = attachSeq.getResource(i);
          } catch (PropertyNotFoundException ex) {
            log.warn("Inncosistent sequence of attachment");
            fixSeq(attachSeq);
            i--;
            continue;
          }
          Statement languageStmt = currentAttachment
              .getProperty(DC.language);
          if ((languageStmt == null)
              || (languageStmt.getString().equals(language))) {
            String currentDocumentURL = currentAttachment
                .getProperty(ATTACH.document).getResource()
                .getURI();
            if (originalUrlCol.contains(currentDocumentURL)) {
              StmtIterator labelStmts = currentAttachment
                  .listProperties(RDFS.label);
              Collection otherLangLabels = new ArrayList();
              while (labelStmts.hasNext()) {
                Statement current = labelStmts.nextStatement();
                Literal value = current.getLiteral();
                if (!language.equals(value.getLanguage())) {
                  otherLangLabels.add(value);
                }
              }
              originalLabelsMap
                  .put(
                      currentDocumentURL,
                      otherLangLabels
                          .toArray(new Literal[otherLangLabels
                              .size()]));
              // TODO put in map of attachments to update
            }
            currentAttachment.removeProperties();

          } else {
            // remove attachment from sequence anyway and re-insert
            // it at the end at the best position
            // best position: for the moment the same index if
            // available in the new seq.
            untouchedAttachments.put(new Integer(i),
                currentAttachment);
          }
          attachSeq.remove(i--);
        }
      }
      // for every attachment
      String[] attachmentPositions = requestBody
          .getParameterValues("attachment_position");
      String[] attachmentTypes = requestBody
          .getParameterValues("attachment_type");
      String[] attachmentLabels = requestBody
          .getParameterValues("attachment_label");
      String[] attachmentWidths = requestBody
          .getParameterValues("attachment_width");
      String[] attachmentHeights = requestBody
          .getParameterValues("attachment_height");
      String[] attachmentMode = requestBody
          .getParameterValues("attachment_mode");
      String[] languageSpecific = requestBody
          .getParameterValues("attachment_language_specific");
      String[] summmaryViews = requestBody
          .getParameterValues("attachment_summary_view");
      // for url-attachments
      String[] attachmentURLs = requestBody
          .getParameterValues("attachment_url");
      String[] urlAttachmentContentTypes = requestBody
          .getParameterValues("attachment_contenttype");
      // for upload-attachments
      byte[][] attachmentContent = requestBody
          .getFileContents("attachment_file");
      String[] fileNames = requestBody.getFileNames("attachment_file");
      MimeType[] fileContentTypes = requestBody
          .getFileContentTypes("attachment_file");

      // int urlIter = 0;
      // int fileIter = 0;
      SortedSet attachmentsSet = new TreeSet();
      // Attachment[] attachments = new
      // Attachment[attachmentTypes.length];
      for (int i = 0; i < attachmentTypes.length; i++) {
        int position = Integer.parseInt(attachmentPositions[i]);
        if (position == -1) {
          continue;
        }
        String currentType = attachmentTypes[i];
        int width, height;
        try {
          width = Integer.parseInt(attachmentWidths[i]);
          height = Integer.parseInt(attachmentHeights[i]);
        } catch (NumberFormatException ex) {
          width = -1;
          height = -1;
        }
        Literal[] existingLabel = (Literal[]) originalLabelsMap
            .get(originalUrls[i]);
        Literal[] labels;
        if (existingLabel != null) {
          labels = new Literal[existingLabel.length + 1];
          System.arraycopy(existingLabel, 0, labels, 0,
              existingLabel.length);
        } else {
          labels = new Literal[1];
        }
        labels[labels.length - 1] = model.createLiteral(
            attachmentLabels[i], language);
        String attachmentLanguage;
        if (languageSpecific[i].equals("true")) {
          attachmentLanguage = language;
        } else {
          attachmentLanguage = null;
        }

        if ((currentType != null) && (currentType.equals("url"))) {
          if ((attachmentURLs[i] != null)
              && (!attachmentURLs[i].equals(""))) {
            URL attachmnetTargetURL;
            try {
              attachmnetTargetURL = new URL(baseURL,
                  attachmentURLs[i]);
            } catch (MalformedURLException e) {
              throw new RuntimeException(e);
            }

            MimeType mimeType;
            if ((urlAttachmentContentTypes[i] != null)
                && (!urlAttachmentContentTypes[i].equals(""))) {
              try {
                mimeType = new MimeType(
                    urlAttachmentContentTypes[i]);
              } catch (MimeTypeParseException e) {
                throw new HandlerException("Invalid MimeType",
                    e);
              }
            } else {
              mimeType = null;
            }
            attachmentsSet.add(new Attachment(labels,
                attachmnetTargetURL, mimeType, width, height,
                attachmentMode[i].equals("inline"),
                attachmentLanguage, position, summmaryViews[i]
                    .equals("true")));
            /*
             * Resource attachmentTarget =
             * model.createResource(attachmnetTargetURL.toString());
             * ItemUtil.addAttachment(target, attachmentTarget,
             * urlAttachmentContentTypes[i], attachmentLabels[i],
             * width, height, attachmentMode[i].equals("inline"));
             */
          }
          // urlIter++;

        } else {
          if ((attachmentContent != null)
              && (attachmentContent[i] != null)
              && (attachmentContent[i].length > 0)) {
            String fileName = fileNames[i];
            MimeType mimeType;
            mimeType = fileContentTypes[i];
            try {
              attachmentsSet.add(new Attachment(model, hashStore,
                  new URL(target.getURI()), labels,
                  attachmentContent[i], fileName, mimeType,
                  width, height, attachmentMode[i]
                      .equals("inline"),
                  attachmentLanguage, position,
                  summmaryViews[i].equals("true"),
                  permissions));
              /*
               * ItemUtil.addAttachment(target,
               * attachmentContent[i], fileNames[i],
               * fileContentTypes[i], attachmentLabels[i], width,
               * height, attachmentMode[i].equals("inline"));
               */
            } catch (IOException e) {
              throw new HandlerException(e);
            }
          }
          // fileIter++;
        }
      }
View Full Code Here

Examples of org.wymiwyg.wrhapi.HandlerException

      response.setResponseStatus(ResponseStatus.getInstanceByCode(responseCode));
      if (responseCode == ResponseStatus.SUCCESS.getCode()) {
        response.setBody(connection.getInputStream());
      }
    } catch (MalformedURLException e) {
      throw new HandlerException(e);
    } catch (IOException e) {
      throw new HandlerException(e);
    }
   
  }
View Full Code Here

Examples of org.wymiwyg.wrhapi.HandlerException

            final PipedInputStream pipedIn = new PipedInputStream();
            final PipedOutputStream pipedOut;
            try {
                pipedOut = new PipedOutputStream(pipedIn);
            } catch (IOException e) {
                throw new HandlerException(e);
            }

            transformingThread = new Thread() {
                public void run() {
                 
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.