Java Code Examples for org.apache.cxf.endpoint.Endpoint#getService()

The following examples show how to use org.apache.cxf.endpoint.Endpoint#getService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodahaleMetricsProvider.java    From cxf with Apache License 2.0 6 votes vote down vote up
StringBuilder getBaseServiceName(Endpoint endpoint, boolean isClient, String clientId) {
    StringBuilder buffer = new StringBuilder();
    if (endpoint.get("org.apache.cxf.management.service.counter.name") != null) {
        buffer.append((String)endpoint.get("org.apache.cxf.management.service.counter.name"));
    } else {
        Service service = endpoint.getService();

        String serviceName = "\"" + escapePatternChars(service.getName().toString()) + "\"";
        String portName = "\"" + endpoint.getEndpointInfo().getName().getLocalPart() + "\"";

        buffer.append(ManagementConstants.DEFAULT_DOMAIN_NAME).append(':');
        buffer.append(ManagementConstants.BUS_ID_PROP + "=" + bus.getId() + ",");
        buffer.append(ManagementConstants.TYPE_PROP).append("=Metrics");
        if (isClient) {
            buffer.append(".Client,");
        } else {
            buffer.append(".Server,");
        }
        buffer.append(ManagementConstants.SERVICE_NAME_PROP + "=" + serviceName + ",");
        buffer.append(ManagementConstants.PORT_NAME_PROP + "=" + portName + ",");
        if (clientId != null) {
            buffer.append("Client=" + clientId + ",");
        }
    }
    return buffer;
}
 
Example 2
Source File: ColocOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Server isColocated(List<Server> servers, Endpoint endpoint, BindingOperationInfo boi) {
    if (servers != null) {
        Service senderService = endpoint.getService();
        EndpointInfo senderEI = endpoint.getEndpointInfo();
        for (Server s : servers) {
            Endpoint receiverEndpoint = s.getEndpoint();
            Service receiverService = receiverEndpoint.getService();
            EndpointInfo receiverEI = receiverEndpoint.getEndpointInfo();
            if (receiverService.getName().equals(senderService.getName())
                && receiverEI.getName().equals(senderEI.getName())) {
                //Check For Operation Match.
                BindingOperationInfo receiverOI = receiverEI.getBinding().getOperation(boi.getName());
                if (receiverOI != null
                    && isCompatibleOperationInfo(boi, receiverOI)) {
                    return s;
                }
            }
        }
    }

    return null;
}
 
Example 3
Source File: AbstractValidationInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Object getServiceObject(Message message) {
    if (serviceObject != null) {
        return serviceObject;
    }
    Object current = message.getExchange().get(Message.SERVICE_OBJECT);
    if (current != null) {
        return current;
    }
    Endpoint e = message.getExchange().getEndpoint();
    if (e != null && e.getService() != null) {
        Invoker invoker = e.getService().getInvoker();
        if (invoker instanceof FactoryInvoker) {
            FactoryInvoker factoryInvoker = (FactoryInvoker)invoker;
            if (factoryInvoker.isSingletonFactory()) {
                return factoryInvoker.getServiceObject(message.getExchange());
            }
        }
    }
    return null;
}
 
