org.apache.cxf.endpoint.Server Java Examples

The following examples show how to use org.apache.cxf.endpoint.Server. 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: StudentTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testMapMap() throws Exception {

    ServerFactoryBean sf = new ServerFactoryBean();
    sf.setServiceClass(StudentServiceDocLiteral.class);
    sf.setServiceBean(new StudentServiceDocLiteralImpl());
    sf.setAddress("local://StudentServiceDocLiteral");
    setupAegis(sf);
    Server server = sf.create();
    server.start();

    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    proxyFac.setAddress("local://StudentServiceDocLiteral");
    proxyFac.setBus(getBus());
    setupAegis(proxyFac.getClientFactoryBean());
    //CHECKSTYLE:OFF
    HashMap<String, Student> mss = new HashMap<>();
    mss.put("Alice", new Student());
    HashMap<String, HashMap<String, Student>> mmss = new HashMap<>();
    mmss.put("Bob", mss);

    StudentServiceDocLiteral clientInterface = proxyFac.create(StudentServiceDocLiteral.class);
    clientInterface.takeMapMap(mmss);
    //CHECKSTYLE:ON
}
 
Example #2
Source File: DefaultApplicationFactory.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Detects the application (if present) or creates the default application (in case the scan is disabled).
 */
public static ApplicationInfo createApplicationInfoOrDefault(final Server server, 
            final ServerProviderFactory factory, final JAXRSServiceFactoryBean sfb, final Bus bus, 
                final boolean scan) {
    
    ApplicationInfo appInfo = null;
    if (!scan) {
        appInfo = factory.getApplicationProvider();
        if (appInfo == null) {
            Set<Class<?>> serviceClasses = new HashSet<>();
            for (ClassResourceInfo cri : sfb.getClassResourceInfo()) {
                serviceClasses.add(cri.getServiceClass());
            }
            appInfo = createApplicationInfo(serviceClasses, bus);
            server.getEndpoint().put(Application.class.getName(), appInfo);
        }
    }
    
    return appInfo;
}
 
Example #3
Source File: FragmentGetQNameTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void getTest() throws XMLStreamException {
    String content = "<root><a><b>Text</b></a></root>";
    ResourceManager resourceManager = new MemoryResourceManager();
    ReferenceParametersType refParams = resourceManager.create(getRepresentation(content));
    Server resource = createLocalResource(resourceManager);
    Resource client = createClient(refParams);

    ObjectFactory objectFactory = new ObjectFactory();

    Get request = new Get();
    request.setDialect(FragmentDialectConstants.FRAGMENT_2011_03_IRI);
    ExpressionType expression = new ExpressionType();
    expression.setLanguage(FragmentDialectConstants.QNAME_LANGUAGE_IRI);
    expression.getContent().add("a");
    request.getAny().add(objectFactory.createExpression(expression));

    GetResponse response = client.get(request);
    ValueType value = getValue(response);
    Assert.assertEquals(1, value.getContent().size());
    Assert.assertEquals("a", ((Element)value.getContent().get(0)).getLocalName());

    resource.destroy();
}
 
Example #4
Source File: FragmentGetXPath10Test.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void getImpliedLanguageTest() throws XMLStreamException {
    String content = "<root><a><b>Text</b></a></root>";
    ResourceManager resourceManager = new MemoryResourceManager();
    ReferenceParametersType refParams = resourceManager.create(getRepresentation(content));
    Server resource = createLocalResource(resourceManager);
    Resource client = createClient(refParams);

    ObjectFactory objectFactory = new ObjectFactory();

    Get request = new Get();
    request.setDialect(FragmentDialectConstants.FRAGMENT_2011_03_IRI);
    ExpressionType expression = new ExpressionType();
    expression.getContent().add("/root/a/b");
    request.getAny().add(objectFactory.createExpression(expression));

    GetResponse response = client.get(request);
    ValueType value = getValue(response);
    Assert.assertEquals(1, value.getContent().size());
    Assert.assertEquals("b", ((Element)value.getContent().get(0)).getLocalName());

    resource.destroy();
}
 
