CXF - getting started

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://cxf.apache.org/configuration/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:core="http://cxf.apache.org/core"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://cxf.apache.org/configuration/beans http://cxf.apache.org/schemas/configuration/cxf-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
    ">

    <jaxws:endpoint id="helloWorld1"
        implementor="idv.steven.cxf.helloworld.HelloWorldImpl" address="http://localhost:9000/CXF/HelloWorld" />

    <jaxws:client id="client"
        serviceClass="idv.steven.cxf.helloworld.HelloWorld"
        address="http://localhost:9000/CXF/HelloWorld" />
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"
>

    <context:component-scan base-package="idv.steven.mvc.controller" />
    <mvc:annotation-driven />

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
        p:prefix="/jsp/"
        p:suffix=".jsp"
    />
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>CXF</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:beans-config.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:mvc-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>
package idv.steven.cxf.helloworld;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public interface HelloWorld {
    String sayHello(@WebParam(name="text") String text);
}
package idv.steven.cxf.helloworld;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService(serviceName = "HelloWorld")
public class HelloWorldImpl implements HelloWorld {

    @Override
    public String sayHello(@WebParam(name="text") String text) {
        System.out.println("sayHello called");
        return "Hello " + text + "!";
    }
}
package idv.steven.mvc.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import idv.steven.cxf.helloworld.HelloWorld;

@Controller
public class SayHelloController {
    @Autowired
    private HelloWorld client;

    @RequestMapping(value="/say", method=RequestMethod.GET)
    public @ResponseBody Map<String, Object> getHelloWorld(String name) {
        Map<String, Object> result = new HashMap<String, Object>();
        String respText = client.sayHello(name);
        result.put("result", respText);

        return result;
    }
}
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-3.0.0.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SayHello</title>
<script type="text/javascript">
var message;

$(function() {
    $("#say").bind("click", function(e) {
        var myUrl = "<%=request.getContextPath()%>/say.do?name=" + $(‘#name‘).val();

        $.ajax({
            type: ‘get‘,
            url: myUrl,
            dataType: ‘json‘,
            success: function(data, result) {
                alert(data.result);
            },
            error: function() {
                alert(‘error‘);
            }
        });
    });
});
</script>
</head>
<body>

<form id="helloForm" name="helloForm" method="post">
    Name: <input type="text" id="name" name="name" />&nbsp;
    <input type="button" id="say" name="say" value="哈囉"/>
</form>

</body>
</html>
时间: 2024-08-26 19:01:16

CXF - getting started的相关文章

WebService -- Java 实现之 CXF (初体验)

1. 认识WebService 简而言之,她就是:一种跨编程语言以及操作系统的远程调用技术. 大家都可以根据定义好的规范和接口进行开发,尽管各自的使用的开发语言和操作系统有所不同,但是由于都遵循统一的规范还有接口,因而可以做到透明和正常交互. 2. CXF 官方主页:http://cxf.apache.org/ 定义: Apache CXF is an open source services framework. CXF helps you build and develop services

CXF框架实现webservice实例

服务器端: 1.新建Web项目,例如CXF_Server,导入cxf-2.4.2的相关jar包,如下图所示: 2.新建一个webservice服务接口MyService,该接口通过注解来暴露服务:  package com.founder.service; import javax.jws.WebService; @WebService(serviceName="MyServiceManage") public interface MyService { /**  * add():定义

CXF+Spring+JAXB+Json构建Restful服务

话不多说,先看具体的例子: 文件目录结构: web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://

cxf在cmd中通过wsdl2java生成客户端文件

首先到cxf官方网站下载cxf的组件:http://cxf.apache.org/download.html 我下载的是apache-cxf-3.1.0这个版本,然后通过在浏览器中打开webservice url,保存wsdl文件,如loginService.xml cd 进入apache-cxf-3.1.0\bin目录 执行命名: E:\apache-cxf-3.1.0\bin>wsdl2java -p com.service.cxf -d e:\workspaces\testproject\

[CXF REST标准实战系列] 二、Spring4.0 整合 CXF3.0,实现测试接口

Writer:BYSocket(泥沙砖瓦浆木匠) 微博:BYSocket 豆瓣:BYSocket Reprint it anywhere u want. 文章Points: 1.介绍RESTful架构风格 2.Spring配置CXF 3.三层初设计,实现WebService接口层 4.撰写HTTPClient 客户端,并实现简单调用 介绍RESTful架构风格 REST是REST之父Roy Thomas创造的,当时提出来了REST的6个特点:客户端-服务器的.无状态的.可缓存的.统一接口.分层系

osgi应用使用桥接的方式打成war包部署在websphere上时遇到的与cxf相关的问题

原来我们的程序都是基于Equinox架构的,但是后面因为要实现打成war包在中间件中部署的需求,使用了eclipse官方提供的桥接方式实现. 桥接的部分后面有时间了我专门写一个文章来说,不明白的暂时请参考eclipse官方文档.这里主要说一下已经桥接成功,但是在使用CXF时遇到问题的情况. 本来在其他中间件里跑得好好的程序,一放到websphere_v8里,就各种报错,都是与axis2有关的,但是我们的项目并没有使用axis2,而是使用cxf. 报错类似如下(我有3个环境,每个报的错都不同,不过

【Apache CXF】CXF对JAX-RS的支持

用CXF构建RESTful services有两种方式:·CXF对JAX-RS的实现.·使用JAX-WS Provider/Dispatch API.官网上还有Http Bindings方式,他需要做一些繁琐的工作去创建资源再映射到服务上,这种方式从2.6时已经被移除了.刚好我这里有几个工程都是用第一种方式实现的,在这里便主要记录一下spring+CXF构建RESTful service. 首先列举一下JAX-RS的一些常用注解.·@Path:指定资源的URI.·@Produces/@Consu

Eclipse+CXF框架开发Web服务实战

一. 说明 采用CXF框架开发webservice. 所用软件及版本如下. ? 操作系统:Window XP SP3. ? JDK:JDK1.6.0_07,http://www.oracle.com/technetwork/java/javase/downloads/index.html. ? Tomcat:apache-tomcat-6.0.14.exe,http://tomcat.apache.org/. ? IDE:eclipse-jee-juno-SR1-win32.zip,http:/

WebService的讲解 和 CXF 的初步使用

1. 复习准备 1.1. Schema约束 几个重要知识: namespace 相当于schema文件的id targetNamespace属性 用来指定schema文件的namespace的值 xmlns属性 引入一个约束, 它的值是一个schema文件的namespace值 schemaLocation属性 用来指定引入的schema文件的位置   schema规范中: 1. 所有标签和属性都需要有schema文件来定义 2. 所有的schema文件都需要有一个id, 但在这里它叫names

webservice的简单使用,cxf框架的的使用

Web service是一个平台独立的,低耦合的,自包含的.基于可编程的web的应用程序,可使用开放的XML(标准通用标记语言下的一个子集)标准来描述.发布.发现.协调和配置这些应用程序,用于开发分布式的互操作的应用程序. Web Service技术, 能使得运行在不同机器上的不同应用无须借助附加的.专门的第三方软件或硬件, 就可相互交换数据或集成.依据Web Service规范实施的应用之间, 无论它们所使用的语言. 平台或内部协议是什么, 都可以相互交换数据.Web Service是自描述.