[Daily] basic steps for developing cxf-based Web Services in eclipse

Source: Internet
Author: User

Something I used to play for a long time ago, I had to go to a buddy yesterday to provide him with a service, so I had to think about it again, because I had a little knowledge about Java and only stayed at the layer of pictures and tigers, however, luck is good. In addition, I have encountered many setbacks before, so the configuration is still smooth. Record in csdn to avoid forgetting.

Sequence:

 

Preparations

1 eclipse3.4

2 jdk1.5

3 Tomcat 6

4 Tomcat plugin v3.2.1

5 cxf Development Kit 2.2.5

 

Ii. Configuration Environment

1. Install JDK

2 Copy eclipse & tomcat6 & cxf to the place where you want to put them (eclispe does not need to be installed, and tomcat does not need to be installed from 6)

3. Configure the environment variables as follows:
Reference

Set cxf_home = C:/cxf2.1
Set java_home = C:/Java/jdk1.5.0 _ 09

Set Path = % java_home %/bin; % cxf_home %/bin; % PATH %
Set classpath =.; % cxf_home %/lib/cxf-manifest.jar;./build/classes

4. Decompress Tomcat plugin v3.2.1 to the eclipse plugin directory.

 

3. Development Process

Apache and IBM have detailed documentation on the development process,

Eg: http://www.ibm.com/?works/cn/webservices/ws-pojo-springcxf /.

I will summarize only one problem that may occur during the process. (Feasible source code will be attached later)

1. eclispe can be used to create a new common Java project, but it seems that myeclipse can only be created in a web project.

2. There are two ways to expose a service: jaxws: endpoint and jaxws: Server. The difference between them is explained in detail on the Internet. You can choose either of them.

3. Sometimes, eclipse will prompt that the endpoint cannot be found. There is no problem, go on

4. You need to deploy a project to Tomcat and write an XML file to the Tomcat directory:

Refer:

<? XML version = "1.0" encoding = "UTF-8"?>
<Context docbase = "E:/self-code/javacode/eclipse34_workspace/your project name, which must be correct and case-sensitive"/>

Suggestion: it is best to use English as the directory. Otherwise, binary data cannot be read when different edits are used. For example, after the above "self" is written in notepad,

Sometimes errors occur during eclipse execution. If you use eclipse to open it, you will find that this notepad can open and see "yourself". Due to coding problems, it may not work in eclipse.

Normally displayed and needs to be modified.
5. interfaces and class-added @ WebService will be exposed, and you can also selectively expose them.

6. Attach a feasible code reference:

[1] class interface (the function name is random and has nothing to do with parameters)

Package ws. cxf;

Import javax. JWS. WebService;

@ WebService
Public interface iauthenservice
{
Public String clientservice (string footname, int num );
}

[2] category

/**
*
*/
Package ws. cxf;

Import javax. JWS. WebService;

Import ws. cxf. iauthenservice;

@ WebService
Public class authenservice implements iauthenservice
{
Private string myfootname = "potatoandtomato ";
Private int eatnum = 1000;
 
Public static void main (string [] ARGs)
{
System. Out. println ("Hello, world! Jo 1 ");
}

Public String clientservice (string footname, int num)
{
String result = "";
If (this. myfootname. Equals (footname ))
{
Result = "you can't eat this anymore, buddy! ";
}
Else
{
Result = "you can still eat, strong! ";
If (Num <this. eatnum)
{
Result + = "Unfortunately, you have no more! ";
}
Else
{
Result + = "wait a moment. I will give it to you later! ";
}
}
Return result;
}
 
Public String getmyfootname (){
Return myfootname;
}

Public void setmyfootname (string myfootname ){
This. myfootname = myfootname;
}

Public int geteatnum (){
Return eatnum;
}

Public void seteatnum (INT eatnum ){
This. eatnum = eatnum;
}

}

 

[3] configure the exposure service XML

