Search in sources :

Example 91 with Server

use of org.apache.cxf.endpoint.Server in project cxf by apache.

the class ResourceTest method putRequestTest.

@Test
public void putRequestTest() {
    ResourceManager manager = EasyMock.createMock(ResourceManager.class);
    EasyMock.expect(manager.get(EasyMock.isA(ReferenceParametersType.class))).andReturn(new Representation());
    EasyMock.expectLastCall().once();
    manager.put(EasyMock.isA(ReferenceParametersType.class), EasyMock.isA(Representation.class));
    EasyMock.expectLastCall().once();
    EasyMock.replay(manager);
    ReferenceParametersType refParams = new ReferenceParametersType();
    Element uuid = DOMUtils.getEmptyDocument().createElementNS(MemoryResourceManager.REF_NAMESPACE, MemoryResourceManager.REF_LOCAL_NAME);
    uuid.setTextContent(UUID_VALUE);
    refParams.getAny().add(uuid);
    Element representationEl = DOMUtils.getEmptyDocument().createElementNS(REPRESENTATION_NAMESPACE, REPRESENTATION_NAME);
    representationEl.setTextContent(REPRESENTATION_VALUE);
    Representation representation = new Representation();
    representation.setAny(representationEl);
    Server server = createLocalResource(manager);
    Resource client = createClient(refParams);
    Put putRequest = new Put();
    putRequest.setRepresentation(representation);
    PutResponse response = client.put(putRequest);
    EasyMock.verify(manager);
    representationEl = (Element) response.getRepresentation().getAny();
    Assert.assertEquals("Namespace is other than expected.", REPRESENTATION_NAMESPACE, representationEl.getNamespaceURI());
    Assert.assertEquals("Element name is other than expected", REPRESENTATION_NAME, representationEl.getLocalName());
    Assert.assertEquals("Value is other than expected.", REPRESENTATION_VALUE, representationEl.getTextContent());
    server.destroy();
}
Also used : Server(org.apache.cxf.endpoint.Server) Element(org.w3c.dom.Element) Resource(org.apache.cxf.ws.transfer.resource.Resource) ReferenceParametersType(org.apache.cxf.ws.addressing.ReferenceParametersType) Representation(org.apache.cxf.ws.transfer.Representation) MemoryResourceManager(org.apache.cxf.ws.transfer.manager.MemoryResourceManager) ResourceManager(org.apache.cxf.ws.transfer.manager.ResourceManager) PutResponse(org.apache.cxf.ws.transfer.PutResponse) Put(org.apache.cxf.ws.transfer.Put) Test(org.junit.Test)

Example 92 with Server

use of org.apache.cxf.endpoint.Server in project cxf by apache.

the class JavaFirstSchemaValidationTest method createServer.

public static Server createServer(String port, Class<?> serviceInterface, Object serviceImpl, SchemaValidationType type, Feature... features) throws IOException {
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setServiceClass(serviceImpl.getClass());
    if (features != null) {
        Collections.addAll(svrFactory.getFeatures(), features);
    }
    if (type != null) {
        Map<String, Object> properties = new HashMap<>();
        properties.put(Message.SCHEMA_VALIDATION_ENABLED, type);
        svrFactory.setProperties(properties);
    }
    svrFactory.setAddress(getAddress(port, serviceInterface));
    svrFactory.setServiceBean(serviceImpl);
    Server server = svrFactory.create();
    serverList.add(server);
    return server;
}
Also used : Server(org.apache.cxf.endpoint.Server) HashMap(java.util.HashMap) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean)

Example 93 with Server

use of org.apache.cxf.endpoint.Server in project cxf by apache.

the class WsdlGetUtilsTest method testNewDocumentIsCreatedForEachWsdlRequest.

@Test
public void testNewDocumentIsCreatedForEachWsdlRequest() {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new StuffImpl());
    factory.setAddress("http://localhost:" + PORT + "/Stuff");
    Server server = factory.create();
    try {
        Message message = new MessageImpl();
        Exchange exchange = new ExchangeImpl();
        exchange.put(Bus.class, getBus());
        exchange.put(Service.class, server.getEndpoint().getService());
        exchange.put(Endpoint.class, server.getEndpoint());
        message.setExchange(exchange);
        Map<String, String> map = UrlUtils.parseQueryString("wsdl");
        String baseUri = "http://localhost:" + PORT + "/Stuff";
        String ctx = "/Stuff";
        WSDLGetUtils utils = new WSDLGetUtils();
        Document doc = utils.getDocument(message, baseUri, map, ctx, server.getEndpoint().getEndpointInfo());
        Document doc2 = utils.getDocument(message, baseUri, map, ctx, server.getEndpoint().getEndpointInfo());
        assertFalse(doc == doc2);
    } finally {
        server.stop();
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) Server(org.apache.cxf.endpoint.Server) Message(org.apache.cxf.message.Message) WSDLGetUtils(org.apache.cxf.frontend.WSDLGetUtils) Document(org.w3c.dom.Document) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 94 with Server

use of org.apache.cxf.endpoint.Server in project cxf by apache.

the class UserNameTokenAuthorizationTest method setUpService.

