JBoss-Net Hello World Example

本文介绍了JBoss-Net Hello World示例,该示例集成了Apache Axis。文中说明了搭建所需的环境,如安装JBoss、Jakarta Ant等,还介绍了创建Java类、编写web-service.xml文件、打包部署等步骤,以及使用Ant和构建文件的项目示例,最后展示了如何测试服务。

JBoss-Net Hello World Example
This builds a simple example showing what can be done
with JBoss-Net which integrates Apache Axis.
Updated 29 August 2004

This example works with the newest builds of JBoss.NET that use Apache axis 1_1 for its core. Therefore you may need to change the code to work with the correct API, if you have an earlier version. In any case you need to download the Axis version so that you can code to the correct API, and have the Axis docs for details about the utilities, which come with Axis.
 
This assumes a number of things are already set up on your machine.

That you have a running version of JBoss with JBoss-Net installed. It shouldn't matter if you have the Jetty or Tomcat version. If not then you first need to go here to get the distribution.
That you have Jakarta Ant installed and ready to use, as discussed here.
That you have added the axis.jar from the relevant axis distro to your classpath. You need this for two things:
to use the tcpmon for debugging
to have the documentation and AP
 
If you are doing this exercise with a JBoss-3.0.x distro, then you will need to make a few changes to the code as we go along in order for it to work for you. Before you go any further, make sure that you've made the changes to your jboss-net.sar file discussed under the general jboss-net Guide page. Once you've done that, ie turned the jboss-net.sar file into a directory, then come back here.
This exercise assumes that you are using JBoss-3.2.x versions. This has jboss.net under the 'all' servewr option.
But if you first want to get your head around web services, then this will get you going on a smaller scale. In any case the principles are the same:

create a Java class
write a web-service.xml file
put these into a wsr archive
deploy on JBoss
access the service via a client application.
If you've looked over the Axis docs, then you'll have come across 'jws' files (ie 'java web service'), which are uncompiled Java source code, that is compiled on the fly by the Axis engine in the same way that jsp pages are compiled into servlets by Catalina.

JWS files don't seem to work in JBoss-Net. But that's not a big problem anyway. JBoss-Net remember is about integrating Axis into a J2EE server, and simple web services are unlikely to be deployed on it in anything other than testing and learning scenarios.

Instead, JBoss-Net needs to have a compiled class file deployed along with a deployment descriptor file bundled into an archive, which is then placed in the deploy directory of the JBoss server.

Axis by default uses a Web Services Deployment Descriptor (WSDD) for the configuration of web services. Under JBoss-Net this is a web-service.xml file.

JBoss-Net needs to have this web-service.xml file and put into a Web Service aRchive (WSR) along with the Java classes for the service. This lets you drop the wsr file into the running JBoss server where it will hot deploy.

However, it does not seem to update itself if you change the class file, rebundle it, and then drop in a new wsr file. This sort of change on the fly works with war files, but NOT at present with wsr files. If you want to make changes, then you will need to first undeploy the service. I've experimented with the <undeployment> WSDD files mentioned in the Axis docs. However, this didn't seem to work. So, for the moment, you need to delete the wsr file from the deploy directory, stop the server, and then restart it.

Now for the sample application, which uses Ant and build files for the project. Ok, it might be considered overkill, but as always Ant speeds up the edit, compile, copy, jar, etc routine.

You can download the code and build files in a zip file from here

The directory structure that you need to create looks like this:

jboss-axis

main

src

client

META-INF

web

WEB-INF

build.xml sit under jboss-axis (or whatever you want to call the directory).

web-services.xml sits under META-INF

testHelloWorld.java sits under main/src

testClient.java sits under main/client

Nothing actually goes into the web or WEB-INF directories, but are there for later use when you tie your application into web resources. If you want to, then you can put a placeholder index.html page under web.
 
First, the build.xml script, which is simple and short. You will need to make sure that you have JBOSS_DIST set in your environment.

<fileset dir="{jboss.home}/server/all/deploy/jboss-net.sar"> so that it becomes

<fileset dir="{jboss.home}/server/all/deploy/jboss-net.ear/jboss-net.sar"> and then it can find the axis.jar, wsdl4j.jar, etc which it needs to complile.
 
