Package com.sun.jersey.api.container

Examples of com.sun.jersey.api.container.ContainerException


        String regex = (String)rc.getProperty(PROPERTY_WEB_PAGE_CONTENT_REGEX);
        if (regex != null && regex.length() > 0) {
            try {
                staticContentPattern = Pattern.compile(regex);
            } catch (PatternSyntaxException ex) {
                throw new ContainerException(
                        "The syntax is invalid for the regular expression, " + regex +
                        ", associated with the initialization parameter " + PROPERTY_WEB_PAGE_CONTENT_REGEX, ex);
            }
        }
View Full Code Here


            return;
        }

        if (filterContextPath != null) {
            if (!servletPath.startsWith(filterContextPath)) {
                throw new ContainerException("The servlet path, \"" + servletPath +
                        "\", does not start with the filter context path, \"" + filterContextPath + "\"");
            } else if (servletPath.length() == filterContextPath.length()) {
                // Path does not end in a slash, may need to redirect
                if (webComponent.getResourceConfig().getFeature(ResourceConfig.FEATURE_REDIRECT)) {
                    URI l = UriBuilder.fromUri(request.getRequestURL().toString()).
View Full Code Here

                m.getDispatcher(),
                m.getRequestFilters(),
                m.getResponseFilters());
       
        if (!m.getHttpMethod().equals("GET")) {
            throw new ContainerException("");
        }
       
        this.m = m;
    }
View Full Code Here

        private final DefaultResourceConfig adaptedApp;

        private ApplicationHolder(ProviderFactory pf) {
            final ComponentProvider cp = pf.getComponentProvider(appClass);
            if (cp == null) {
                throw new ContainerException("The Application class " + appClass.getName() + " could not be instantiated");
            }
            this.originalApp = (Application) cp.getInstance();

            if ((originalApp.getClasses() == null || originalApp.getClasses().isEmpty())
                    && (originalApp.getSingletons() == null || originalApp.getSingletons().isEmpty())) {
View Full Code Here

                context.getResponse().setAnnotations(annotations);
        } catch (InvocationTargetException e) {
            // Propagate the target exception so it may be mapped to a response
            throw new MappableContainerException(e.getTargetException());
        } catch (IllegalAccessException e) {
            throw new ContainerException(e);
        }
    }
View Full Code Here

        } catch (WebApplicationException e) {
            throw e;
        } catch (ContainerException e) {
            throw e;
        } catch (RuntimeException e) {
            throw new ContainerException("Exception obtaining parameters", e);
        }
    }
