0 Replies Latest reply on Sep 10, 2008 5:23 AM by xiaofeng wang

    hlep me: Authorization EJB3 webservice client

    xiaofeng wang Newbie

      How to join the authorized client information

      @Stateless
      @WebService
      @RolesAllowed({"AdminUser"})
      public class SupportInterfaceBean implements SupportInterfaceBeanRemote {
      
       @EJB(beanName = "ChatContentFacade") ChatContentFacadeLocal chatContentFacadeLocal;//必需为Bean的本地接�,�能是远程接�
       @EJB(beanName = "ChatFacade") ChatFacadeLocal chatFacadeLocal;
      
       @WebMethod(operationName="sendMessage")
       public Boolean sendMessage(@WebParam(name="chatId") Integer chatId,@WebParam(name="content") String content,@WebParam(name="sndObject") String sndObject) {
       LogUtil.log("���天内容消�", Level.INFO, null);
       ChatContent chatContent = new ChatContent();
       chatContent.setChat(chatFacadeLocal.findById(chatId));
       chatContent.setContent(content);
       chatContent.setIsRead(false);
       chatContent.setSndObject(Short.parseShort(sndObject));
       return chatContentFacadeLocal.save(chatContent);
       }
      
       @WebMethod(operationName="accessMessage")
       public List<WsChatContent> accessMessage(@WebParam(name="chatId") Integer chatId,@WebParam(name="sndObject") String sndObject) {
       LogUtil.log("获�指定�件的�天内容", Level.INFO, null);
       String sqlString = "select * from ChatContent model where model.isRead=0 and model.ChatID=" + chatId + " and model.sndObject='" + sndObject + "'";
       List<ChatContent> list = chatContentFacadeLocal.query(sqlString, null, null);
       List<WsChatContent> results = new ArrayList<WsChatContent>();
       for(ChatContent chatContent : list){
       WsChatContent wsObj = new WsChatContent();
       wsObj.setChatContentId(chatContent.getChatContentId());
       wsObj.setContent(chatContent.getContent());
       wsObj.setIsRead(chatContent.getIsRead());
       wsObj.setSndObject(chatContent.getSndObject().toString());
       results.add(wsObj);
       chatContent.setIsRead(true);
       chatContentFacadeLocal.update(chatContent);
       }
       return results;
       }
      
      }
      


      // TODO Auto-generated method stub
       SupportInterfaceBean proxy = new SupportInterfaceBeanService().getSupportInterfaceBeanPort();
       BindingProvider bindProvider = (BindingProvider) proxy;
       Map<String, Object> reqCtx = bindProvider.getRequestContext();
      
       //reqCtx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "/SupportInterfaceBeanService/SupportInterfaceBean");
       reqCtx.put(BindingProvider.USERNAME_PROPERTY, "lihuoming");
       reqCtx.put(BindingProvider.PASSWORD_PROPERTY, "123456");
       reqCtx.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
       System.out.println(proxy.accessMessage(1, "1"));
      


      xception in thread "main" javax.xml.ws.soap.SOAPFaultException: Authorization failure
       at com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:188)
       at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:108)
       at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:119)
       at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:89)
       at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:118)
       at $Proxy34.accessMessage(Unknown Source)
       at com.ewke.ejb.ws.Test.main(Test.java:25)