如何将soap webservices公开为REST API

时间:2017-03-03 18:33:14

标签: java web-services rest soap

我编写了以下用于制作soap webservice调用的代码。如何将其公开为REST api?以下代码进行soap调用,并将用户名和密码作为标题发送。输出将来自一个名为SR_spcWeb_spcServiceStub的Web服务。提前致谢

      SR_spcWeb_spcService srv;
    try {
        srv = new UNINServiceRequestWSLocator().getSR_spcWeb_spcService(new java.net.URL("http://crmuat.un.org//eai_enu/start.swe?SWEExtSource=WebService&SWEExtCmd=Execute&WSSOAP=1"));
        ((SR_spcWeb_spcServiceStub)srv).setUsername("username");
           ((SR_spcWeb_spcServiceStub)srv).setPassword("password");
           ((SR_spcWeb_spcServiceStub)srv).setHeader("http://siebel.com/webservices", "UsernameToken","username");
           ((SR_spcWeb_spcServiceStub)srv).setHeader("http://siebel.com/webservices", "PasswordText","password");
           ((SR_spcWeb_spcServiceStub)srv).setHeader("http://siebel.com/webservices", "SessionType","Stateless");



           String timeStamp = new SimpleDateFormat("MM/dd/yyyy").format(Calendar.getInstance().getTime());
           String fullName = firstName+" "+lastName;
           System.out.println(timeStamp);

           if (filename == null)
            {   
               uploadFileName = "";
               extension = "";
               encodedString   = "";

            }

            FileAttachment[] fileattachments =   { new  FileAttachment( uploadFileName, extension, encodedString ) } ;

           CreateSR_Input sr=new CreateSR_Input("3-Medium", "",emailAddr,"","Reported By","","","",fullName,"",indexNum, indexNum, 
                   "CRM Tier 3 Support","Incident",emailAddr,"","","Medium","",help_area, timeStamp,"","","","Low", indexNum,
                   subarea, area,emailAddr,"","", fileattachments,indexNum,requesteditem, "","",  "Web",subarea1,
                   emailAddr, justification,"", "", "3-Medium", location_name, "");



           System.out.println("srgroupe + "+ srgroup);
           System.out.println("subarea + "+ subarea);
           System.out.println("area + "+ area);
           System.out.println("requesteditem + "+ requesteditem);
           System.out.println("subarea1 + "+ subarea1);



           CreateSR_Output srvo;
        try {
            srvo = srv.createSR(sr);
             System.out.println("Got from webservice + "+ srvo.getSRNum());
               System.out.println("Got from webservice + "+ srvo.getStatusMsg());
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }



    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ServiceException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

0 个答案:

没有答案