Example #5
Source File: FragmentGetXPath10Test.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void getNumberTest() throws XMLStreamException {
    String content = "<root><a><b>Text</b><b>Text2</b></a></root>";
    ResourceManager resourceManager = new MemoryResourceManager();
    ReferenceParametersType refParams = resourceManager.create(getRepresentation(content));
    Server resource = createLocalResource(resourceManager);
    Resource client = createClient(refParams);

    ObjectFactory objectFactory = new ObjectFactory();

    Get request = new Get();
    request.setDialect(FragmentDialectConstants.FRAGMENT_2011_03_IRI);
    ExpressionType expression = new ExpressionType();
    expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
    expression.getContent().add("count(//b)");
    request.getAny().add(objectFactory.createExpression(expression));

    GetResponse response = client.get(request);
    ValueType value = getValue(response);
    Assert.assertEquals(1, value.getContent().size());
    Assert.assertEquals("2", value.getContent().get(0));

    resource.destroy();
}
 
Example #6
Source File: AbstractTestCXFClientServerInterceptors.java    From kieker with Apache License 2.0 6 votes vote down vote up
private Server startServer() {
	LOGGER.info("XX: {}", this.serviceAddress);

	final JaxWsServerFactoryBean srvFactory = new JaxWsServerFactoryBean();
	srvFactory.setServiceClass(IBookstore.class);
	srvFactory.setAddress(this.serviceAddress);
	srvFactory.setServiceBean(new BookstoreImpl());

	// On the server-side, we only intercept incoming requests and outgoing
	// responses.
	srvFactory.getInInterceptors()
			.add(new OperationExecutionSOAPRequestInInterceptor(this.serverMonitoringController));
	srvFactory.getOutInterceptors()
			.add(new OperationExecutionSOAPResponseOutInterceptor(this.serverMonitoringController));
	return srvFactory.create(); // create() also starts the server
}
 
Example #7
Source File: ExceptionTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test(expected = HelloException.class)
public void testJaxwsServerSimpleClient() throws Exception {
    JaxWsServerFactoryBean sfbean = new JaxWsServerFactoryBean();
    sfbean.setServiceClass(ExceptionService.class);
    sfbean.setDataBinding(new AegisDatabinding());
    sfbean.setAddress("local://ExceptionServiceJaxWs1");
    Server server = sfbean.create();
    Service service = server.getEndpoint().getService();
    service.setInvoker(new BeanInvoker(new ExceptionServiceImpl()));

    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    proxyFac.setAddress("local://ExceptionServiceJaxWs1");
    proxyFac.setBus(getBus());
    setupAegis(proxyFac.getClientFactoryBean());

    ExceptionService clientInterface = proxyFac.create(ExceptionService.class);

    clientInterface.sayHiWithException();
}
 
Example #8
Source File: AbstractSpringConfigurationFactory.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Server createJaxRsServer() {

        JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
        factory.setAddress(getAddress());
        factory.setTransportId(getTransportId());
        factory.setBus(getBus());

        setJaxrsResources(factory);

        factory.setInInterceptors(getInInterceptors());
        factory.setOutInterceptors(getOutInterceptors());
        factory.setOutFaultInterceptors(getOutFaultInterceptors());
        factory.setFeatures(getFeatures());
        if (!StringUtils.isEmpty(jaxrsExtensions)) {
            factory.setExtensionMappings(CastUtils.cast((Map<?, ?>)parseMapSequence(jaxrsExtensions)));
        }
        finalizeFactorySetup(factory);
        return factory.create();
    }
 
