Developed using CXF WebService server side notes _

sponsored links
Developed using CXF WebService server side notes _

1, to achieve the functions:

To achieve the functionality is very simple server-side to provide a user password under the login name check services, as a String type of input parameters, the return value is String type, is indeed very simple, simply could not be more simple.

What is not here to explain the meaning of CXF, CXF Why should these academic problems, do not know the answer of their own to baidu and google to find out.

2, implementation steps:

Our web project from an empty to begin with, step by step shows how to perform and verify.

2.0 Preparing Files:

Download the release CXF file, download the address is http://cxf.apache.org/download.html, I downloaded the latest version is 2.2.7, unzipped directly into the apache-cxf-2.2.7/lib, the jar file in the directory stored separately and will be imported into the web project. A total of 66 files more then 26MB.

New web 2.1 project webproject, into the jar cxf file, and then modify the web.xml file:

<context-param>

<param-name> contextConfigLocation </ param-name>

<param-value> classpath *: application *. xml </ param-value>

</ Context-param>

<listener>

<listener-class>

org.springframework.web.context.ContextLoaderListener

</ Listener-class>

</ Listener>

<! - The first two on Needless to say, here is our concern CXF configuration ->

<servlet>

<servlet-name> CXFServlet </ servlet-name>

<servlet-class>

org.apache.cxf.transport.servlet.CXFServlet

</ Servlet-class>

<load-on-startup> 1 </ load-on-startup>

</ Servlet>

<servlet-mapping>

<servlet-name> CXFServlet </ servlet-name>

<url-pattern> / services / * </ url-pattern>

</ Servlet-mapping>

This is only the prelude, the following steps of writing into the service.

2.2 write server-side services and configuration CXF

Service interface file code is as follows:

package com.demo.service.userinfo;

import javax.jws.WebService;

@ WebService / / WebService annotation using jws

/ / If not the label, can not be published as web services, and know not?

public interface IUserService (

public String getPassword (String loginName);

)

Service implementation class file code is as follows

package com.demo.service.userinfo.impl;



import javax.jws.WebService;



import com.demo.service.userinfo.IUserService;



@ WebService / / WebService annotation using jws

/ / If not the label, can not be published as web services, and know not?

public class UserServiceImpl implements IUserService (



@ Override

public String getPassword (String loginName) (

System.out.println ("Server's getPassord () is called:" + loginName);

return loginName + "'s password = 123456";

/ / This is the demo program, so casually written, formal development and the right to remove debugging information

)



)

CXF configuration: configure a file in src applicationContext_cxf.xml, which reads as follows:

<Beans xmlns = "http://www.springframework.org/schema/beans"

xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"

xmlns: jaxws = "http://cxf.apache.org/jaxws"

xmlns: soap = "http://cxf.apache.org/bindings/soap"

xsi: schemaLocation = "

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd

http://cxf.apache.org/jaxws

http://cxf.apache.org/schemas/jaxws.xsd ">

<import resource="classpath:META-INF/cxf/cxf.xml" />

<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />

<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<! - This configuration of three lines do not have to check whether the path corresponds to the corresponding file will be automatically generated for cxf ->

<bean/>

<!-UserInfoService do not have to explain that this is a typical Spring configuration, development, suggested by Spring2.5 annotation ->

<Jaxws: endpoint

/ / This should be configured as a client to use to do it, note that I use the web to identify it

implementor = "# userService" / / This is the quote above userService

address = "/ callUserService">

/ / This is the web address of the service call, know why I call the right to use, easy to understand, right?

</ Jaxws: endpoint>

</ Beans>

Note in the above program I write does not increase so much, no time to add the first, second and superfluous, it is proposed ctrl + c and ctrl + v to a certain number of students to pay attention to the matter, do not say my program has problem.

It now has a problem: configured so long, how do not see the wsdl document? No wsdl file, how do you know did the right thing ah? According to the above configuration, visit the URL wsdl how much ah? Guess what?

http://127.0.0.1:8089/webproject/services/callUserService?wsdl

Wsdl the URL can be absurd to access the value of it? (IP address and port number to change based on actual needs its own) If not, you should carefully reflect on friends. Well, we look at the content of our userService the wsdl. See attachment picture.

Server-side steps that done? What do you think about it, right? No, worse last step is to code the client needs into a jar file guide, to return to the client for debugging. Then we complete this final step it.

At the same time with the mouse to select com.demo.service.userinfo and com.demo.service.userinfo, then: Right - "Export .... -" Java -> Jar file - "select save path and file name, save me as "ws.userinfo.jar".
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Developed using CXF WebService server side notes _

  • Build flex + spring + blazeds + hibernate application

    Build flex + spring + blazeds + hibernate application First, set up the project blazeds 1, will blazeds.war extract to a directory, such as: myflex /; 2, set up java works were such as: MyFlex, in the orientation of selection create project from exis ...

  • Hibernate connection pool configuration

    Hibernate connection pool configuration <! - Jdbc -> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </ property> <property name="connection.url"> jdbc: oracle: thin: @ 10.203.14.132:15

  • hibernate generic generic DAO

    package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • Servlet brief introduction

    Servlet brief introduction: Servlet is a small application server Are used to complete the B / S architecture, the client requests the response to treatment Platform independence, performance, able to run thread Servlet API for Servlet provides the s ...

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

  • Hibernate secondary cache

    Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

  • Great collection of java interview topics

    1, object-oriented features of what has 1. Abstract: Abstract is that it has overlooked a subject has nothing to do with the current goal of those aspects in order to more fully with the current objectives of the attention-related aspects. Abstract does n

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries