powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / как прикрутить XmlRpcServer (3) к сервлету ?
5 сообщений из 5, страница 1 из 1
как прикрутить XmlRpcServer (3) к сервлету ?
    #34772767
ИгорьМ
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
в версии 2 всё было достаточно просто :
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
 package  com.bcc.game.reversi;

 import  org.apache.log4j.Logger;
 import  org.apache.xmlrpc.XmlRpcServer;

 import  javax.servlet.http.HttpServletRequest;
 import  javax.servlet.http.HttpServletResponse;
 import  javax.servlet.http.HttpServlet;
 import  javax.servlet.ServletConfig;
 import  javax.servlet.ServletException;
 import  java.io.UnsupportedEncodingException;
 import  java.io.IOException;
 import  java.io.OutputStream;
 import  java.util.Vector;
 import  java.util.List;
 import  java.net.UnknownHostException;
 import  java.net.BindException;

 import  com.bcc.game.reversi.ServiceReversiInstance;


 public   class  ServiceReverceController  extends  HttpServlet  {

    
     private   static   final  Logger LOG = Logger.getLogger("ServiceReverceController");
    
     private  XmlRpcServer server =  new  XmlRpcServer();

    
     private   static   final  String SERVICE_URL ="192.168.55.33";
     private   static   final   int  PORT =  11110 ;


    public   void  init()  throws  ServletException {
       LOG.info("init start");
        
       server.addHandler("ServiceController",  new  SendHandler());
        LOG.info("init fin");

    }

     public   class  SendHandler {
         public  String A(){
             return  A;
        }
    }


     protected   void  doGet(HttpServletRequest req, HttpServletResponse resp){
        doPost(req, resp);
    }

     protected   void  doPost(HttpServletRequest req, HttpServletResponse resp){
       
        resp.setCharacterEncoding("UTF-8");
         try  {
            req.setCharacterEncoding("UTF-8");
        }  catch  (UnsupportedEncodingException e) {
            LOG.error("setCharacterEncoding in doPost");
        }
        resp.setHeader("Cache-Control", "no-cache");
         byte [] result =  new   byte [ 0 ];
         try  {
            result = server.execute(req.getInputStream());
        }  catch  (IOException e) {
             LOG.error("server.execute in doPost");
        }
        resp.setContentType("text/xml");
        resp.setContentLength(result.length);
        OutputStream output =  null ;
         try  {
            output = resp.getOutputStream();
        }  catch  (IOException e) {
            LOG.error("resp.getOutputStream in doPost");
        }
         try  {
            output.write(result);
        }  catch  (IOException e) {
            LOG.error("output.write in doPost");
        }
         try  {
            output.close();
        }  catch  (IOException e) {
            LOG.error(" output.close in doPost");
        }

    }


}

в версии 3 ( библиотеки от Apache) столкнулся с такой проблемой :

метод execute(XmlRpcRequest xrr) имеет параметр XmlRpcRequest, а не InputStream
бъюсь с ним уже час, как сформировать объект из того что пришло запросом в
HttpServletRequest lkz вызоа метода execute ?
...
Рейтинг: 0 / 0
как прикрутить XmlRpcServer (3) к сервлету ?
    #34773360
no13
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Есть XmlRpcServlet, наследуйтесь от него.
...
Рейтинг: 0 / 0
как прикрутить XmlRpcServer (3) к сервлету ?
    #34773449
ИгорьМ
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
no13Есть XmlRpcServlet, наследуйтесь от него.
спасибо большое! попробую
...
Рейтинг: 0 / 0
как прикрутить XmlRpcServer (3) к сервлету ?
    #34774133
ИгорьМ
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
чего -то видимо я не догоняю, не вызывается startService , да и как потом ответ вытащить ??

ещё вопрос появился:
почему в методе init(ServletConfig config) нельзя в контекст сервлета атрибуты засунуть??
this.getServletContext().setAttribute("test",test); - делаю и ошибка:

Server returned HTTP response code: 500 for URL: http://192.168.55.33:9090/....


Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
 package  com.bcc.game.reversi;

 import  org.apache.log4j.Logger;
 import  org.apache.xmlrpc.server.XmlRpcServer;
 import  org.apache.xmlrpc.server.PropertyHandlerMapping;
 import  org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
 import  org.apache.xmlrpc.server.XmlRpcHandlerMapping;
 import  org.apache.xmlrpc.webserver.ServletWebServer;
 import  org.apache.xmlrpc.webserver.XmlRpcServlet;
 import  org.apache.xmlrpc.webserver.XmlRpcServletServer;
 import  org.apache.xmlrpc.XmlRpcRequest;
 import  org.apache.xmlrpc.XmlRpcException;

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

 import  javax.servlet.ServletException;
 import  javax.servlet.ServletConfig;
 import  java.io.UnsupportedEncodingException;
 import  java.io.IOException;
 import  java.io.OutputStream;
 import  java.io.InputStream;
 import  java.util.Vector;
 import  java.util.List;
 import  java.net.UnknownHostException;

 import  com.bcc.game.reversi.ServiceReversiInstance;


 public   class  ServiceReverceController  extends  XmlRpcServlet  {

    
     private   static   final  Logger LOG = Logger.getLogger("ServiceReverceController");
    
     private   static   final  String SERVICE_URL ="192.168.55.33";
     private   static   final   int  PORT =  11110 ;
     private  XmlRpcServletServer xrss =  null ;

   /**
     * Creates and returns the handler mapping.
     *
     * @return mapping table.
     *
     * @throws XmlRpcException in case of any mapping exception.
     */
     protected  XmlRpcHandlerMapping newXmlRpcHandlerMapping()  throws  XmlRpcException
    {
        PropertyHandlerMapping mapping =  new  PropertyHandlerMapping();

        mapping.addHandler("ServiceControlle", SendHandler. class );


         return  mapping;
    }
     public  XmlRpcServletServer getXmlRpcServletServer()
    {
         XmlRpcServletServer xrps =  new   XmlRpcServletServer();
          return  xrps;
    }


    public   void  init(ServletConfig config)  throws  ServletException {
       LOG.info("init start");


       
       XmlRpcHandlerMapping phm =  null ;
        try  {
           phm =  this .newXmlRpcHandlerMapping();
       }  catch  (XmlRpcException e) {
           e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
       }
       //LOG.debug("new PropertyHandlerMapping()");

        LOG.debug("getXmlRpcServletServer(): "+getXmlRpcServletServer());
        xrss =  this .getXmlRpcServletServer();
        xrss.setHandlerMapping(phm);
        LOG.debug("setHandlerMapping(phm);");

       LOG.info("init fin");

    }

     public   class  SendHandler {

        
        public  String startService(String clientId) {
            LOG.info("startService start 1");
            
            LOG.info("startService fin 1");
             return   new  String("Start");
         }

       }


     public    void  doGet(HttpServletRequest req, HttpServletResponse resp){
         LOG.info("doGet");
        resp.setCharacterEncoding("UTF-8");
         try  {
            req.setCharacterEncoding("UTF-8");
        }  catch  (UnsupportedEncodingException e) {
            LOG.error("setCharacterEncoding in doGet");
        }
        // Отключение кеша
        resp.setHeader("Cache-Control", "no-cache");
        doPost(req, resp);
    }

     public   void  doPost(HttpServletRequest req, HttpServletResponse resp){
       LOG.info("doPost");
        try  {
            resp.setCharacterEncoding("UTF-8");
            req.setCharacterEncoding("UTF-8");
            resp.setHeader("Cache-Control", "no-cache");
        }  catch  (UnsupportedEncodingException e) {
            LOG.error("setCharacterEncoding in doPost");
        }
        
        // Массив для ответа
         byte [] result =  new   byte [ 0 ];
         try  {
            LOG.debug("execute1");
            xrss.execute(req, resp);
            
            LOG.debug("execute2");
        }  catch  (ServletException e) {
            e.printStackTrace();  
        }  catch  (IOException e) {
            e.printStackTrace();  
        }

        
        resp.setContentType("text/xml");
        resp.setContentLength(result.length);
        OutputStream output =  null ;
         try  {
            output = resp.getOutputStream();
            output.write(result);
            output.close();
        }  catch  (IOException e) {
            LOG.error("output.write in doPost");
        }
        

    }


}

...
Рейтинг: 0 / 0
как прикрутить XmlRpcServer (3) к сервлету ?
    #34774140
ИгорьМ
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
может кто пример подкинет или ссылку толковую даст я на apche.org всё излазел уже
...
Рейтинг: 0 / 0
5 сообщений из 5, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / как прикрутить XmlRpcServer (3) к сервлету ?
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]