Example #9
Source File: ServerFactoryTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testJaxbExtraClass() throws Exception {
    ServerFactoryBean svrBean = new ServerFactoryBean();
    svrBean.setAddress("http://localhost/Hello");
    svrBean.setServiceClass(HelloServiceImpl.class);
    svrBean.setBus(getBus());

    Map<String, Object> props = svrBean.getProperties();
    if (props == null) {
        props = new HashMap<>();
    }
    props.put("jaxb.additionalContextClasses",
              new Class[] {GreetMe.class, GreetMeOneWay.class});
    svrBean.setProperties(props);
    Server serv = svrBean.create();
    Class<?>[] extraClass = ((JAXBDataBinding)serv.getEndpoint().getService()
            .getDataBinding()).getExtraClass();
    assertEquals(extraClass.length, 2);
    assertEquals(extraClass[0], GreetMe.class);
    assertEquals(extraClass[1], GreetMeOneWay.class);
}
 
Example #10
Source File: MEXUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static List<Element> getSchemas(Server server, String id) {
    Message message = PhaseInterceptorChain.getCurrentMessage();

    String base = (String)message.get(Message.REQUEST_URL);
    String ctxUri = (String)message.get(Message.PATH_INFO);

    WSDLGetUtils utils = new WSDLGetUtils();
    EndpointInfo info = server.getEndpoint().getEndpointInfo();
    Map<String, String> locs = utils.getSchemaLocations(message,
                                                  base,
                                                  ctxUri,
                                                  info);
    List<Element> ret = new LinkedList<>();
    for (Map.Entry<String, String> xsd : locs.entrySet()) {

        if (StringUtils.isEmpty(id)
            || id.equals(xsd.getKey())) {
            String query = xsd.getValue().substring(xsd.getValue().indexOf('?') + 1);
            Map<String, String> params = UrlUtils.parseQueryString(query);

            ret.add(utils.getDocument(message, base, params, ctxUri, info).getDocumentElement());
        }
    }
    return ret;
}
 
Example #11
Source File: CrossSchemaImportsTests.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testJaxbCrossSchemaImport() throws Exception {
    testUtilities.setBus((Bus)applicationContext.getBean("cxf"));
    testUtilities.addDefaultNamespaces();
    Server s = testUtilities.getServerForService(new QName("http://apache.org/type_test/doc",
                                                           "TypeTestPortTypeService"));
    Document wsdl = testUtilities.getWSDLDocument(s);
    testUtilities.
         assertValid("//xsd:schema[@targetNamespace='http://apache.org/type_test/doc']/"
                     + "xsd:import[@namespace='http://apache.org/type_test/types1']", wsdl);

    Assert.assertEquals(1, LifeCycleListenerTester.getInitCount());

    Assert.assertEquals(0, LifeCycleListenerTester.getShutdownCount());

    ((ConfigurableApplicationContext)applicationContext).close();
    Assert.assertEquals(1, LifeCycleListenerTester.getShutdownCount());
}
 
Example #12
Source File: JavaFirstSchemaValidationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #13
Source File: StudentTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testReturnMap() throws Exception {

    JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
    sf.setServiceClass(StudentService.class);
    sf.setServiceBean(new StudentServiceImpl());
    sf.setAddress("local://StudentService");
    setupAegis(sf);
    Server server = sf.create();
    server.start();

    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setAddress("local://StudentService");
    proxyFac.setBus(getBus());
    setupAegis(proxyFac.getClientFactoryBean());

    StudentService clientInterface = proxyFac.create(StudentService.class);
    Map<Long, Student> fullMap = clientInterface.getStudentsMap();
    assertNotNull(fullMap);
    Student one = fullMap.get(Long.valueOf(1));
    assertNotNull(one);
    assertEquals("Student1", one.getName());

    Map<String, ?> wildMap = clientInterface.getWildcardMap();
    assertEquals("valuestring", wildMap.get("keystring"));
}
 