Example 4
Source File: MAPAggregatorTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private Message setUpMessage(SetupMessageArgs args)
    throws Exception {

    Message message = getMessage();
    Exchange exchange = getExchange();
    setUpOutbound(message, exchange, args.outbound, args.fault);
    setUpMessageProperty(message,
                         REQUESTOR_ROLE,
                         Boolean.valueOf(args.requestor));
    if (args.outbound && args.requestor) {
        if (args.usingAddressing) {
            setUpConduit(message, exchange);
        }
        setUpUsingAddressing(message, exchange, args.usingAddressing);
        if (args.usingAddressing) {
            setUpRequestor(message,
                           exchange,
                           args.oneway,
                           args.mapsInContext,
                           args.decoupled,
                           args.zeroLengthAction);
        }
    } else if (!args.requestor) {
        SetupResponderArgs srArgs = new SetupResponderArgs();
        srArgs.oneway = args.oneway;
        srArgs.outbound = args.outbound;
        srArgs.decoupled = args.decoupled;
        srArgs.zeroLengthAction = args.zeroLengthAction;
        srArgs.fault = args.fault;
        srArgs.noMessageId = args.noMessageId;

        Endpoint endpoint = control.createMock(Endpoint.class);
        exchange.getEndpoint();
        EasyMock.expectLastCall().andReturn(endpoint).anyTimes();

        setUpResponder(message,
                       exchange,
                       srArgs, 
                       endpoint);

        endpoint.getOutInterceptors();
        EasyMock.expectLastCall().andReturn(new ArrayList<Interceptor<? extends Message>>()).anyTimes();
        Service serv = control.createMock(Service.class);
        endpoint.getService();
        EasyMock.expectLastCall().andReturn(serv).anyTimes();
        serv.getOutInterceptors();
        EasyMock.expectLastCall().andReturn(new ArrayList<Interceptor<? extends Message>>()).anyTimes();
    }
    control.replay();
    return message;
}
 
Example 5
Source File: EjbInterceptor.java    From tomee with Apache License 2.0 4 votes vote down vote up
@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
    Endpoint endpoint = this.exchange.get(Endpoint.class);
    Service service = endpoint.getService();
    Binding binding = ((JaxWsEndpointImpl) endpoint).getJaxwsBinding();

    this.exchange.put(InvocationContext.class, context);

    if (binding.getHandlerChain() == null || binding.getHandlerChain().isEmpty()) {
        // no handlers so let's just directly invoke the bean
        log.debug("No handlers found.");

        EjbMethodInvoker invoker = (EjbMethodInvoker) service.getInvoker();
        return invoker.directEjbInvoke(this.exchange, this.method, this.params);

    } else {
        // have handlers so have to run handlers now and redo data binding
        // as handlers can change the soap message
        log.debug("Handlers found.");

        Message inMessage = exchange.getInMessage();
        PhaseInterceptorChain chain = new PhaseInterceptorChain(bus.getExtension(PhaseManager.class).getInPhases());

        chain.setFaultObserver(endpoint.getOutFaultObserver());

        /*
         * Since we have to re-do data binding and the XMLStreamReader
         * contents are already consumed by prior data binding step
         * we have to reinitialize the XMLStreamReader from the SOAPMessage
         * created by SAAJInInterceptor.
         */
        if (inMessage instanceof SoapMessage) {
            try {
                reserialize((SoapMessage) inMessage);
            } catch (Exception e) {
                throw new ServerRuntimeException("Failed to reserialize soap message", e);
            }
        } else {
            // TODO: how to handle XML/HTTP binding?
        }

        this.exchange.setOutMessage(null);

        // install default interceptors
        chain.add(new ServiceInvokerInterceptor());
        //chain.add(new OutgoingChainInterceptor()); // it is already in the enclosing chain, if we add it there we are in the tx so we write the message in the tx!

        // See http://cwiki.apache.org/CXF20DOC/interceptors.html
        // install Holder and Wrapper interceptors
        chain.add(new WrapperClassInInterceptor());
        chain.add(new HolderInInterceptor());

        // install interceptors for handler processing
        chain.add(new MustUnderstandInterceptor());
        chain.add(new LogicalHandlerInInterceptor(binding));
        chain.add(new SOAPHandlerInterceptor(binding));

        // install data binding interceptors - todo: check we need it
        copyDataBindingInterceptors(chain, inMessage.getInterceptorChain());

        InterceptorChain oldChain = inMessage.getInterceptorChain();
        inMessage.setInterceptorChain(chain);
        try {
            chain.doIntercept(inMessage);
        } finally {
            inMessage.setInterceptorChain(oldChain);
        }

        // TODO: the result should be deserialized from SOAPMessage
        Object result = getResult();

        return result;
    }
}