Search in sources :

Example 6 with ServiceImpl

use of org.apache.cxf.service.ServiceImpl in project cxf by apache.

the class ReflectionServiceFactoryBean method buildServiceFromClass.

protected void buildServiceFromClass() {
    Object o = getBus().getProperty("requireExplicitContractLocation");
    if (o != null && ("true".equals(o) || Boolean.TRUE.equals(o))) {
        throw new ServiceConstructionException(new Message("NO_WSDL_PROVIDED", LOG, getServiceClass().getName()));
    }
    if (LOG.isLoggable(Level.INFO)) {
        LOG.info("Creating Service " + getServiceQName() + " from class " + getServiceClass().getName());
    }
    populateFromClass = true;
    if (Proxy.isProxyClass(this.getServiceClass())) {
        LOG.log(Level.WARNING, "USING_PROXY_FOR_SERVICE", getServiceClass());
    }
    sendEvent(Event.CREATE_FROM_CLASS, getServiceClass());
    ServiceInfo serviceInfo = new ServiceInfo();
    SchemaCollection col = serviceInfo.getXmlSchemaCollection();
    col.getXmlSchemaCollection().setSchemaResolver(new CatalogXmlSchemaURIResolver(this.getBus()));
    col.getExtReg().registerSerializer(MimeAttribute.class, new MimeSerializer());
    ServiceImpl service = new ServiceImpl(serviceInfo);
    setService(service);
    setServiceProperties();
    serviceInfo.setName(getServiceQName());
    serviceInfo.setTargetNamespace(serviceInfo.getName().getNamespaceURI());
    sendEvent(Event.SERVICE_SET, getService());
    createInterface(serviceInfo);
    Set<?> wrapperClasses = this.getExtraClass();
    for (ServiceInfo si : getService().getServiceInfos()) {
        if (wrapperClasses != null && !wrapperClasses.isEmpty()) {
            si.setProperty(EXTRA_CLASS, wrapperClasses);
        }
    }
    initializeDataBindings();
    boolean isWrapped = isWrapped() || hasWrappedMethods(serviceInfo.getInterface());
    if (isWrapped) {
        initializeWrappedSchema(serviceInfo);
    }
    for (OperationInfo opInfo : serviceInfo.getInterface().getOperations()) {
        Method m = (Method) opInfo.getProperty(METHOD);
        if (!isWrapped(m) && !isRPC(m) && opInfo.getInput() != null) {
            createBareMessage(serviceInfo, opInfo, false);
        }
        if (!isWrapped(m) && !isRPC(m) && opInfo.getOutput() != null) {
            createBareMessage(serviceInfo, opInfo, true);
        }
        if (opInfo.hasFaults()) {
            // check to make sure the faults are elements
            for (FaultInfo fault : opInfo.getFaults()) {
                QName qn = (QName) fault.getProperty("elementName");
                MessagePartInfo part = fault.getFirstMessagePart();
                if (!part.isElement()) {
                    part.setElement(true);
                    part.setElementQName(qn);
                    checkForElement(serviceInfo, part);
                }
            }
        }
    }
    if (LOG.isLoggable(Level.FINE) || isValidate()) {
        ServiceModelSchemaValidator validator = new ServiceModelSchemaValidator(serviceInfo);
        validator.walk();
        String validationComplaints = validator.getComplaints();
        if (!"".equals(validationComplaints)) {
            if (isValidate()) {
                LOG.warning(validationComplaints);
            } else {
                LOG.fine(validationComplaints);
            }
        }
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) FaultInfo(org.apache.cxf.service.model.FaultInfo) Message(org.apache.cxf.common.i18n.Message) ServiceImpl(org.apache.cxf.service.ServiceImpl) QName(javax.xml.namespace.QName) ServiceModelSchemaValidator(org.apache.cxf.service.ServiceModelSchemaValidator) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Method(java.lang.reflect.Method) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) MimeSerializer(org.apache.cxf.databinding.source.mime.MimeSerializer) CatalogXmlSchemaURIResolver(org.apache.cxf.catalog.CatalogXmlSchemaURIResolver) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection)