Example #14
Source File: AbstractAegisTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Server createJaxwsService(Class<?> serviceClass,
                                    Object serviceBean, String address, QName name) {
    if (address == null) {
        address = serviceClass.getSimpleName();
    }
    JaxWsServiceFactoryBean sf = new JaxWsServiceFactoryBean();
    sf.setDataBinding(new AegisDatabinding());
    JaxWsServerFactoryBean serverFactoryBean = new JaxWsServerFactoryBean();
    serverFactoryBean.setServiceClass(serviceClass);

    if (serviceBean != null) {
        serverFactoryBean.setServiceBean(serviceBean);
    }

    serverFactoryBean.setAddress("local://" + address);

    serverFactoryBean.setServiceFactory(sf);
    if (name != null) {
        serverFactoryBean.setEndpointName(name);
    }
    return serverFactoryBean.create();
}
 
Example #15
Source File: JaxWsServerFactoryBean.java    From cxf with Apache License 2.0 6 votes vote down vote up
public Server create() {
    ClassLoaderHolder orig = null;
    try {
        if (bus != null) {
            ClassLoader loader = bus.getExtension(ClassLoader.class);
            if (loader != null) {
                orig = ClassLoaderUtils.setThreadContextClassloader(loader);
            }
        }

        Server server = super.create();
        initializeResourcesAndHandlerChain(server);
        checkPrivateEndpoint(server.getEndpoint());

        return server;
    } finally {
        if (orig != null) {
            orig.reset();
        }
    }
}
 
Example #16
Source File: SimpleEventingIntegrationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected Server createEventSinkWithWSAActionAssertion(String address, String action) {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestingEventSinkImpl());
    factory.setAddress(address);
    factory.getHandlers().add(new WSAActionAssertingHandler(action));
    return factory.create();
}
 
Example #17
Source File: ProtobufferImporterTest.java    From fuchsia with Apache License 2.0 5 votes vote down vote up
@Test
public void testDenyDeclaration() throws BinderException, InvalidSyntaxException, ClassNotFoundException, InterruptedException, InvocationTargetException, EndpointException, IllegalAccessException, NoSuchMethodException {
    ImportDeclaration declaration = getValidDeclarations().get(0);
    fuchsiaDeclarationBinder.useDeclaration(declaration);
    Map<String, Server> serverPublished = field("registeredImporter").ofType(Map.class).in(fuchsiaDeclarationBinder).get();
    Assert.assertEquals(1, serverPublished.size());
    fuchsiaDeclarationBinder.denyDeclaration(declaration);
    Assert.assertEquals(0, serverPublished.size());
}
 
Example #18
Source File: JaxWsServerFactoryBeanTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testJaxwsServiceClass() throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceClass(CalculatorPortType.class);
    factory.setServiceBean(new CalculatorImpl());
    String address = "http://localhost:9001/jaxwstest";
    factory.setAddress(address);
    Server server = factory.create();
    Endpoint endpoint = server.getEndpoint();
    ServiceInfo service = endpoint.getEndpointInfo().getService();
    assertNotNull(service);

    Bus bus = factory.getBus();
    Definition def = new ServiceWSDLBuilder(bus, service).build();

    WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter();
    def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
    Document doc = wsdlWriter.getDocument(def);

    Map<String, String> ns = new HashMap<>();
    ns.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
    ns.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
    XPathUtils xpather = new XPathUtils(ns);
    xpather.isExist("/wsdl:definitions/wsdl:binding/soap:binding",
                    doc,
                    XPathConstants.NODE);
    xpather.isExist("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='add']/soap:operation",
                    doc,
                    XPathConstants.NODE);
    xpather.isExist("/wsdl:definitions/wsdl:service/wsdl:port[@name='add']/soap:address[@location='"
                    + address + "']",
                    doc,
                    XPathConstants.NODE);
}
 
Example #19
Source File: StatsConfig.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Bean @DependsOn("cxf")
Server jaxRsServer() {
    final JAXRSServerFactoryBean factory = RuntimeDelegate
        .getInstance()
        .createEndpoint(new StatsApplication(), JAXRSServerFactoryBean.class);
    factory.setServiceBean(statsRestService);
    factory.setProvider(new JacksonJsonProvider());
    return factory.create();
}
 
