Package org.switchyard.component.resteasy.composer

Examples of org.switchyard.component.resteasy.composer.RESTEasyBindingData


        String operationName = restMessageRequest.getOperationName();
        if (operationName.equals("getItem")) {
            Assert.assertTrue(input instanceof Integer);
            Assert.assertTrue((Integer)input == 1);
            Assert.assertFalse(oneWay);
            return new RESTEasyBindingData(new Item(1, "Apple"));
        } else if (operationName.equals("addItem") || operationName.equals("updateItem")) {
            Assert.assertTrue(input instanceof Item);
            Assert.assertFalse(oneWay);
            return new RESTEasyBindingData(((Item)input).toString());
        } else if (operationName.equals("removeItem")) {
            Assert.assertTrue(input instanceof Integer);
            Assert.assertFalse(oneWay);
            return new RESTEasyBindingData("2");
        } else if (operationName.equals("getItemCount")) {
            Assert.assertTrue(input == null);
            Assert.assertFalse(oneWay);
            return new RESTEasyBindingData(0);
        } else if (operationName.equals("testVoid")) {
            Assert.assertTrue(input == null);
            Assert.assertTrue(oneWay);
        }
        return null;
View Full Code Here


            throw RestEasyMessages.MESSAGES.referenceBindingNotStarted(_referenceName, _bindingName);
        }

        final String opName = exchange.getContract().getProviderOperation().getName();

        RESTEasyBindingData restRequest = null;
        try {
            restRequest = _messageComposer.decompose(exchange, new RESTEasyBindingData());
        } catch (Exception e) {
            final String m = RestEasyMessages.MESSAGES.unexpectedExceptionComposingRESTRequest();
            LOGGER.error(m, e);
            throw new HandlerException(m, e);
        }

        Object response = null;
        MethodInvoker methodInvoker = _methodMap.get(opName);
        if (methodInvoker == null) {
            final String m = RestEasyMessages.MESSAGES.unableToMapAmongResources(opName, _methodMap.keySet().toString());
            throw new HandlerException(m);
        }

        try {
            RESTEasyBindingData restResponse = methodInvoker.invoke(restRequest.getParameters(), restRequest.getHeaders());
            restResponse.setOperationName(opName);
            Message out = _messageComposer.compose(restResponse, exchange);
            // Our transformer magic transforms the entity appropriately here :)
            exchange.send(out);
        } catch (Exception e) {
            final String m = "Unexpected exception composing inbound Message from Outbound";
View Full Code Here

        } else if (methodName.equals("equals")) {
            return this.equals(proxy);
        } else if (methodName.equals("hashCode")) {
            return this.hashCode();
        }
        RESTEasyBindingData requestData = new RESTEasyBindingData();
        HttpHeaders headers = ResteasyProviderFactory.getContextData(HttpHeaders.class);
        if (headers != null) {
            requestData.setHeaders(headers.getRequestHeaders());
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Incoming Headers to SwitchYard through InboundHandler [");
                traceLog(LOGGER, headers.getRequestHeaders());
                LOGGER.trace("]");
            }
        }
        SecurityContext securityContext = ResteasyProviderFactory.getContextData(SecurityContext.class);
        if (securityContext != null) {
            if (securityContext instanceof ServletSecurityContext && SERVLET_REQUEST_ACCESS != null) {
                HttpServletRequest servletRequest = SERVLET_REQUEST_ACCESS.read((ServletSecurityContext)securityContext);
                requestData.setServletRequest(servletRequest);
            }
            requestData.setSecured(securityContext.isSecure());
            requestData.setPrincipal(securityContext.getUserPrincipal());
        }
        requestData.setOperationName(methodName);
        if ((args != null) && (args.length > 0)) {
            requestData.setParameters(args);
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace(args);
            }
        }
        RESTEasyBindingData responseData = _serviceConsumer.invoke(requestData, method.getReturnType().equals(Void.TYPE));
        Response.ResponseBuilder builder = Response.ok();
        if (responseData != null) {
            if (method.getReturnType().equals(Response.class)) {
                if (responseData.getParameters().length > 0) {
                    Object param = responseData.getParameters()[0];
                    if (param instanceof Response) {
                        // In future use builder = Response.ResponseBuilder.fromResponse((Response)param);
                        Response response = (Response)param;
                        builder.entity(response.getEntity());
                        builder.status(response.getStatus());
                    } else {
                        builder.entity(param);
                    }
                }
                // Data overrides status
                if (responseData.getStatusCode() != null) {
                    builder.status(responseData.getStatusCode());
                }
                for (Map.Entry<String, List<String>> entry : responseData.getHeaders().entrySet()) {
                    String name = entry.getKey();
                    List<String> values = entry.getValue();
                    for (String value : values) {
                        builder.header(name, value);
                    }
                }
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Outgoing Headers from SwitchYard through InboundHandler [");
                    traceLog(LOGGER, responseData.getHeaders());
                    LOGGER.trace("]");
                }
            } else if (responseData.getParameters().length > 0) {
                return responseData.getParameters()[0];
            }
        }
        return builder.build();
    }
View Full Code Here

     * @param oneWay true of this is a oneway request
     * @return the response from invocation
     * @throws WebApplicationException if any error
     */
    public RESTEasyBindingData invoke(final RESTEasyBindingData restMessageRequest, final boolean oneWay) throws WebApplicationException {
        RESTEasyBindingData output = new RESTEasyBindingData();
        SynchronousInOutHandler inOutHandler = new SynchronousInOutHandler();
        Exchange exchange = _service.createExchange(restMessageRequest.getOperationName(), inOutHandler);

        // identify ourselves
        exchange.getContext().setProperty(ExchangeCompletionEvent.GATEWAY_NAME, _gatewayName, Scope.EXCHANGE)
View Full Code Here

            ClientErrorHandler errorHandler = new ClientErrorHandler(_providerFactory.getClientErrorInterceptors());
            clientResponse.setAttributeExceptionsTo(_method.toString());
            clientResponse.setAnnotations(_method.getAnnotations());
            ClientRequestContext clientRequestContext = new ClientRequestContext(request, clientResponse, errorHandler, _extractorFactory, _baseUri);
            Object response = _extractor.extractEntity(clientRequestContext);
            RESTEasyBindingData restResponse = new RESTEasyBindingData();
            if (response != null) {
                restResponse.setParameters(new Object[]{response});
            }
            // Propagate outgoing headers
            restResponse.setHeaders(clientResponse.getHeaders());
            restResponse.setStatusCode(clientResponse.getStatus());
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Incoming Headers to SwitchYard through OutboundHandler [");
                RESTEasyProxy.traceLog(LOGGER, clientResponse.getHeaders());
                LOGGER.trace("]");
            }
View Full Code Here

TOP

Related Classes of org.switchyard.component.resteasy.composer.RESTEasyBindingData

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.