<project name="testHelloWorld" default="dist" basedir=".">

<property name="app.name" value="testHelloWorld"/>
<property environment="env" />
<property name ="jboss.home" value="{env.JBOSS_DIST}" />
<property name="deploy.home" value="{jboss.home}/server/all/deploy"/>

<property name="dist.home" value="{deploy.home}"/>
<property name="dist.src" value="{app.name}.jar"/>
<property name="dist.wsr" value="{app.name}.wsr"/>
<property name="dist.war" value="{app.name}.war"/>
<property name="dist.ear" value="{app.name}.ear"/>
<property name="javadoc.home" value="javadoc"/>

<property name="build.jboss-axis.dir" value="{basedir}/build"/>
<property name="build.classes.dir" value="{basedir}/build/classes"/>

<!-- need to add in details of src.dir -->
<property name="src.dir" value ="{basedir}"/>

<!-- the other jars for axis, servlets, etc are added to the classpath
This assumes they are under server/all
-->
<path id="base.libraries">

<fileset dir="{jboss.home}/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="{jboss.home}/server/all/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="{jboss.home}/server/all/deploy/jboss-net.sar">
<include name="*.jar"/>
</fileset>

</path>

<target name="clean">
<delete dir="{build.jboss-axis.dir}"/>
</target>

<target name="validate">

<available property="classpath_id" value="base.libraries" file="{jboss.home}/server/all/lib/jboss.jar" />

</target>

<target name="fail_if_not_valid" unless="classpath_id">

<fail message="jboss.home={jboss.home} is not a valid JBoss dist directory " />

</target>

<target name="prepare" depends="clean, validate, fail_if_not_valid">
<mkdir dir="{build.classes.dir}"/>
<mkdir dir="{build.classes.dir}/client" />
<mkdir dir="{build.classes.dir}/WEB-INF"/>
<mkdir dir="{build.classes.dir}/WEB-INF/classes"/>
<mkdir dir="{build.classes.dir}/META-INF"/>
<mkdir dir="{javadoc.home}"/>


<!-- set the classpath for compiling files -->
<property name="classpath" refid="{classpath_id}" />


<!-- now copy across the files -->
<!-- <copy file="main/testHelloWorld.java" todir="{build.classes.dir}"/> -->
<copy todir="{build.classes.dir}">
<fileset dir="{src.dir}/web">
<include name="**/*"/>
</fileset>
</copy>

<copy todir="{build.classes.dir}/WEB-INF">
<fileset dir="{src.dir}/WEB-INF">
<include name="**/*"/>
</fileset>
</copy>

<copy todir="{build.classes.dir}/META-INF">
<fileset dir="{src.dir}/META-INF">
<include name="**/*"/>
</fileset>
</copy>
</target>

<target name="compile" depends="prepare">
<javac srcdir="main" destdir="{build.classes.dir}"
classpath="{build.classes.dir}"
debug="on" optimize="off" deprecation="on">
<classpath path="{classpath}" />
</javac>
<copy todir="">
<fileset dir="{src.dir}/main/src">
<include name="main/src/testHelloWorld.*"/>
</fileset>
</copy>
<!-- copy the client class file back to the client directory -->
<copy file="{build.classes.dir}/testClient.class" todir="{src.dir}/main/client"/>
</target>

<target name="javadoc" depends="prepare">
<javadoc sourcepath="src" packagenames="*"
destdir="{javadoc.home}"/>
</target>

<!-- axis doesn't like it this way, so will wrap the wsr file in a war file -->
<!-- build the wsr file -->
<target name ="wsr" depends="prepare,compile">


<jar jarfile="{build.jboss-axis.dir}/{dist.wsr}"
basedir="{build.classes.dir}">
<include name="testHelloWorld.class" />
<include name="META-INF/web-service.xml" />
</jar>
<copy file="{build.jboss-axis.dir}/{dist.wsr}" todir="{build.classes.dir}"/>
</target>

<!-- now build the war file -->
<target name="war" depends="wsr">
<jar jarfile="{build.jboss-axis.dir}/{dist.war}"
basedir="{build.classes.dir}">
<include name="index.html" />
<include name="WEB-INF/web.xml" />
<include name="WEB-INF/jboss-web.xml" />
</jar>
<copy file="{build.jboss-axis.dir}/{dist.war}" todir="{build.classes.dir}"/>
</target>

