少年阿宾

那些青春的岁月

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

#

/**
 *
 */
package com.abin.lee.cxf;

import javax.jws.WebService;

/**
 * @author abin
 *
 */
@WebService(targetNamespace="cxf.lee.abin.com")
public interface IUserService {
 public String getMessage(String message);
}





package com.abin.lee.cxf;

import javax.jws.WebService;

@WebService(endpointInterface="com.abin.lee.cxf.IUserService")
public class UserService implements IUserService{

 public String getMessage(String message) {
  return message+" welcome to beijing";
 }
 
}






<?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:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:jaxws="http://cxf.apache.org/jaxws"
 xmlns:cxf="http://cxf.apache.org/core"
 xmlns:wsa="http://cxf.apache.org/ws/addressing"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-beans-3.0.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
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-3.0.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" />
 
 <cxf:bus>
  <cxf:features>
   <!--日志拦截功能,用于监控soap内容,开发后可以删除 -->
   <cxf:logging/>
   <wsa:addressing/>
  </cxf:features>
 </cxf:bus> 

 <bean id="userService" class="com.abin.lee.cxf.UserService"></bean>
 <jaxws:endpoint id="userWebservice" implementor="#userService" address="/UserService" publish="true" />


</beans>

 





<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
   <!--
     classpath*:com/abin/lee/spring/queue/applicationContext-springqueue.xml,
     classpath*:com/abin/lee/quartz/applicationContext-quartzCluster.xml,
     classpath*:com/abin/lee/quartz/applicationContext-quartzHeartCluster.xml,
     classpath*:com/abin/lee/quartz/applicationContext-activemq.xml
   -->
   classpath*:com/abin/lee/cxf/applicationContext-cxf.xml
  </param-value>
 </context-param>
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 <!--cxf服务启动servlet-->
 <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>/service/*</url-pattern>   
 </servlet-mapping> 






package com.abin.lee.spring;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *
 * 获取spring容器,以访问容器中定义的其他bean
 *
 * @author lyltiger
 * @since MOSTsView 3.0 2009-11-16
 */
public class SpringContextUtil implements ApplicationContextAware {

 // Spring应用上下文环境
 private static ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
   "com/abin/lee/cxf/applicationContext-cxf.xml");

 /**
  * 实现ApplicationContextAware接口的回调方法,设置上下文环境
  *
  * @param applicationContext
  */
 public void setApplicationContext(ApplicationContext applicationContext) {
  SpringContextUtil.applicationContext = applicationContext;
 }

 /**
  * @return ApplicationContext
  */
 public static ApplicationContext getApplicationContext() {
  return applicationContext;
 }

 /**
  * 获取对象 这里重写了bean方法,起主要作用
  *
  * @param name
  * @return Object 一个以所给名字注册的bean的实例
  * @throws BeansException
  */
 public static Object getBean(String name) throws BeansException {
  return applicationContext.getBean(name);
 }

}









package com.abin.lee.cxf.test;

import com.abin.lee.cxf.UserService;
import com.abin.lee.spring.SpringContextUtil;

import junit.framework.TestCase;

public class TestUserService extends TestCase{
 public void testcxf(){
  UserService userService=(UserService)SpringContextUtil.getBean("userService");
  
  String response=userService.getMessage("abin");
  System.out.println("response="+response);
  System.exit(0);
 }
}