<Beans xmlns = "http://www.springframework.org/schema/beans"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xmlns: jaxws = "http://cxf.apache.org/jaxws"
Xsi: schemalocation = "http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
Http://cxf.apache.org/jaxws
Http://cxf.apache.org/schemas/jaxws.xsd>
<! -- Import Apache cxf bean definition -->
<Import resource = "classpath: META-INF/cxf. xml"/>
<Import resource = "classpath: META-INF/cxf/cxf-extension-soap.xml"/>
<Import resource = "classpath: META-INF/cxf/cxf-servlet.xml"/>

<! -- Eatservice -->
<Bean id = "myservice2" class = "ws. cxf. authenservice">
<Property name = "myfootname" value = "Qiao"/>
<Property name = "eatnum" value = "10"/>
</Bean>

<! -- Expose eatwebservice -->
<Jaxws: endpoint id = "eatwebservice2" servicename = "authensrv" address = "/accesscontroldomain/access">
<Jaxws: implementor ref = "myservice2"/>
</Jaxws: endpoint>

</Beans>

 

4. project configuration file XML: placed under the WEB-INF

 

<? XML version = "1.0" encoding = "UTF-8"?>
<Web-app version = "2.4" xmlns = "http://java.sun.com/xml/ns/j2ee"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<Description> description displayed in Tomcat Manager </description>
<Display-Name> name displayed in cat manager </display-Name>
<! -- Spring config location -->
<Context-param>
<Param-Name> contextconfiglocation </param-Name>
<Param-value> classpath *:/beanrefserver. xml </param-value>
</Context-param>
<! -- Spring contextloaderlistener -->
<Listener>
<Listener-class> org. springframework. Web. Context. contextloaderlistener </listener-class>
</Listener>
<! -- Apache cxfservlet -->
<Servlet>
<Servlet-Name> cxfservlet </servlet-Name>
<Servlet-class> org. Apache. cxf. Transport. servlet. cxfservlet </servlet-class>
<Load-on-startup> 1 </load-on-startup>
</Servlet>
<! -- Cxfservlet Mapping -->
<Servlet-mapping>
<Servlet-Name> cxfservlet </servlet-Name>
<URL-pattern>/* </url-pattern>
</Servlet-mapping>
<Login-config>
<Auth-method> basic </auth-method>
</Login-config>
</Web-app>

 

 

7. Run Tomcat: If you are prompted that the port is occupied, check whether oracle is installed on your computer. It automatically installs the apache service and occupies port 8080. You need to modify one of the ports, replace 8080 with an uncommon port in the corresponding configuration file, such as 8088.

 

8. Visit "127.0.0.1: 8080" in the browser. The Tomcat homepage is displayed. Click "Tomcat Manager". If you have configured tomcat,

In Tomcat 6, the user configuration information is placed in the tomcat-user.xml under its Directory, which is commented out by default, you need to remove the annotator, and then add a role Manager

The following figure shows the user tomcat.

<Tomcat-users>
<Role rolename = "Tomcat"/>
<Role rolename = "role1"/>
<User Username = "Tomcat" Password = "Tomcat" roles = "tomcat, Manager"/>
<User Username = "both" Password = "Tomcat" roles = "tomcat, role1"/>
<User Username = "role1" Password = "Tomcat" roles = "role1"/>
</Tomcat-users>

After entering Tomcat Manager, you can view your deployed project and click it to access it.

 

9 Oracle OSB can perform browser-based tests similar to Microsoft Web services. It is very convenient if you need to try it.

 

The above description is here. I feel that I have encountered many small problems before, but I cannot remember it for a moment. Let's do it first.

 

Appendix: For details about Microsoft's service development and UDDI deployment, refer to an article I wrote on computer programming and skills.

Some findings about the deployment of UDDI may be hard to find on the Internet.

Http://www.cqvip.com/qk/98258x/201005/33119616.html.

 

Note: I have read a very detailed article on cxf development in my resources, with 1 point.

 

Appendix:

[1] view Tomcat Manager

 

 

 

[2] Release page:

 

That's all.

Good luck 2 U.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.