Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » WebService/XML/JSON/SOAP/SOA » Web Services  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 AXIS中关于SESSION的问题
phoenixfmc





发贴: 2
积分: 0
于 2006-05-19 14:33 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我是一个AXIS的初学者。现在有一个问题想请教大家:在服务器端如何维护一个SESSION。我看到有的资料里说用HANDLER,我也试了,现在SOAP消息中也能自动加入上次会话的ID,可是还是得不到上次SESSION中的存的值。现在真的没有办法了。能找的资料都找了,谁能不能帮我看一下啊?package fmc;

import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.http.HttpSession;
import javax.xml.soap.SOAPException;
import org.apache.axis.session.Session;
import org.apache.axis.MessageContext;

public class ServiceTest {
  MessageContext mc = MessageContext.getCurrentContext();
  final Session conSession = mc.getSession();
  public boolean login(String username, String password) throws Exception {
    mc.setMaintainSession(true);
    System.out.println("Deng lu ID and Ps :" + username + " " + password);
    String sql = "select * from aa022 where aav001='" + username
        + "' and aaw001='" + password + "'";
    ResultSet result = OraJDBCTest.executeQuery(sql);
    if (result.next()) {
      conSession.set("username", username);
      conSession.set("password", password);
      conSession.touch();
      OraJDBCTest.close();
      return true;
    } else {
      return false;
    }
  }

  public boolean changeadminpwd(String oldpwd, String newpwd)
      throws SQLException, ClassNotFoundException, SOAPException {
    mc.setMaintainSession(true);
    System.out.println("olspwd :" + oldpwd + " " + "newpwd :" + newpwd);
    String password = (String) conSession.get("password");
    System.out.println("Two word :" + "oldpwd :" + oldpwd + " and "
        + "password :" + password);
    String name = (String) conSession.get("username");
    System.out.println("Session get username :" + name);
    String sql = "select * from aa022 where aaw001='" + oldpwd
        + "' and aab002='" + name + "'";
    ResultSet rs = OraJDBCTest.getRs(sql);
    if (rs.next()) {
      String sqlupdate = "update aa022 set aaw001='" + newpwd
          + "' where aab002='" + name + "' and aaw001='" + oldpwd
          + "'";
      OraJDBCTest.executeUpdate(sqlupdate);
      OraJDBCTest.close();
      return true;
    } else {
      return false;
    }
  }
}

import java.net.MalformedURLException;
import java.rmi.RemoteException;
//import org.apache.axis.handlers.SimpleSessionHandler;
import org.apache.axis.client.Service;
import org.apache.axis.client.Call;

import client.ServiceTestServiceLocator;
import client.ServiceTest_PortType;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;

public class TestClient {
  Service service = new Service();
  ServiceTestServiceLocator locator = new ServiceTestServiceLocator();
  public void loginTest(String username,String password) {
    try {
      locator.setMaintainSession(true);
      ServiceTest_PortType st = locator.getServiceTest();
      if(st.login(username, password)){
        System.out.println("Ke Yi Deng Lu ! ");
      }
      else{
        System.out.println("CUO WU ! QING CHONG SHI !");
      }
      /*Call call = (Call) service.createCall();
      // call.setProperty(Call.SESSION_MAINTAIN_PROPERTY,Boolean.TRUE);
      //call.setProperty(Call.USERNAME_PROPERTY,username);
     //call.setProperty(Call.PASSWORD_PROPERTY,password);
      // call.setMaintainSession(true);
      //call.setUsername(username);
      //call.setPassword(password);
      String endpoint = "http://192.168.0.22:8899/MyService/services/Sessions?wsdl";
      call.setOperationName(new QName(endpoint, "login"));
      call.setTargetEndpointAddress(new java.net.URL(endpoint));
      //call.addParameter("fmc",org.apache.axis.Constants.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
      //call.setReturnType(org.apache.axis.Constants.XSD_STRING);
      Object[] params = { username, password };
      String obj = (String)call.invoke(params);
      System.out.println(obj);
      if (obj.equals("true")) {
        System.out.println("Ke Yi Deng Lu ! " + obj + " !");
      }
      else if(obj.equals("false")){
        System.out.println("CUO WU ! QING CHONG SHI !");
      }*/
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public void changeTest(String oldpwd, String newpwd)
      throws ServiceException, MalformedURLException, RemoteException {
    locator.setMaintainSession(true);
    ServiceTest_PortType st = locator.getServiceTest();
    if(st.changeadminpwd(oldpwd, newpwd)){
      System.out.println("Xiu Gai Cheng Gong ! ");
    }
    else{
      System.out.println("CUO WU ! CHONG SHI !");
    }
    /*Call call = (Call) service.createCall();
    //call.setMaintainSession(true);
    String endpoint = "http://192.168.0.22:8899/MyService/services/Sessions?wsdl";
    call.setOperationName(new QName(endpoint, "changeadminpwd"));
    call.setTargetEndpointAddress(new java.net.URL(endpoint));
    // call.addParameter("fmc",org.apache.axis.Constants.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
    // call.setReturnType(org.apache.axis.Constants.XSD_STRING);
    Object[] params = { oldpwd, newpwd };
    String obj = (String) call.invoke(params);
    // System.setProperty("org.xml.sax.driver",
    // "org.apache.xerces.parsers.SAXParser");
    System.out.println(obj);
    if (obj.equals("true")) {
      System.out.println("XIU GAI CHENG GONG ! " + obj + " !");
    }
    if (obj.equals("false")) {
      System.out.println("CUO WU ! QING CHONG SHI !");
    }*/
  }

  public static void main(String[] args) throws MalformedURLException,
      RemoteException, ServiceException {
    TestClient tc = new TestClient();
    //tc.loginTest("admin", "admin");
    tc.changeTest("admin", "phoenix");
  }
}



作者 Re:AXIS中关于SESSION的问题 [Re:phoenixfmc]
phoenixfmc





发贴: 2
积分: 0
于 2006-06-02 11:18 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
怎么这么久了还是没有人回答啊??这个问题有那么难吗???能不能有谁给个说法啊????也太没有效率啦!!!!!


作者 Re:AXIS中关于SESSION的问题 [Re:phoenixfmc]
aweisw





发贴: 8
积分: 0
于 2006-07-14 09:54 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我没有用过AXIS 不过有个方法你可以试试

import javax.xml.ws.WebServiceContext;
public class ServiceTest
{
@Resource
private WebServiceContext wsContext;
MessageContext mc = wsContext.getMessageContext();
HttpSession session = ((javax.servlet.http.HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST)).getSession();
}
以上是服务端的...在客户端还是需要设置,不然每次都是新的session...怎么设置我现在也没弄起.




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2020 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号
客服电话 0592-8750026    客服信箱 714923@qq.com    客服QQ 714923