posted @ 2012-08-21 00:27 abin 阅读(876) | 评论 (0)编辑 收藏

     摘要: 1.实例化spring容器 和 从容器获取Bean对象 实例化Spring容器常用的两种方式: 方法一: 在类路径下寻找配置文件来实例化容器 [推荐使用] ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"beans.xml"}); 方法二: 在文件系统路径下寻找配置文件来实例化容器 [这...  阅读全文
posted @ 2012-08-20 12:34 abin 阅读(24180) | 评论 (2)编辑 收藏

package com.abin.lee.queue;

import java.util.Queue;

public interface IMakeQueue {
 public void addQueue(Object obj);
 public boolean hasQueue();
 public Object getQueueHeader();
 public int queueSize();
 public boolean delQueue();
}




package com.abin.lee.queue;

import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

public class MakeQueue implements IMakeQueue{
 private static Queue queue=new LinkedBlockingQueue();

 public void addQueue(Object obj) {
  queue.offer(obj);
 }

 public boolean hasQueue() {
  boolean flag=false;
  if(queue.isEmpty()){
   flag=true;
  }
  return flag;
 }

 public Object getQueueHeader() {
  Object obj=queue.peek();
  return obj;
 }

 public int queueSize() {
  int queueSize=queue.size();
  return queueSize;
 }

 public boolean delQueue() {
  boolean flag=false;
  Object obj=queue.poll();
  if(obj!=null){
   flag=true;
  }
  return flag;
 }
 
}






package com.abin.lee.queue;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *
 * 获取spring容器,以访问容器中定义的其他bean
 *
 * @author lyltiger
 * @since MOSTsView 3.0 2009-11-16
 */
public class SpringContextUtil implements ApplicationContextAware {

 // Spring应用上下文环境
 private static ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
   "com/abin/lee/spring/applicationContext-queue.xml");

 /**
  * 实现ApplicationContextAware接口的回调方法,设置上下文环境
  *
  * @param applicationContext
  */
 public void setApplicationContext(ApplicationContext applicationContext) {
  SpringContextUtil.applicationContext = applicationContext;
 }

 /**
  * @return ApplicationContext
  */
 public static ApplicationContext getApplicationContext() {
  return applicationContext;
 }

 /**
  * 获取对象 这里重写了bean方法,起主要作用
  *
  * @param name
  * @return Object 一个以所给名字注册的bean的实例
  * @throws BeansException
  */
 public static Object getBean(String name) throws BeansException {
  return applicationContext.getBean(name);
 }

}





package com.abin.lee.queue;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class QueueServlet extends HttpServlet{
 
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  Map map=request.getParameterMap();
  String name1=(String)((Object[])map.get("name1"))[0];
  String name2=(String)((Object[])map.get("name2"))[0];
  MakeQueue makeQueue = (MakeQueue)SpringContextUtil.getBean("makeQueue");//bean的名称
  System.out.println(makeQueue.queueSize());
  makeQueue.addQueue(name1);
  makeQueue.addQueue(name2);
  System.out.println(makeQueue.queueSize());
  
  ServletOutputStream out=response.getOutputStream();
  BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(out));
  writer.write("success");
  writer.flush();
  writer.close();
 }
}





package com.abin.lee.spring;

import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

public class SpringUnit extends TestCase {
 private static final String HTTP_URL="http://localhost:1010/WebService/servlet/QueueServlet";
 public void testBean() {
  HttpClient client=new DefaultHttpClient();
  HttpPost post=new HttpPost(HTTP_URL);
  try {
   List<NameValuePair> nvps=new ArrayList<NameValuePair>();
   nvps.add(new BasicNameValuePair("name1", "lee"));
   nvps.add(new BasicNameValuePair("name2", "abin"));
   post.setEntity(new UrlEncodedFormEntity(nvps,HTTP.UTF_8));
   HttpResponse response=client.execute(post);
   HttpEntity entity=response.getEntity();
   String result=EntityUtils.toString(entity);
   System.out.println("result="+result);
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}







<?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:aop="http://www.springframework.org/schema/aop"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd">

 <!-- Queue全局队列 -->
 <bean id="makeQueue" class="com.abin.lee.queue.MakeQueue" scope="singleton" />
 

</beans>

posted @ 2012-08-20 12:25 abin 阅读(2675) | 评论 (0)编辑 收藏

方法一:
package com.abin.lee.queue;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *
 * 获取spring容器,以访问容器中定义的其他bean
 *
 * @author lyltiger
 * @since MOSTsView 3.0 2009-11-16
 */
public class SpringContextUtil implements ApplicationContextAware {

 // Spring应用上下文环境
 private static ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
   "com/abin/lee/spring/applicationContext-queue.xml");

 /**
  * 实现ApplicationContextAware接口的回调方法,设置上下文环境
  *
  * @param applicationContext
  */
 public void setApplicationContext(ApplicationContext applicationContext) {
  SpringContextUtil.applicationContext = applicationContext;
 }

 /**
  * @return ApplicationContext
  */
 public static ApplicationContext getApplicationContext() {
  return applicationContext;
 }

 /**
  * 获取对象 这里重写了bean方法,起主要作用
  *
  * @param name
  * @return Object 一个以所给名字注册的bean的实例
  * @throws BeansException
  */
 public static Object getBean(String name) throws BeansException {
  return applicationContext.getBean(name);
 }

}





方法二:

package com.abin.lee.queue;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

public class BeanFactoryUtil {
 private static BeanFactory factory = new XmlBeanFactory(
   new ClassPathResource(
     "com/abin/lee/spring/applicationContext-queue.xml"));