Example #20
Source File: FragmentPutReplaceTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void replaceNonExistingElementTest() throws XMLStreamException {
    String content = "<a/>";
    ResourceManager resourceManager = new MemoryResourceManager();
    ReferenceParametersType refParams = resourceManager.create(getRepresentation(content));
    Server resource = createLocalResource(resourceManager);
    Resource client = createClient(refParams);

    Put request = new Put();
    request.setDialect(FragmentDialectConstants.FRAGMENT_2011_03_IRI);
    Fragment fragment = new Fragment();
    ExpressionType expression = new ExpressionType();
    expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
    expression.getContent().add("/a/b");
    Element replacedElement = DOMUtils.getEmptyDocument().createElement("b");
    ValueType value = new ValueType();
    value.getContent().add(replacedElement);
    fragment.setExpression(expression);
    fragment.setValue(value);
    request.getAny().add(fragment);

    PutResponse response = client.put(request);
    Element rootEl = (Element) response.getRepresentation().getAny();
    Assert.assertEquals(1, rootEl.getChildNodes().getLength());
    Assert.assertEquals("b", ((Element)rootEl.getChildNodes().item(0)).getLocalName());

    resource.destroy();
}
 
Example #21
Source File: ServerRegistryImpTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testServerRegistryPreShutdown() {
    ServerRegistryImpl serverRegistryImpl = new ServerRegistryImpl();
    Server server = new DummyServer(serverRegistryImpl);
    server.start();
    assertEquals("The serverList should have one service", serverRegistryImpl.serversList.size(), 1);
    serverRegistryImpl.preShutdown();
    assertEquals("The serverList should be clear ", serverRegistryImpl.serversList.size(), 0);
    serverRegistryImpl.postShutdown();
    assertEquals("The serverList should be clear ", serverRegistryImpl.serversList.size(), 0);
}
 
Example #22
Source File: WebServiceTaskTest.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 独立启动WebService服务
 */
public static void main(String[] args) {
	Counter counter = new CounterImpl();
	JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
	svrFactory.setServiceClass(Counter.class);
	svrFactory.setAddress("http://localhost:12345/counter");
	svrFactory.setServiceBean(counter);
	svrFactory.getInInterceptors().add(new LoggingInInterceptor());
	svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
	Server server = svrFactory.create();
	server.start();
}
 
Example #23
Source File: StaxToDOMSignatureIdentifierTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Service createService() {
    // Create the Service
    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 LoggingInInterceptor());
    service.getOutInterceptors().add(new LoggingOutInterceptor());

    return service;
}
 
Example #24
Source File: ColocOutInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void verifyIsColocatedWithNullList() {
    Server val = colocOut.isColocated(null, null, null);
    assertEquals("Is not a colocated call",
                 null,
                 val);
    control.reset();
}
 
Example #25
Source File: TestUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static Server createStudentsResource(ResourceManager resourceManager, String port) {
    ResourceLocal resourceLocal = new ResourceLocal();
    resourceLocal.setManager(resourceManager);
    resourceLocal.getResourceTypeIdentifiers().add(
            new XSDResourceTypeIdentifier(
                    new StreamSource(TestUtils.class.getResourceAsStream("/schema/studentPut.xsd")),
                    new XSLTResourceTransformer(
                            new StreamSource(TestUtils.class.getResourceAsStream("/xslt/studentPut.xsl")),
                            new StudentPutResourceValidator())));
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceClass(Resource.class);
    factory.setServiceBean(resourceLocal);
    factory.setAddress("http://localhost:" + port + "/ResourceStudents");
    return factory.create();
}
 
