朱杰兵blog

jonhney'blog
posts - 140, comments - 1, trackbacks - 0, articles - 0

通过HttpClient请求webService 

由于服务端是用webService开发的,android要调用webService服务获取数据,这里采用的是通过HttpClient发送post请求,获取webService数据。
 
服务端使用的webService框架是axis2,请求数据之前,要封装一个xml格式,再通过post请求,获取服务端数据。
请求的xml格式如下所示: 
1 <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"xmlns:sam="http://user.service.xxx.com">
2    <soap:Header/>
3    <soap:Body>
4       <sam:getUserInfo>
5      <sam:userName>sunlightcs</sam:userName>
6       </sam:getUserInfo>
7    </soap:Body>
8 </soap:Envelope>
其中:getUserInfo是方法名,userName是参数名,当然,还可以加多个参数。
 
 
下面的代码是向webService发送请求,获取数据,返回的数据是xml形式的,android只要解析xml数据,就可以获得想要的数据了。 

01 import java.io.IOException;
02 import java.io.OutputStream;
03 import java.io.OutputStreamWriter;
04 import java.io.Writer;
05  
06 import org.apache.http.HttpResponse;
07 import org.apache.http.client.HttpClient;
08 import org.apache.http.client.methods.HttpPost;
09 import org.apache.http.entity.ContentProducer;
10 import org.apache.http.entity.EntityTemplate;
11 import org.apache.http.impl.client.DefaultHttpClient;
12 import org.apache.http.util.EntityUtils;
13  
14  
15 public class ClientTest {
16  
17     public static void main(String[] args) {
18         ClientTest.httpClientPost();
19     }
20      
21     private static void httpClientPost() {
22         HttpClient client = new DefaultHttpClient();
23         HttpPost post = newHttpPost("http://localhost:8080/xxx/services/userService");
24          
25         try {
26             ContentProducer cp = new ContentProducer() {
27                 public void writeTo(OutputStream outstream) throwsIOException {
28                     Writer writer = new OutputStreamWriter(outstream,"UTF-8");
29                      
30                     /**
31                      * 获取请求的xml格式数据
32                      */
33                     String requestXml = getRequestXml();
34                     writer.write(requestXml);
35                     writer.flush();
36                 }
37             };
38  
39             post.setEntity(new EntityTemplate(cp));
40             HttpResponse response = client.execute(post);
41              
42         //打印返回的xml数据
43             System.out.println(EntityUtils.toString(response.getEntity()));
44         catch (IOException e) {
45             e.printStackTrace();
46         }
47     }
48      
49      
50     private static String getRequestXml(){
51         StringBuilder sb = new StringBuilder("<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:sam=\"http://user.service.xxx.com\">");
52         sb.append("<soap:Header/>");
53         sb.append("<soap:Body>");
54         sb.append("<sam:getUserInfo>");
55         sb.append("<sam:userName>sunlightcs</sam:userName>");
56         sb.append("</sam:getUserInfo>");
57         sb.append("</soap:Body>");
58         sb.append("</soap:Envelope>");
59          
60         return sb.toString();
61     }
62  
63 }

返回的数据格式如下: 
1 <?xml version='1.0' encoding='UTF-8'?>
2 <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
3     <soapenv:Body>
4         <ns:getUserInfoResponse xmlns:ns="http://user.service.xxx.com">
5             <ns:return>xxx</ns:return>
6         </ns:getUserInfoResponse>
7     </soapenv:Body>
8 </soapenv:Envelope>
其中,<ns:return>内的"xxx"可以是json数据,android只需解析标签<ns:return>里的json数据即可。 
转载 http://www.juziku.com/wiki/3919.htm

posted @ 2017-05-24 16:10 朱杰兵 阅读(1201) | 评论 (0)编辑 收藏

netstat -pan|grep 7001
找到进程号,kill -9杀死
打开启动路径
nohup ./startWeblogic.sh &
tail -f nohup.out看启动日志
---------------------------
csh   服务端运行
ps -ef | grep weblogic
kiss -9 sid(左边id)
(
查看后台web进程 
#ps -ef|grep java 如: 
     root 123456 2346546 
    root 1346464    64646464 
杀后台进程 :#kill -9 1346464 
)
cd 到。。。bin/startWebLogic.sh &    注意大小写

posted @ 2017-04-26 19:53 朱杰兵 阅读(89) | 评论 (0)编辑 收藏

java.lang.ClassCastException: weblogic.xml.jaxp.RegistryDocumentBuilderFactory

解决办法

删掉war包中的xml-apis.jar就可以了

posted @ 2017-04-14 16:06 朱杰兵 阅读(100) | 评论 (0)编辑 收藏

右键pom文件 run as --> maven build,  goals填入相应命令,点run

打包
goals 输入 clean package

安装jar到仓库
goals 输入 clean install

测试
goals 输入 clean test

编译
goals 输入 compile

清除
goals输入 clean

 clean  清除编译,compile  编译,test  编译并测试,install 打包并发送到本地仓库,package 只是打成jar包,并不会发送到本地仓库

posted @ 2017-04-13 14:16 朱杰兵 阅读(175) | 评论 (0)编辑 收藏

posted @ 2017-04-12 17:50 朱杰兵 阅读(2459) | 评论 (0)编辑 收藏

public enum MessageLevel {
    LOW {
        @Override
        public String getDesc() {
            return "低";
                    
        }

        @Override
        public String getCode() {
            return "L";
        }

        @Override
        public String getIcon() {
            return "medal_bronze_1.png";
        }

    },
    HEIGH {

        @Override
        public String getDesc() {
            return "高";
        }

        @Override
        public String getCode() {
            return "H";
        }

        @Override
        public String getIcon() {
            return "medal_gold_1.png";
        }

    },
    NORMAL {

        @Override
        public String getDesc() {
            return "中";
        }

        @Override
        public String getCode() {
            return "N";
        }

        @Override
        public String getIcon() {
            return "medal_silver_1.png";
        }

    };
    
    public abstract String getDesc();

    public abstract String getCode();

    public abstract String getIcon();
}

  1. public static void main(String[] args)  
  2.     {  
  3.         System.out.println(MessageLevel.LOW.getDesc());  
  4.         System.out.println(MessageLevel.LOW.getCode());
  5.         System.out.println(MessageLevel.LOW.getIcon());
  6.     } 
-----------------------------------------------------------------------------------------------
  1. public enum Operation   
  2. {  
  3.     PLUS  
  4.     {  
  5.         public double eval(double x,double y)  
  6.         {  
  7.             return x+y;  
  8.         }  
  9.     },  
  10.     MINUS  
  11.     {  
  12.         public double eval(double x,double y)  
  13.         {  
  14.             return x-y;  
  15.         }  
  16.     },  
  17.     TIMES  
  18.     {  
  19.         public double eval(double x,double y)  
  20.         {  
  21.             return x*y;  
  22.         }  
  23.     },  
  24.     DIVIDE  
  25.     {  
  26.         public double eval(double x,double y)  
  27.         {  
  28.             return x/y;  
  29.         }  
  30.     };  
  31.     //为枚举类定义一个抽象方法,这个抽象方法由不同的枚举值提供不同的实现。  
  32.     public abstract double eval(double x,double y);  
  33.     public static void main(String[] args)  
  34.     {  
  35.         System.out.println(Operation.PLUS.eval(3,4));  
  36.         System.out.println(Operation.MINUS.eval(5,4));  
  37.         System.out.println(Operation.TIMES.eval(5,4));  
  38.         System.out.println(Operation.DIVIDE.eval(5,4));  
  39.     }  

posted @ 2017-04-07 11:19 朱杰兵 阅读(85) | 评论 (0)编辑 收藏

classpath

首先 classpath是指编译过后的WEB-INF文件夹下的的classes目录

  • 对于maven的所有项目, 配置文件一般放在resources目录下, 当编译之后会自动复制到classes目录下
  • 非maven的所有项目, 一般放在src目录下, 编译之后也会自动复制到classes目录下面.
  • 所有的web-app项目, 例如web.xml, spring的配置文件等等,是放在webapp/WEB-INF下面的,
    如果想要引用resources或者src目录下的配置文件, 就在在配置文件的路径前加上classpath:, 例如MyBatis配置文件的引用.
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  <property name="dataSource" ref="dataSource"/>  <property name="configLocation" value="classpath:MybatisConfiguration.xml"/>  <property name="mapperLocations" value="classpath*:com/tenlee/mapper/UserMapper.xml"/> </bean>
  • 如果不加的的话,那么都要把配置文件放在WEB-INF/目录下面, 但这样不能单独运行java类进行调试了,必须要启动整个webapp, 比如这样
    <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/configs/mvc-dispatcher.xml</param-value> </init-param>

classpath classpath* 区别:

  • classpath:只会到你的classes路径中查找找文件
  • classpath* :不仅包含classes路径,还包括jar文件classes路径进行查找
  • classpath:classpath*:的区别在于,前者只会从第一个classpath中加载,而后者会从所有的classpath中加载 如果要加载的资源,不在当前ClassLoader的路径里,那么用classpath:前缀是找不到的,这种情况下就需要使用classpath*:前缀.
  • 另一种情况下,在多个classpath中存在同名资源,都需要加载,那么用classpath:只会加载第一个,这种情况下也需要用classpath*:前缀.
  • 可想而知,用classpath*:需要遍历所有的classpath,所以加载速度是很慢的,因此,在规划的时候,应该尽可能规划好资源文件所在的路径,尽量避免使用classpath*

posted @ 2017-04-06 14:32 朱杰兵 阅读(173) | 评论 (0)编辑 收藏

     摘要: 如果你经常需要在Eclipse里打开相关资源文件所在的文件夹,比较麻烦,要右键,属性,在Location一栏中把所在的文件夹拷贝一下,然后再去资源管理器里输入这个路径,回车,然后打开它,比较麻烦。下载地址:http://download.csdn.net/download/lang791534167/8585091eclipse3.6以下的版本将下载的jar包复制到plugins目录下3.6以上包...  阅读全文

posted @ 2017-04-05 09:32 朱杰兵 阅读(108) | 评论 (0)编辑 收藏

     摘要: 解决方法: 步骤一: 从http://maven.oschina.net/content/groups/public/org/apache/maven/archetypes/maven-archetype-quickstart/ 下载最新版maven-archetype-quickstart-1.1.jar 步骤二: 命令行到下载目录下执行 mvn install...  阅读全文

posted @ 2017-03-31 11:13 朱杰兵 阅读(2205) | 评论 (0)编辑 收藏

properties文件默认应该显示为unicode编码,如果安装propertiesEditor插件后可显示为中文

如果没有安装插件,但显示中文,则程序调用属性文件会出现乱码问题,这样就需要手动来将中文转为unicode

直接使用JDK自带的工具:native2ascii.exe

运行cmd,直接用命令的形式,找到文件对应的目录,输入以下命令,

命令格式:native2ascii -encoding UTF-8 源文件名.properties 目标文件名.properties

就可以将含有中文的源文件转为unicode编码的目标文件

posted @ 2017-03-29 14:11 朱杰兵 阅读(119) | 评论 (0)编辑 收藏

仅列出标题
共14页: 上一页 1 2 3 4 5 6 7 8 9 下一页 Last