少年阿賓

          那些青春的歲月

            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=" xmlns:xsi=" xmlns:tx=" xmlns:jaxws=" xmlns:cxf=" xmlns:wsa=" 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
            <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);
           }
          }



               摘要: 1.實例化spring容器 和 從容器獲取Bean對象 實例化Spring容器常用的兩種方式: 方法一: 在類路徑下尋找配置文件來實例化容器 [推薦使用] ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"beans.xml"}); 方法二: 在文件系統路徑下尋找配置文件來實例化容器 [這...  閱讀全文
          posted @ 2012-08-20 12:34 abin 閱讀(24203) | 評論 (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=" xmlns:xsi=" 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
                    

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

          </beans>


          方法一:
          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 閱讀(2161) | 評論 (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 閱讀(4197) | 評論 (1)編輯 收藏

          Spring+Quartz的集群配置

           

          http://blog.sina.com.cn/s/blog_4b0210750100z6jb.html#SinaEditor_Temp_FontName
          posted @ 2012-08-17 18:01 abin 閱讀(492) | 評論 (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 閱讀(1301) | 評論 (0)編輯 收藏

               摘要: HttpsURLConnection 擴展 HttpURLConnection,支持各種特定于 https 功能。此類使用 HostnameVerifier 和 SSLSocketFactory。為這兩個類都定義了默認實現。但是,可以根據每個類(靜態的)或每個實例來替換該實現。所有新 HttpsURLConnection 實例在創建時將被分配“默認的”靜態值,通過在連接前調...  閱讀全文
          posted @ 2012-08-16 09:48 abin 閱讀(6379) | 評論 (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 閱讀(689) | 評論 (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 閱讀(762) | 評論 (0)編輯 收藏

          僅列出標題
          共50頁: First 上一頁 32 33 34 35 36 37 38 39 40 下一頁 Last 
          主站蜘蛛池模板: 闵行区| 收藏| 老河口市| 香港 | 嘉义县| 金门县| 澄江县| 东山县| 扶绥县| 太原市| 海伦市| 淅川县| 赤水市| 仁布县| 若羌县| 浑源县| 山阴县| 明光市| 木兰县| 新巴尔虎左旗| 黑河市| 岳普湖县| 鞍山市| 云龙县| 沂水县| 盐城市| 西丰县| 桃园市| 蒙阴县| 馆陶县| 上蔡县| 金坛市| 遂宁市| 吕梁市| 长阳| 凌海市| 湖北省| 全州县| 元氏县| 闻喜县| 安阳县|