<!-- now build the ear file -->
<target name="ear" depends="war">
<jar jarfile="{build.jboss-axis.dir}/{dist.ear}"
basedir="{build.classes.dir}">
<include name="META-INF/application.xml" />
<include name="{dist.war}" />
<include name="{dist.wsr}" />
</jar>
</target>
<target name="dist" depends="wsr">
<copy file="{build.jboss-axis.dir}/{dist.wsr}" todir="{deploy.home}" />

</target>


</project>
 
Second, the web-service.xml file, which goes under the META-INF directory.
<!-- Example bare bones Web Service Deployment Descriptor -->
<deployment
xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

<service name="testHelloWorld" provider="java:RPC">
<parameter name="className" value="testHelloWorld"/>
<parameter name="allowedMethods" value=" getHelloWorldMessage"/>
</service>

</deployment>
 
Third, the Java source class, which goes under main/src.
public class testHelloWorld {
public testHelloWorld() {
}

public String getHelloWorldMessage(String name){
return "Hello world to " + name;
}
}
 
Fourth, the client to test the application, which goes under main/client.
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;


public class testClient
{
public static void main(String [] args) {
try {
String endpoint =
"http://localhost:8070/jboss-net/services/testHelloWorld";
String methodName = "getHelloWorldMessage";

Service service = new Service();
Call call = (Call) service.createCall();

call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName(methodName);

call.addParameter("name",
org.apache.axis.Constants.XSD_STRING,
ParameterMode.IN);
call.setReturnType(org.apache.axis.Constants.XSD_STRING);

String ret = (String) call.invoke( new Object[] { "AXIS!" } );

System.out.println(ret);
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
 
Fifth, the runClient.bat file which goes under main/client and pulls together the appropriate classpath for you to run the client. You can probably do away with some of the jar files in the first batch. Indeed, you may find problems with the length of this line.
@echo off

rem bat to run client

set TEMP_CP=%TEMP_CP%

set JBOSS=C:/Java/jboss-tomcat/jboss rem now add client jars to classpath which jboss needs to run

set TEMP_CP=.;%JBOSS%/catalina/common/lib/servlet.jar;%JBOSS%/client/concurrent.jar;
%JBOSS%/client/jboss-common-client.jar;%JBOSS%/client/jboss-client.jar;
%JBOSS%/client/jboss-j2ee.jar;%JBOSS%/client/jaas.jar;
%JBOSS%/client/jboss-jsr77.jar;%JBOSS%/client/jcert.jar;
%JBOSS%/client/jboss-net-client.jar;%JBOSS%/client/gnu-regexp.jar;
%JBOSS%/client/jbosssx-client.jar;%JBOSS%/client/log4j.jar;%JBOSS%/client/jnet.jar;
%JBOSS%/client/jnp-client.jar;%JBOSS%/client/jsse.jar;%JBOSS%/client/jacorb.jar;
%JBOSS%/client/jbossmq-client.jar;%JBOSS%/client/getopt.jar;
%JBOSS%/client/jboss-iiop-client.jar;%JBOSS%/client/jbossmx-ant.jar;
%JBOSS%/client/jboss-system-client.jar;%JBOSS%/client/jboss-transaction-client.jar

rem add in the classpath to the axis required jar files

set TEMP_CP=%TEMP_CP%;%JBOSS%/server/all/deploy/jboss-net.sar/axis.jar;%JBOSS%/server/all/deploy/jboss-net.sar/jaxrpc.jar;
%JBOSS%/server/all/deploy/jboss-net.sar/saaj.jar;
%JBOSS%/server/all/deploy/jboss-net.sar/wsdl4j.jar;
%JBOSS%/server/all/deploy/jboss-net.sar/commons-logging.jar;
%JBOSS%/server/all/deploy/jboss-net.sar/commons-discovery.jar

set TEMP_CP=%TEMP_CP%;%CLASSPATH%

java -classpath %TEMP_CP% testClient %1 %2 %3 %4 %5
 
With all of the files in their right spot, open a console in the same directory as the build.xml file and enter this command: build

This will process the main target, which will compile the class files, build the wsr file, and copy the compiled client class back to the client directory. It also puts the wsr file into the deploy directory of your JBoss server. You should see some output in the console window telling you what is happening.

Any errors that you encounter are probably due to missing items in your classpath, as the build.xml script checks that all of the Axis required jars are in your classpath. If jars are missing, then they will appear as errors, class not found.

Open a browser and navigate to

http://localhost:8080/jboss-net/servlet/AxisServlet where you should see a list of items, including your newly deployed service at the bottom of the page. Now navigate to

http://localhost:8080/jboss-net/services/testHelloWorld?wsdl where you should see the wsdl details of your application. Note that it provides the targetnamespace of http://localhost:8080/jboss-net/services/testHelloWorld which is where we find the webservice.

Some of you will realise that the client goes to http://localhost:8070/jboss-net/services/testHelloWorld, and wonder what gives. Well, it's an excuse to introduce another debug tool, the tcpmon which comes with Axis. The tcpmon intercepts messages on one port (ie 8070), shows them in one window, and then redirects the message to its designated port (ie 8080) and picks up the response.

Open another console window and enter this command (assuming that you have added the axis.jar to your classpath. Unfortunately, I have found that this ONLY works if the axis.jar is in your system classpth.):

java org.apache.axis.utils.tcpmon

You should have a Swing application open up. Put 8070 in the 'Listen Port #' textfield, put localhost in the 'Target hostname' textfield, and 8080 in the 'Target Port #' textfield. The radio button for 'Act as a listener' should be selected. Now click 'add' and a new tab 'Port 8070' should appear. Select it.

Open another console window and navigate to the jboss-axis/main/client directory and run the command:

runClient

You should see "Hello World to AXIS!" appear in your client console window, and both the sent and received SOAP messages in the tcpmon windows.

That's it, you've done it. You built a simple application, deployed it on JBoss-Net and discovered how similar it is to the raw Axis, which sits on the server.

I've also done a Hello World using EJB-JSP example with JBoss-Net which you can find here.

You can also go through the jboss-net examples from the cvs files at Sourceforge to also browse through. Go to:

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jboss/contrib/jboss.net/ and look under samples and testsuite. Needless to say, these only give you some indication of what's going on, and you really should build JBoss-Net from the sourcecode as described in a howto here.

这个是完整源码 python实现 Django 【python毕业设计】基于Python的天气预报(天气预测分析)(Django+sklearn机器学习+selenium爬虫)可视化系统.zip 源码+论文+sql脚本 完整版 数据库是mysql 本研究旨在开发一个基于Python的天气预报可视化系统,该系统结合了Django框架、sklearn机器学习库和Selenium爬虫技术,实现对天气数据的收集、分析和可视化。首先,我们使用Selenium爬虫技术从多个天气数据网站实时抓取气象数据,包括温度、湿度、气压、风速等多项指标。这些数据经过清洗和预处理后本研究旨在开发一个基于Python的天气预报可视化系统,该系统结合了Django框架、sklearn机器学习库和Selenium爬虫技术,实现对天气数据的收集、分析和可视化。首先,我们使用Selenium爬虫技术从多个天气数据网站实时抓取气象数据,包括温度、湿度、气压、风速等多项指标。这些数据经过清洗和预处理后,将其存储在后端数据库中,以供后续分析。 其次,采用s,将其存储在后端数据库中,以供后续分析。 其次,采用sklearn机器学习库构建预测模型,通过时间序列分析和回归方法,对未来天气情况进行预测。我们利用以往的数据训练模型,以提高预测的准确性。通过交叉验证和超参数优化等技术手段,我们优化了模型性能,确保其在实际应用中的有效性和可靠性。 最后,基于Django框架开发前端展示系统,实现天气预报的可视化。用户可以通过友好的界面查询实时天气信息和未来几天内的天气预测。系统还提供多种图表类型,包括折线图和柱状图,帮助用户直观理解天气变化趋势。 本研究的成果为天气预报领域提供了一种新的技术解决方案,不仅增强了数据获取和处理的效率,还提升了用户体验。未来,该系统能够扩展至其他气象相关的应用场景,为大众提供更加准确和及时的气象服务。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值