Package javax.ws.rs

Examples of javax.ws.rs.WebApplicationException


                //  For path, query & matrix parameters this is 404,
                //  for others 400...
                //
                if (pType == ParameterType.PATH || pType == ParameterType.QUERY
                    || pType == ParameterType.MATRIX) {
                    throw new WebApplicationException(nfe, Response.Status.NOT_FOUND);
                }
                throw new WebApplicationException(nfe, Response.Status.BAD_REQUEST);
            }
        }
       
        boolean adapterHasToBeUsed = false;
        Class<?> cls = pClass;       
        Class<?> valueType = JAXBUtils.getValueTypeFromAdapter(pClass, pClass, paramAnns);
        if (valueType != cls) {
            cls = valueType;
            adapterHasToBeUsed = true;
        }
       
        Object result = instantiateFromParameterHandler(value, cls, message);
        if (result != null) {
            return result;
        }
        // check constructors accepting a single String value
        try {
            Constructor<?> c = cls.getConstructor(new Class<?>[]{String.class});
            result = c.newInstance(new Object[]{value});
        } catch (NoSuchMethodException ex) {
            // try valueOf
        } catch (WebApplicationException ex) {
            throw ex;
        } catch (Exception ex) {
            result = createFromParameterHandler(value, cls, message);
            if (result == null) {
                LOG.severe(new org.apache.cxf.common.i18n.Message("CLASS_CONSTRUCTOR_FAILURE",
                                                                   BUNDLE,
                                                                   pClass.getName()).toString());
                throw new WebApplicationException(ex, HttpUtils.getParameterFailureStatus(pType));
            }
        }
        if (result == null) {
            // check for valueOf(String) static methods
            String[] methodNames = cls.isEnum()
View Full Code Here


                                                   parameter);
        LOG.severe(errorMessage.toString());
        Response r = Response.status(Response.Status.INTERNAL_SERVER_ERROR)
                         .type(MediaType.TEXT_PLAIN_TYPE)
                         .entity(errorMessage.toString()).build();
        throw new WebApplicationException(r);
    }
View Full Code Here

            Throwable t = ex instanceof InvocationTargetException
                ? ((InvocationTargetException)ex).getTargetException() : ex;
            LOG.severe(new org.apache.cxf.common.i18n.Message("CLASS_VALUE_OF_FAILURE",
                                                               BUNDLE,
                                                               pClass.getName()).toString());
            throw new WebApplicationException(t, HttpUtils.getParameterFailureStatus(pType));
        }
        return null;
    }
View Full Code Here

            try {
                method.invoke(instance, new Object[]{});
            } catch (InvocationTargetException ex) {
                String msg = "Method " + method.getName() + " can not be invoked"
                    + " due to InvocationTargetException";
                throw new WebApplicationException(Response.serverError().entity(msg).build());
            } catch (IllegalAccessException ex) {
                String msg = "Method " + method.getName() + " can not be invoked"
                    + " due to IllegalAccessException";
                throw new WebApplicationException(Response.serverError().entity(msg).build());
            }
        }
    }
View Full Code Here

        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            IOUtils.copy(is, bos, 1024);
            return new String(bos.toByteArray(), encoding);
        } catch (Exception ex) {
            throw new WebApplicationException(ex);
        }
    }
View Full Code Here

            }
            String cdName = cd == null ? null : cd.getParameter("name");
            String contentId = a.getContentId();
            String name = StringUtils.isEmpty(cdName) ? contentId : cdName.replace("\"", "").replace("'", "");
            if (StringUtils.isEmpty(name)) {
                throw new WebApplicationException(400);
            }
            if (CONTENT_DISPOSITION_FILES_PARAM.equals(name)) {
                // this is a reserved name in Content-Disposition for parts containing files
                continue;
            }
            try {
                String value = IOUtils.toString(a.getDataHandler().getInputStream());
                params.add(HttpUtils.urlDecode(name),
                           decode ? HttpUtils.urlDecode(value) : value);
            } catch (IllegalArgumentException ex) {
                LOG.warning("Illegal URL-encoded characters, make sure that no "
                    + "@FormParam and @Multipart annotations are mixed up");
                throw new WebApplicationException(415);
            } catch (IOException ex) {
                throw new WebApplicationException(415);
            }
        }
    }
View Full Code Here

            return;
        }
        try {
            int maxPartsCount = Integer.valueOf(maxPartsCountProp);
            if (maxPartsCount != -1 && numberOfParts >= maxPartsCount) {
                throw new WebApplicationException(413);
            }
        } catch (NumberFormatException ex) {
            throw new WebApplicationException(500);
        }
    }
View Full Code Here

   * @param fieldName The field name for logging
   */
  public static void assertNotNull(Object obj, String fieldName) {
    if (obj == null) {
      log.warn("Field '{}' should not be null", fieldName);
      throw new WebApplicationException(Response.Status.BAD_REQUEST);
    }
  }
View Full Code Here

   */
  public static void assertPositive(Number obj, String fieldName) {
    assertNotNull(obj, fieldName);
    if (obj.intValue() < 0) {
      log.warn("Field '{}' should be positive", fieldName);
      throw new WebApplicationException(Response.Status.BAD_REQUEST);
    }
  }
View Full Code Here

   */
  public static void assertPresent(Optional obj, String fieldName) {
    assertNotNull(obj, fieldName);
    if (!obj.isPresent()) {
      log.warn("Field '{}' should be present", fieldName);
      throw new WebApplicationException(Response.Status.BAD_REQUEST);
    }
  }
View Full Code Here

TOP

Related Classes of javax.ws.rs.WebApplicationException

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.