Example #26
Source File: RestOrderServer.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // create dummy backend
    DummyOrderService dummy = new DummyOrderService();
    dummy.setupDummyOrders();

    // create CXF REST service and inject the dummy backend
    RestOrderService rest = new RestOrderService();
    rest.setOrderService(dummy);

    // setup Apache CXF REST server on port 9000
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(RestOrderService.class);
    sf.setResourceProvider(RestOrderService.class, new SingletonResourceProvider(rest));
    sf.setAddress("http://localhost:9000/");

    // create and start the CXF server (non blocking)
    Server server = sf.create();
    server.start();

    // keep the JVM running
    Console console = System.console();
    System.out.println("Server started on http://localhost:9000/");
    System.out.println("");

    // If you run the main class from IDEA/Eclipse then you may not have a console, which is null)
    if (console != null) {
        System.out.println("  Press ENTER to stop server");
        console.readLine();
    } else {
        System.out.println("  Stopping after 5 minutes or press ctrl + C to stop");
        Thread.sleep(5 * 60 * 1000);
    }

    // stop CXF server
    server.stop();
    System.exit(0);
}
 
Example #27
Source File: FragmentPutAddTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void addToEmptyDocumentTest() {
    ResourceManager resourceManager = new MemoryResourceManager();
    ReferenceParametersType refParams = resourceManager.create(new Representation());
    Server resource = createLocalResource(resourceManager);
    Resource client = createClient(refParams);

    Put request = new Put();
    request.setDialect(FragmentDialectConstants.FRAGMENT_2011_03_IRI);
    Fragment fragment = new Fragment();
    ExpressionType expression = new ExpressionType();
    expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
    expression.setMode(FragmentDialectConstants.FRAGMENT_MODE_ADD);
    expression.getContent().add("/");
    Element addedElement = DOMUtils.getEmptyDocument().createElement("a");
    ValueType value = new ValueType();
    value.getContent().add(addedElement);
    fragment.setExpression(expression);
    fragment.setValue(value);
    request.getAny().add(fragment);

    PutResponse response = client.put(request);
    Element rootEl = (Element) response.getRepresentation().getAny();
    Assert.assertEquals("a", rootEl.getNodeName());

    resource.destroy();
}
 
Example #28
Source File: ExceptionTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    super.setUp();

    Server s = createService(ExceptionService.class, new ExceptionServiceImpl(), null);
    s.getEndpoint().getService().setInvoker(new BeanInvoker(new ExceptionServiceImpl()));
}
 
Example #29
Source File: AnnotationsFactoryBeanListener.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setScope(Server server, Class<?> cls) {
    FactoryType scope = cls.getAnnotation(FactoryType.class);
    if (scope != null) {
        Invoker i = server.getEndpoint().getService().getInvoker();
        if (i instanceof FactoryInvoker) {
            Factory f;
            if (scope.factoryClass() == FactoryType.DEFAULT.class) {
                switch (scope.value()) {
                case Session:
                    if (scope.args().length > 0) {
                        f = new SessionFactory(cls, Boolean.parseBoolean(scope.args()[0]));
                    } else {
                        f = new SessionFactory(cls);
                    }
                    break;
                case PerRequest:
                    f = new PerRequestFactory(cls);
                    break;
                case Pooled:
                    f = new PooledFactory(cls, Integer.parseInt(scope.args()[0]));
                    break;
                default:
                    f = new SingletonFactory(cls);
                    break;
                }
            } else {
                try {
                    f = scope.factoryClass().getConstructor(Class.class, String[].class)
                        .newInstance(cls, scope.args());
                } catch (Throwable t) {
                    throw new ServiceConstructionException(t);
                }
            }
            ((FactoryInvoker)i).setFactory(f);
        }

    }
}
 
Example #30
Source File: WSAFeatureTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testServerFactory() {
    JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
    sf.getFeatures().add(new WSAddressingFeature());
    sf.setServiceBean(new GreeterImpl());
    sf.setAddress("http://localhost:" + PORT + "/test");
    sf.setStart(false);
    sf.setBus(getBus());

    Server server = sf.create();

    Endpoint endpoint = server.getEndpoint();
    checkAddressInterceptors(endpoint.getInInterceptors());

}