 public static BeanFactory getFactory() {
  return factory;
 }

 public static void setFactory(BeanFactory factory) {
  BeanFactoryUtil.factory = factory;
 }
 
 public static Object getBean(String name){
  return factory.getBean(name);
 }
}







具体用法:

package com.abin.lee.queue;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class QueueServlet extends HttpServlet{
 
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  Map map=request.getParameterMap();
  String name1=(String)((Object[])map.get("name1"))[0];
  String name2=(String)((Object[])map.get("name2"))[0];
  MakeQueue makeQueue = (MakeQueue)BeanFactoryUtil.getBean("makeQueue");//bean的名称
  System.out.println(makeQueue.queueSize());
  makeQueue.addQueue(name1);
  makeQueue.addQueue(name2);
  System.out.println(makeQueue.queueSize());
  
  ServletOutputStream out=response.getOutputStream();
  BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(out));
  writer.write("success");
  writer.flush();
  writer.close();
 }
}



posted @ 2012-08-20 11:34 abin 阅读(2150) | 评论 (0)编辑 收藏

package com.abin.lee.sort;

import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class CollectionIterator {
 /**
  * 创建二维MAP
  *
  * @return
  */
 public static Map<String, Map<String, String>> createMap() {
  Map<String, Map<String, String>> map2 = Collections
    .synchronizedMap(new HashMap<String, Map<String, String>>());
  Map<String, String> map1 = Collections
    .synchronizedMap(new HashMap<String, String>());
  Map<String, String> map3 = Collections
    .synchronizedMap(new HashMap<String, String>());
  map1.put("abin", "varyall");
  map1.put("abing", "boy");
  map1.put("peng", "boy");
  map1.put("pengzi", "man");
  map2.put("user", map1);

  map3.put("chinese", "beijing");
  map3.put("china", "shanghai");
  map2.put("contury", map3);

  return map2;
 }
 /**
  * 解析二维MAP
  * @param map
  * @return
  */
 
 public static String getMap(Map<String, Map<String, String>> map) {
  for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) {
   Map.Entry entry=(Map.Entry)iterator.next();
   //先遍历一维map
   System.out.println("one map name="+entry.getKey());
   System.out.println("one map name="+entry.getValue());
   Map<String, String> map1=(Map<String, String>)entry.getValue();
   if(entry.getValue() instanceof Map){
    for(Iterator it=map1.entrySet().iterator();it.hasNext();){
     Map.Entry entry2=(Map.Entry)it.next();
     //再遍历二维map
     System.out.println("two map name="+entry2.getKey());
     System.out.println("two map name="+entry2.getValue());
    }
   }
  }

  return null;
 }
 public static void main(String[] args) {
  Map<String, Map<String, String>> map=createMap();
  getMap(map);
  
 }
}