View Full Code Here

        if (rc == null) {
            throw new IllegalArgumentException("ResourceConfig instance MUST NOT be null");
        }

        if (initiated) {
            throw new ContainerException(ImplMessages.WEB_APP_ALREADY_INITIATED());
        }
        this.initiated = true;

        LOGGER.info("Initiating Jersey application, version '" + BuildId.getBuildId() + "'");

        // If there are components defined in jaxrs-components then
        // wrap resource config with appended set of classes
        Class<?>[] components = ServiceFinder.find("jersey-server-components").toClassArray();
        if (components.length > 0) {
            if (LOGGER.isLoggable(Level.INFO)) {
                StringBuilder b = new StringBuilder();
                b.append("Adding the following classes declared in META-INF/services/jersey-server-components to the resource configuration:");
                for (Class c : components)
                    b.append('\n').append("  ").append(c);
                LOGGER.log(Level.INFO, b.toString());
            }

            this.resourceConfig = rc.clone();
            this.resourceConfig.getClasses().addAll(Arrays.asList(components));
        } else {
            this.resourceConfig = rc;
        }

        this.provider = _provider;

        this.providerFactories = new ArrayList<IoCComponentProviderFactory>(2);

        for (Object o : resourceConfig.getProviderSingletons()) {
            if (o instanceof IoCComponentProviderFactory) {
                providerFactories.add((IoCComponentProviderFactory)o);
            }
        }

        if (_provider != null)
            providerFactories.add(_provider);

        // Set up the component provider factory to be
        // used with non-resource class components
        this.cpFactory = (providerFactories.isEmpty())
                ? new ProviderFactory(injectableFactory)
                : new IoCProviderFactory(injectableFactory, providerFactories);

        // Set up the resource component provider factory
        this.rcpFactory = (providerFactories.isEmpty())
                ? new ResourceFactory(this.resourceConfig, this.injectableFactory)
                : new IoCResourceFactory(this.resourceConfig, this.injectableFactory, providerFactories);

        // Initiate IoCComponentProcessorFactoryInitializer
        for (IoCComponentProviderFactory f : providerFactories) {
            IoCComponentProcessorFactory cpf;
            if (f instanceof IoCComponentProcessorFactoryInitializer) {
                cpf = new ComponentProcessorFactoryImpl();
                IoCComponentProcessorFactoryInitializer i = (IoCComponentProcessorFactoryInitializer)f;
                i.init(cpf);
            }

        }

        this.resourceContext = new ResourceContext() {
            @Override
            public ExtendedUriInfo matchUriInfo(URI u) throws ContainerException {
                try {
                    return handleMatchResourceRequest(u);
                } catch (ContainerException ex) {
                    throw ex;
                } catch (WebApplicationException ex) {
                    if (ex.getResponse().getStatus() == 404) {
                        return null;
                    } else {
                        throw new ContainerException(ex);
                    }
                } catch (RuntimeException ex) {
                    throw new ContainerException(ex);
                }
            }

            @Override
            public Object matchResource(URI u) throws ContainerException {
                ExtendedUriInfo ui = matchUriInfo(u);
                return (ui != null) ? ui.getMatchedResources().get(0) : null;
            }

            @Override
            public <T> T matchResource(URI u, Class<T> c) throws ContainerException, ClassCastException {
                return c.cast(matchResource(u));
            }

            @Override
            public <T> T getResource(Class<T> c) {
                return c.cast(getResourceComponentProvider(c).getInstance(context));
            }
        };

        final ProviderServices providerServices = new ProviderServices(
                ServerSide.class,
                this.cpFactory,
                resourceConfig.getProviderClasses(),
                resourceConfig.getProviderSingletons());

        injectableFactory.add(new ContextInjectableProvider<ProviderServices>(
                ProviderServices.class, providerServices));

        injectableFactory.add(new ContextInjectableProvider<ResourceMethodCustomInvokerDispatchFactory>(
                ResourceMethodCustomInvokerDispatchFactory.class, new ResourceMethodCustomInvokerDispatchFactory(providerServices)));

        // Add injectable provider for @ParentRef
        injectableFactory.add(
                new InjectableProvider<ParentRef, Type>() {
                    @Override
                    public ComponentScope getScope() {
                        return ComponentScope.PerRequest;
                    }

                    @Override
                    public Injectable<Object> getInjectable(ComponentContext cc, ParentRef a, Type t) {
                        if (!(t instanceof Class))
                            return null;

                        final Class target = ReflectionHelper.getDeclaringClass(cc.getAccesibleObject());
                        final Class inject = (Class)t;
                        return new Injectable<Object>() {
                            @Override
                            public Object getValue() {
                                final UriInfo ui = context.getUriInfo();
                                final List l = ui.getMatchedResources();

                                final Object parent = getParent(l, target);
                                if (parent == null) return null;
                                try {
                                    return inject.cast(parent);
                                } catch (ClassCastException ex) {
                                    throw new ContainerException(
                                            "The parent resource is expected to be of class " + inject.getName() +
                                                    " but is of class " + parent.getClass().getName(),
                                            ex);
                                }
                            }
View Full Code Here

            }
        } catch (InvocationTargetException e) {
            // Propagate the target exception so it may be mapped to a response
            throw new MappableContainerException(e.getTargetException());
        } catch (IllegalAccessException e) {
            throw new ContainerException(e);
        } catch (WebApplicationException e) {
            throw e;
        } catch (RuntimeException e) {
            throw new ContainerException("Exception injecting parameters for sub-locator method: " + m, e);
        }
    }
View Full Code Here

                            return u.unmarshal(source, type).getValue();
                        }
                    } catch (UnmarshalException ex) {
                        throw new ExtractorContainerException(ImplMessages.ERROR_UNMARSHALLING_JAXB(type), ex);
                    } catch (JAXBException ex) {
                        throw new ContainerException(ImplMessages.ERROR_UNMARSHALLING_JAXB(type), ex);
                    } catch (Exception ex) {
                        throw new ContainerException(ImplMessages.ERROR_UNMARSHALLING_JAXB(type), ex);
                    }
                }
            };
        }
View Full Code Here

                throw (WebApplicationException)target;
            } else {
                throw new ExtractorContainerException(target);
            }
        } catch (RuntimeException ex) {
            throw new ContainerException(ex);
        } catch (Exception ex) {
            throw new ContainerException(ex);
        }
    }
View Full Code Here

TOP

Related Classes of com.sun.jersey.api.container.ContainerException

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.