public void setUpService(String expectedRoles, boolean digest, boolean encryptUsernameTokenOnly) throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new EchoImpl());
    factory.setAddress("local://Echo");
    factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    Server server = factory.create();
    Service service = server.getEndpoint().getService();
    service.getInInterceptors().add(new SAAJInInterceptor());
    service.getInInterceptors().add(new LoggingInInterceptor());
    service.getOutInterceptors().add(new SAAJOutInterceptor());
    service.getOutInterceptors().add(new LoggingOutInterceptor());
    wsIn = new SimpleSubjectCreatingInterceptor();
    wsIn.setSupportDigestPasswords(digest);
    wsIn.setProperty(ConfigurationConstants.SIG_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(ConfigurationConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
    service.getInInterceptors().add(wsIn);
    SimpleAuthorizingInterceptor sai = new SimpleAuthorizingInterceptor();
    sai.setMethodRolesMap(Collections.singletonMap("echo", expectedRoles));
    service.getInInterceptors().add(sai);
    wsOut = new WSS4JOutInterceptor();
    wsOut.setProperty(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(ConfigurationConstants.USER, "myalias");
    if (digest) {
        wsOut.setProperty("password", "myAliasPassword");
    } else {
        wsOut.setProperty(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_TEXT);
    }
    if (encryptUsernameTokenOnly) {
        wsOut.setProperty(ConfigurationConstants.ENCRYPTION_USER, "myalias");
        wsOut.setProperty(ConfigurationConstants.ENCRYPTION_PARTS, "{Content}{" + WSS4JConstants.WSSE_NS + "}UsernameToken");
    }
    wsOut.setProperty(ConfigurationConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
    service.getOutInterceptors().add(wsOut);
    // Create the client
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setServiceClass(Echo.class);
    proxyFac.setAddress("local://Echo");
    proxyFac.getClientFactoryBean().setTransportId(LocalTransportFactory.TRANSPORT_ID);
    echo = (Echo) proxyFac.create();
    ((BindingProvider) echo).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE);
    client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getInInterceptors().add(wsIn);
    client.getInInterceptors().add(new SAAJInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());
    client.getOutInterceptors().add(wsOut);
    client.getOutInterceptors().add(new SAAJOutInterceptor());
}
Also used : SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) SimpleAuthorizingInterceptor(org.apache.cxf.interceptor.security.SimpleAuthorizingInterceptor) Server(org.apache.cxf.endpoint.Server) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Service(org.apache.cxf.service.Service) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean)

Example 95 with Server

use of org.apache.cxf.endpoint.Server in project cxf by apache.

the class RoundTripTest method setUpService.

@Before
public void setUpService() throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new EchoImpl());
    factory.setAddress("local://Echo");
    factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    Server server = factory.create();
    Service service = server.getEndpoint().getService();
    service.getInInterceptors().add(new SAAJInInterceptor());
    service.getInInterceptors().add(new LoggingInInterceptor());
    service.getOutInterceptors().add(new SAAJOutInterceptor());
    service.getOutInterceptors().add(new LoggingOutInterceptor());
    wsIn = new WSS4JInInterceptor();
    wsIn.setProperty(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(ConfigurationConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
    service.getInInterceptors().add(wsIn);
    wsOut = new WSS4JOutInterceptor();
    wsOut.setProperty(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(ConfigurationConstants.USER, "myalias");
    wsOut.setProperty("password", "myAliasPassword");
    wsOut.setProperty(ConfigurationConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
    service.getOutInterceptors().add(wsOut);
    // Create the client
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setServiceClass(Echo.class);
    proxyFac.setAddress("local://Echo");
    proxyFac.getClientFactoryBean().setTransportId(LocalTransportFactory.TRANSPORT_ID);
    echo = (Echo) proxyFac.create();
    client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getInInterceptors().add(wsIn);
    client.getInInterceptors().add(new SAAJInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());
    client.getOutInterceptors().add(wsOut);
    client.getOutInterceptors().add(new SAAJOutInterceptor());
}
Also used : SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) Server(org.apache.cxf.endpoint.Server) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Service(org.apache.cxf.service.Service) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) Before(org.junit.Before)

Aggregations

Server (org.apache.cxf.endpoint.Server)199 Test (org.junit.Test)119 ReferenceParametersType (org.apache.cxf.ws.addressing.ReferenceParametersType)54 ResourceManager (org.apache.cxf.ws.transfer.manager.ResourceManager)52 MemoryResourceManager (org.apache.cxf.ws.transfer.manager.MemoryResourceManager)50 Resource (org.apache.cxf.ws.transfer.resource.Resource)50 ExpressionType (org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType)47 ValueType (org.apache.cxf.ws.transfer.dialect.fragment.ValueType)44 Element (org.w3c.dom.Element)44 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)33 Put (org.apache.cxf.ws.transfer.Put)33 Fragment (org.apache.cxf.ws.transfer.dialect.fragment.Fragment)32 Service (org.apache.cxf.service.Service)27 Bus (org.apache.cxf.Bus)25 PutResponse (org.apache.cxf.ws.transfer.PutResponse)25 Endpoint (org.apache.cxf.endpoint.Endpoint)21 ArrayList (java.util.ArrayList)18 QName (javax.xml.namespace.QName)18 ServerRegistry (org.apache.cxf.endpoint.ServerRegistry)18 Document (org.w3c.dom.Document)18