Example 7 with ServiceImpl

use of org.apache.cxf.service.ServiceImpl in project cxf by apache.

the class STSTokenOutInterceptorTest method prepareMessage.

private MessageImpl prepareMessage(Bus bus, STSClient stsClient, String serviceAddress) throws EndpointException {
    MessageImpl message = new MessageImpl();
    message.put(SecurityConstants.STS_CLIENT, stsClient);
    message.put(Message.ENDPOINT_ADDRESS, serviceAddress);
    Exchange exchange = new ExchangeImpl();
    ServiceInfo si = new ServiceInfo();
    Service s = new ServiceImpl(si);
    EndpointInfo ei = new EndpointInfo();
    Endpoint ep = new EndpointImpl(bus, s, ei);
    ei.setBinding(new BindingInfo(si, null));
    message.setExchange(exchange);
    exchange.put(Endpoint.class, ep);
    return message;
}
Also used : Exchange(org.apache.cxf.message.Exchange) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) ServiceImpl(org.apache.cxf.service.ServiceImpl) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) BindingInfo(org.apache.cxf.service.model.BindingInfo) Service(org.apache.cxf.service.Service) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 8 with ServiceImpl

use of org.apache.cxf.service.ServiceImpl in project cxf by apache.

the class ServiceInvokerInterceptorTest method createEndpoint.

Endpoint createEndpoint(Invoker i) throws Exception {
    IMocksControl control = EasyMock.createNiceControl();
    Endpoint endpoint = control.createMock(Endpoint.class);
    ServiceImpl service = new ServiceImpl((ServiceInfo) null);
    service.setInvoker(i);
    service.setExecutor(new SimpleExecutor());
    EasyMock.expect(endpoint.getService()).andReturn(service).anyTimes();
    control.replay();
    return endpoint;
}
Also used : IMocksControl(org.easymock.IMocksControl) Endpoint(org.apache.cxf.endpoint.Endpoint) ServiceImpl(org.apache.cxf.service.ServiceImpl)

Example 9 with ServiceImpl

use of org.apache.cxf.service.ServiceImpl in project cxf by apache.

the class EndpointImplTest method testEqualsAndHashCode.

@Test
public void testEqualsAndHashCode() throws Exception {
    Bus bus = new ExtensionManagerBus();
    Service svc = new ServiceImpl();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress("http://nowhere.com/bar/foo");
    EndpointInfo ei2 = new EndpointInfo();
    ei2.setAddress("http://nowhere.com/foo/bar");
    Endpoint ep = new EndpointImpl(bus, svc, ei);
    Endpoint ep1 = new EndpointImpl(bus, svc, ei);
    Endpoint ep2 = new EndpointImpl(bus, svc, ei2);
    int hashcode = ep.hashCode();
    int hashcode1 = ep1.hashCode();
    int hashcode2 = ep2.hashCode();
    assertTrue("hashcodes must be equal", hashcode == hashcode1);
    assertTrue("hashcodes must not be equal", hashcode != hashcode2);
    assertTrue("reflexivity violated", ep.equals(ep));
    assertFalse("two objects must not be equal", ep.equals(ep1));
    assertFalse("two objects must not be equal", ep.equals(ep2));
    ep.put("custom", Boolean.TRUE);
    assertTrue("hashcode must remain equal", hashcode == ep.hashCode());
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) ServiceImpl(org.apache.cxf.service.ServiceImpl) Service(org.apache.cxf.service.Service) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Test(org.junit.Test)

Example 10 with ServiceImpl

use of org.apache.cxf.service.ServiceImpl in project cxf by apache.

the class MAPAggregatorTest method testGetReplyToUsingBaseAddress.

@Test
public void testGetReplyToUsingBaseAddress() throws Exception {
    Message message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    final String localReplyTo = "/SoapContext/decoupled";
    final String decoupledEndpointBase = "http://localhost:8181/cxf";
    final String replyTo = decoupledEndpointBase + localReplyTo;
    ServiceInfo s = new ServiceInfo();
    Service svc = new ServiceImpl(s);
    EndpointInfo ei = new EndpointInfo();
    InterfaceInfo ii = s.createInterface(new QName("FooInterface"));
    s.setInterface(ii);
    ii.addOperation(new QName("fooOp"));
    SoapBindingInfo b = new SoapBindingInfo(s, "http://schemas.xmlsoap.org/soap/", Soap11.getInstance());
    b.setTransportURI("http://schemas.xmlsoap.org/soap/http");
    ei.setBinding(b);
    ei.setAddress("http://nowhere.com/bar/foo");
    ei.setName(new QName("http://nowhere.com/port", "foo"));
    Bus bus = new ExtensionManagerBus();
    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    DestinationFactory df = control.createMock(DestinationFactory.class);
    Destination d = control.createMock(Destination.class);
    bus.setExtension(dfm, DestinationFactoryManager.class);
    EasyMock.expect(dfm.getDestinationFactoryForUri(localReplyTo)).andReturn(df);
    EasyMock.expect(df.getDestination(EasyMock.anyObject(EndpointInfo.class), EasyMock.anyObject(Bus.class))).andReturn(d);
    EasyMock.expect(d.getAddress()).andReturn(EndpointReferenceUtils.getEndpointReference(localReplyTo));
    Endpoint ep = new EndpointImpl(bus, svc, ei);
    exchange.put(Endpoint.class, ep);
    exchange.put(Bus.class, bus);
    exchange.setOutMessage(message);
    setUpMessageProperty(message, REQUESTOR_ROLE, Boolean.TRUE);
    message.getContextualProperty(WSAContextUtils.REPLYTO_PROPERTY);
    message.put(WSAContextUtils.REPLYTO_PROPERTY, localReplyTo);
    message.put(WSAContextUtils.DECOUPLED_ENDPOINT_BASE_PROPERTY, decoupledEndpointBase);
    AddressingProperties maps = new AddressingProperties();
    AttributedURIType id = ContextUtils.getAttributedURI("urn:uuid:12345");
    maps.setMessageID(id);
    maps.setAction(ContextUtils.getAttributedURI(""));
    setUpMessageProperty(message, CLIENT_ADDRESSING_PROPERTIES, maps);
    control.replay();
    aggregator.mediate(message, false);
    AddressingProperties props = (AddressingProperties) message.get(JAXWSAConstants.ADDRESSING_PROPERTIES_OUTBOUND);
    assertEquals(replyTo, props.getReplyTo().getAddress().getValue());
    control.verify();
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) DestinationFactory(org.apache.cxf.transport.DestinationFactory) Destination(org.apache.cxf.transport.Destination) Message(org.apache.cxf.message.Message) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) ServiceImpl(org.apache.cxf.service.ServiceImpl) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) Service(org.apache.cxf.service.Service) Exchange(org.apache.cxf.message.Exchange) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) MessageImpl(org.apache.cxf.message.MessageImpl) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Aggregations

ServiceImpl (org.apache.cxf.service.ServiceImpl)12 Service (org.apache.cxf.service.Service)8 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)8 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)7 QName (javax.xml.namespace.QName)6 Endpoint (org.apache.cxf.endpoint.Endpoint)6 EndpointImpl (org.apache.cxf.endpoint.EndpointImpl)6 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)5 MessageImpl (org.apache.cxf.message.MessageImpl)5 Exchange (org.apache.cxf.message.Exchange)4 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)4 OperationInfo (org.apache.cxf.service.model.OperationInfo)4 Bus (org.apache.cxf.Bus)3 SoapBindingInfo (org.apache.cxf.binding.soap.model.SoapBindingInfo)3 Message (org.apache.cxf.message.Message)3 BindingInfo (org.apache.cxf.service.model.BindingInfo)3 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)3 Method (java.lang.reflect.Method)2 ExtensionManagerBus (org.apache.cxf.bus.extension.ExtensionManagerBus)2 Message (org.apache.cxf.common.i18n.Message)2