posted @ 2012-08-18 15:51 abin 阅读(4180) | 评论 (1)编辑 收藏

Spring+Quartz的集群配置

 

http://blog.sina.com.cn/s/blog_4b0210750100z6jb.html#SinaEditor_Temp_FontName
posted @ 2012-08-17 18:01 abin 阅读(483) | 评论 (0)编辑 收藏

官网:http://quartz-scheduler.org/

学习文档:http://quartz-scheduler.org/documentation/quartz-2.1.x/tutorials/

例子:http://quartz-scheduler.org/documentation/quartz-2.1.x/examples/ 

spring集成官网:http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/scheduling.html#scheduling-quartz



http://blog.csdn.net/lan861698789/article/details/7620104
posted @ 2012-08-17 11:14 abin 阅读(1283) | 评论 (0)编辑 收藏

     摘要: HttpsURLConnection 扩展 HttpURLConnection,支持各种特定于 https 功能。此类使用 HostnameVerifier 和 SSLSocketFactory。为这两个类都定义了默认实现。但是,可以根据每个类(静态的)或每个实例来替换该实现。所有新 HttpsURLConnection 实例在创建时将被分配“默认的”静态值,通过在连接前调...  阅读全文
posted @ 2012-08-16 09:48 abin 阅读(6366) | 评论 (0)编辑 收藏

package org.lee.abin.dom4j;


import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

public class Dom4jCreate {
 public static String CreateXml(){
  Document document=DocumentHelper.createDocument();
  document.setXMLEncoding("UTF-8");
  Element rootElement=document.addElement("abin").addAttribute("version", "1.01");
  Element first=rootElement.addElement("header").addAttribute("type", "input");
  Element second=first.addElement("one").addText("中国");
  
  return document.asXML();
 }
 public static void main(String[] args) {
  Dom4jCreate dom4jC=new Dom4jCreate();
  String result=dom4jC.CreateXml();
  System.out.println("result="+result);
 }

}

posted @ 2012-08-16 01:02 abin 阅读(682) | 评论 (1)编辑 收藏

Java HTTPS Client FAQ: Can you share some source code for a Java HTTPS client application?

Sure, here's the source code for an example Java HTTPS client program I just used to download the contents of an HTTPS (SSL) URL. I actually found some of this in a newsgroup a while ago, but I can't find the source today to give them credit, so my apologies for that.

I just used this program to troubleshoot a problem with Java and HTTPS URLs, including all that nice Java SSL keystore and cacerts stuff you may run into when working with Java, HTTPS/SSL, and hitting a URL.

This Java program should work if you are hitting an HTTPS URL that has a valid SSL certificate from someone like Verisign or Thawte, but will not work with other SSL certificates unless you go down the Java keystore road.

Example Java HTTPS client program

Here's the source code for my simple Java HTTPS client program:




package foo;

import java.net.URL;
import java.io.*;
import javax.net.ssl.HttpsURLConnection;

public class JavaHttpsExample
{
  public static void main(String[] args)
  throws Exception
  {
    String httpsURL = "https://your.https.url.here/";
    URL myurl = new URL(httpsURL);
    HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
    InputStream ins = con.getInputStream();
    InputStreamReader isr = new InputStreamReader(ins);
    BufferedReader in = new BufferedReader(isr);

    String inputLine;

    while ((inputLine = in.readLine()) != null)
    {
      System.out.println(inputLine);
    }

    in.close();
  }
}






Just change the URL shown there to the HTTPS URL you want to access, and hopefully everything will work well for you. (If not, there's always that Comment section down below, lol.)




http://www.devdaily.com/blog/post/java/simple-https-example
posted @ 2012-08-16 00:41 abin 阅读(753) | 评论 (0)编辑 收藏

仅列出标题
共50页: First 上一页 32 33 34 35 36 37 38 39 40 下一页 Last