Examples of CallContext


Examples of org.apache.cloudstack.context.CallContext

    @Override
    @ActionEvent(eventType = EventTypes.EVENT_VM_DESTROY, eventDescription = "destroying Vm", async = true)
    public UserVm destroyVm(DestroyVMCmd cmd)
            throws ResourceUnavailableException, ConcurrentOperationException {
        CallContext ctx = CallContext.current();
        long vmId = cmd.getId();
        boolean expunge = cmd.getExpunge();

        if (!_accountMgr.isAdmin(ctx.getCallingAccount().getType()) && expunge) {
            throw new PermissionDeniedException("Parameter " + ApiConstants.EXPUNGE + " can be passed by Admin only");
        }

        UserVm destroyedVm = destroyVm(vmId);
        if (expunge) {
            UserVmVO vm = _vmDao.findById(vmId);
            if (!expunge(vm, ctx.getCallingUserId(), ctx.getCallingAccount())) {
                throw new CloudRuntimeException("Failed to expunge vm " + destroyedVm);
            }
        }

        return destroyedVm;
View Full Code Here

Examples of org.apache.cloudstack.context.CallContext

    public void finalizeStop(VirtualMachineProfile profile, Answer answer) {
        VirtualMachine vm = profile.getVirtualMachine();
        // release elastic IP here
        IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId());
        if (ip != null && ip.getSystem()) {
            CallContext ctx = CallContext.current();
            try {
                long networkId = ip.getAssociatedWithNetworkId();
                Network guestNetwork = _networkDao.findById(networkId);
                NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, guestNetwork.getNetworkOfferingId());
                assert (offering.getAssociatePublicIP() == true) : "User VM should not have system owned public IP associated with it when offering configured not to associate public IP.";
                _rulesMgr.disableStaticNat(ip.getId(), ctx.getCallingAccount(), ctx.getCallingUserId(), true);
            } catch (Exception ex) {
                s_logger.warn(
                        "Failed to disable static nat and release system ip "
                                + ip + " as a part of vm "
                                + profile.getVirtualMachine()
View Full Code Here

Examples of org.jboss.seam.remoting.CallContext

   @Test
   public void testBagWrapper() throws Exception
   {
      BagWrapper wrapper = new BagWrapper();
      wrapper.setCallContext(new CallContext());

      String[] values = new String[2];
      values[0] = "foo";
      values[1] = "bar";
View Full Code Here

Examples of org.jboss.seam.remoting.CallContext

   @Test
   public void testMapWrapper() throws Exception
   {
      MapWrapper wrapper = new MapWrapper();
      wrapper.setCallContext(new CallContext());

      // Construct a map with two elements, foo:aaaaa and bar:zzzzz
      Element e = DocumentFactory.getInstance().createElement("map");
      Element child = e.addElement("element");
      child.addElement("k").addElement("str").addText("foo");
      child.addElement("v").addElement("str").addText("aaaaa");
      child = e.addElement("element");
      child.addElement("k").addElement("str").addText("bar");
      child.addElement("v").addElement("str").addText("zzzzz");

      wrapper.setElement(e);

      // Conversion tests
      Map m = (Map) wrapper.convert(Map.class);
      assert m.containsKey("foo");
      assert m.containsKey("bar");
      assert "aaaaa".equals(m.get("foo"));
      assert "zzzzz".equals(m.get("bar"));

      m = (Map) wrapper.convert(HashMap.class);
      assert m.containsKey("foo");
      assert m.containsKey("bar");
      assert "aaaaa".equals(m.get("foo"));
      assert "zzzzz".equals(m.get("bar"));

      Type t = RemotingTest.class.getMethod("dummyMap").getGenericReturnType();
      m = (Map) wrapper.convert(t);
      assert m.containsKey("foo");
      assert m.containsKey("bar");
      assert "aaaaa".equals(m.get("foo"));
      assert "zzzzz".equals(m.get("bar"));

      try
      {
         // This should throw a ConversionException
         wrapper.convert(InvalidClass.class);
         assert false;
      }
      catch (ConversionException ex)
      {
      }

      try
      {
         // This should throw a ConversionException also
         wrapper.convert(InvalidMap.class);
         assert false;
      }
      catch (ConversionException ex)
      {
      }

      // ensure when we marshal/unmarshal the values in the map remain the same     
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      wrapper.marshal(out);
     
      SAXReader xmlReader = new SAXReader();
      Document doc = xmlReader.read( new ByteArrayInputStream(out.toByteArray()) );    
     
      Element root = doc.getRootElement();     
     
      MapWrapper other = new MapWrapper();
      other.setCallContext(new CallContext());
      other.setElement(root);
     
      Map otherMap = (Map) other.convert(Map.class);
      for (Object key : otherMap.keySet())
      {
View Full Code Here

Examples of org.jboss.seam.remoting.CallContext

  
   public Model(BeanManager beanManager)
   {
      this.beanManager = beanManager;
      id = UUID.randomUUID().toString();
      callContext = new CallContext(beanManager);
      beanProperties = new HashMap<String, BeanProperty>();
   }
View Full Code Here

Examples of org.restlet.ext.jaxrs.internal.core.CallContext

        request.setResourceRef(resourceRef);
        request.setOriginalRef(resourceRef);
        request.setRootRef(rootRef);
        final Response response = new Response(request);
        Response.setCurrent(response);
        final CallContext callContext = new CallContext(request, response);
        final ThreadLocalizedContext tlContext = new ThreadLocalizedContext();
        tlContext.set(callContext);
        return new ThreadLocalizedUriInfo(tlContext);
    }
View Full Code Here

Examples of org.restlet.ext.jaxrs.internal.core.CallContext

        // 1. if the Response contains a MediaType, use it.
        if (jaxRsResponseMediaType != null)
            return jaxRsResponseMediaType;
        if (resourceMethod == null)
            return MediaType.TEXT_PLAIN;
        CallContext callContext = tlContext.get();
        // 2. Gather the set of producible media types P:
        // (a) + (b)
        Collection<MediaType> p = resourceMethod.getProducedMimes();
        // 2. (c)
        if (p.isEmpty()) {
            p = providers.writerSubSet(entityClass, genericReturnType)
                    .getAllProducibleMediaTypes();
            // 3.
            if (p.isEmpty())
                // '*/*', in conjunction with 8.:
                return MediaType.APPLICATION_OCTET_STREAM;
        }
        // 4. Obtain the acceptable media types A.
        SortedMetadata<MediaType> a = callContext.getAccMediaTypes();
        // 4. If A = {}, set A = {'*/*'}
        if (a.isEmpty())
            a = SortedMetadata.getMediaTypeAll();
        // 5. Sort P and A (A is already sorted)
        List<MediaType> pSorted = sortByConcreteness(p);
View Full Code Here

Examples of org.restlet.ext.jaxrs.internal.core.CallContext

        request.setRootRef(new Reference(baseRef.toString()));
        // NICE Normally, the "rootRef" property is set by the VirtualHost, each
        // time a request is handled by one of its routes.
        // Email from Jerome, 2008-09-22
        try {
            CallContext callContext;
            callContext = new CallContext(request, response);
            tlContext.set(callContext);
            try {
                ResObjAndMeth resObjAndMeth;
                resObjAndMeth = requestMatching();
                callContext.setReadOnly();
                ResourceMethod resourceMethod = resObjAndMeth.resourceMethod;
                resourceObject = resObjAndMeth.resourceObject;
                Object result = invokeMethod(resourceMethod, resourceObject);
                handleResult(result, resourceMethod);
            } catch (WebApplicationException e) {
View Full Code Here

Examples of org.restlet.ext.jaxrs.internal.core.CallContext

     *             Resource Method for OPTIONS is available.
     * @throws ResourceMethodNotFoundException
     */
    private ResObjAndMeth identifyMethod(ResObjAndRemPath resObjAndRemPath,
            MediaType givenMediaType) throws RequestHandledException {
        CallContext callContext = tlContext.get();
        org.restlet.data.Method httpMethod = callContext.getRequest()
                .getMethod();
        // 3. Identify the method that will handle the request:
        // (a)
        ResourceObject resObj = resObjAndRemPath.resourceObject;
        RemainingPath u = resObjAndRemPath.u;
        // (a) 1
        ResourceClass resourceClass = resObj.getResourceClass();
        Collection<ResourceMethod> resourceMethods = resourceClass
                .getMethodsForPath(u);
        if (resourceMethods.isEmpty())
            excHandler.resourceMethodNotFound();// NICE (resourceClass, u);
        // (a) 2: remove methods not support the given method
        boolean alsoGet = httpMethod.equals(Method.HEAD);
        removeNotSupportedHttpMethod(resourceMethods, httpMethod, alsoGet);
        if (resourceMethods.isEmpty()) {
            Set<Method> allowedMethods = resourceClass.getAllowedMethods(u);
            if (httpMethod.equals(Method.OPTIONS)) {
                callContext.getResponse().getAllowedMethods()
                        .addAll(allowedMethods);
                throw new RequestHandledException();
            }
            excHandler.methodNotAllowed(allowedMethods);
        }
        // (a) 3
        if (givenMediaType != null) {
            Collection<ResourceMethod> supporting = resourceMethods;
            resourceMethods = new ArrayList<ResourceMethod>();
            for (ResourceMethod resourceMethod : supporting) {
                if (resourceMethod.isGivenMediaTypeSupported(givenMediaType))
                    resourceMethods.add(resourceMethod);
            }
            if (resourceMethods.isEmpty())
                excHandler.unsupportedMediaType(supporting);
        }
        // (a) 4
        SortedMetadata<MediaType> accMediaTypes = callContext
                .getAccMediaTypes();
        Collection<ResourceMethod> supporting = resourceMethods;
        resourceMethods = new ArrayList<ResourceMethod>();
        for (ResourceMethod resourceMethod : supporting) {
            if (resourceMethod.isAcceptedMediaTypeSupported(accMediaTypes))
                resourceMethods.add(resourceMethod);
        }
        if (resourceMethods.isEmpty()) {
            excHandler.noResourceMethodForAccMediaTypes(supporting);
        }
        // (b) and (c)
        ResourceMethod bestResourceMethod = getBestMethod(resourceMethods,
                givenMediaType, accMediaTypes, httpMethod);
        MatchingResult mr = bestResourceMethod.getPathRegExp().match(u);
        addPathVarsToMap(mr, callContext);
        String matchedUriPart = mr.getMatched();
        if (matchedUriPart.length() > 0) {
            Object jaxRsResObj = resObj.getJaxRsResourceObject();
            callContext.addForMatched(jaxRsResObj, matchedUriPart);
        }
        return new ResObjAndMeth(resObj, bestResourceMethod);
    }
View Full Code Here

Examples of org.restlet.ext.jaxrs.internal.core.CallContext

            RroRemPathAndMatchedPath rroRemPathAndMatchedPath)
            throws WebApplicationException, RequestHandledException {
        ResourceObject o = rroRemPathAndMatchedPath.rootResObj;
        RemainingPath u = rroRemPathAndMatchedPath.u;
        ResourceClass resClass = o.getResourceClass();
        CallContext callContext = tlContext.get();
        callContext.addForMatched(o.getJaxRsResourceObject(),
                rroRemPathAndMatchedPath.matchedUriPath);
        // Part 2
        for (;;) // (j)
        {
            // (a) If U is null or '/' go to step 3
            if (u.isEmptyOrSlash()) {
                return new ResObjAndRemPath(o, u);
            }
            // (b) Set C = class ofO,E = {}
            Collection<ResourceMethodOrLocator> eWithMethod = new ArrayList<ResourceMethodOrLocator>();
            // (c) and (d) Filter E: remove members do not match U or final
            // match not empty
            for (ResourceMethodOrLocator methodOrLocator : resClass
                    .getResourceMethodsAndLocators()) {
                PathRegExp pathRegExp = methodOrLocator.getPathRegExp();
                MatchingResult matchingResult = pathRegExp.match(u);
                if (matchingResult == null)
                    continue;
                if (matchingResult.getFinalCapturingGroup().isEmptyOrSlash())
                    eWithMethod.add(methodOrLocator);
                // the following is added by Stephan (is not in spec 2008-03-06)
                else if (methodOrLocator instanceof SubResourceLocator)
                    eWithMethod.add(methodOrLocator);
            }
            // (e) If E is empty -> HTTP 404
            if (eWithMethod.isEmpty())
                excHandler.resourceNotFound();// NICE (o.getClass(), u);
            // (f) and (g) sort E, use first member of E
            ResourceMethodOrLocator firstMeth = getFirstByNoOfLiteralCharsNoOfCapturingGroups(eWithMethod);

            PathRegExp rMatch = firstMeth.getPathRegExp();
            MatchingResult matchingResult = rMatch.match(u);

            addPathVarsToMap(matchingResult, callContext);

            // (h) When Method is resource method
            if (firstMeth instanceof ResourceMethod)
                return new ResObjAndRemPath(o, u);
            String matchedUriPart = matchingResult.getMatched();
            Object jaxRsResObj = o.getJaxRsResourceObject();
            callContext.addForMatched(jaxRsResObj, matchedUriPart);

            // (g) and (i)
            u = matchingResult.getFinalCapturingGroup();
            SubResourceLocator subResourceLocator = (SubResourceLocator) firstMeth;
            o = createSubResource(o, subResourceLocator, callContext);
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.