2011-01-22 1 views
1

내가 하나의 Java/Salesforce tutorial에 있었지만 SoapBindingStub가 가치가 떨어지는 라이브러리를 기반으로하는 쓸모없는 코드 인 것처럼 보이기 때문에 그 코드를 작동시키지 못했습니다. 그래서 나는 코드를 JAX-WS Quick Start에서 코드로 메쉬하려고했지만, 이것도 제대로 작동하지 않았습니다. 결과적으로 샘플 콘솔 애플리케이션은 예외적으로 "웹 서비스 예외 생성 Salesface 포트 : 클래스 javax.xml.ws.WebServiceException의 보안 제한으로 인해 JAXBContext를 만들 수 없습니다.".Java/SalesForce 앱이 보안 제한으로 인해 JAXBContext를 만들 수없는 이유는 무엇입니까?

저는 두 코드를 매시하려고했지만 JAX-WS Quickstart.java를 추상화하는 작업을 진행했습니다. 이제는 와우가 작동하고 다른 응용 프로그램에서 해당 메서드를 다시 사용할 수 있다는 것을 이해할 수 있습니다.

코드를 어떻게 슬라이스하고 다룰지라도 코드는 항상 동일한 오류가있는 동일한 위치에서 멈추게됩니다. (시간적으로)

Running main loop 



FOUND enterprise.wsdl!!! 



sforceService INITIALIZED. About to get Soap. 




Web Service Exception creating salesface port: Unable to create JAXBContext due to the security restriction 
on class javax.xml.ws.WebServiceException 
javax.xml.ws.WebServiceException: Unable to create JAXBContext due to the security restriction 
    at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:131) 
    at com.sun.xml.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:63) 
    at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:224) 
    at com.sun.xml.ws.client.WSServiceDelegate.addSEI(WSServiceDelegate.java:588) 
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:291) 
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:274) 
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:267) 
    at javax.xml.ws.Service.getPort(Unknown Source) 
    at com.sforce.soap.enterprise.SforceService.getSoap(SforceService.java:53) 
    at hu.flux.salesforce.LoginToolkit.initPort(LoginToolkit.java:78) 
    at hu.flux.salesforce.LoginToolkit.doLogin(LoginToolkit.java:122) 
    at hu.flux.salesforce.LoginToolkit.<init>(LoginToolkit.java:49) 
    at hu.flux.salesforce.samples.Quickstart.mainLoop(Quickstart.java:55) 
    at hu.flux.salesforce.samples.Quickstart.<init>(Quickstart.java:28) 
    at hu.flux.salesforce.samples.Quickstart.main(Quickstart.java:21) 
Caused by: java.security.PrivilegedActionException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions 
java.lang.StackTraceElement does not have a no-arg default constructor. 
    this problem is related to the following location: 
     at java.lang.StackTraceElement 
     at public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace() 
     at java.lang.Throwable 
     at java.lang.Exception 
     at com.sforce.ws.ConnectionException 
     at com.sforce.ws.SoapFaultException 
     at com.sforce.soap.enterprise.fault.ApiFault 
     at public javax.xml.bind.JAXBElement com.sforce.soap.enterprise.fault.ObjectFactory.createFault(com.sforce.soap.enterprise.fault.ApiFault) 
     at com.sforce.soap.enterprise.fault.ObjectFactory 
com.sforce.ws.types.Time does not have a no-arg default constructor. 
    this problem is related to the following location: 
     at com.sforce.ws.types.Time 
     at public com.sforce.ws.types.Time com.sforce.soap.enterprise.sobject.BusinessHours.getFridayEndTime() 
     at com.sforce.soap.enterprise.sobject.BusinessHours 
     at public com.sforce.soap.enterprise.sobject.BusinessHours com.sforce.soap.enterprise.sobject.ObjectFactory.createBusinessHours() 
     at com.sforce.soap.enterprise.sobject.ObjectFactory 

    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:124) 
    ... 14 more 
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions 
java.lang.StackTraceElement does not have a no-arg default constructor. 
    this problem is related to the following location: 
     at java.lang.StackTraceElement 
     at public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace() 
     at java.lang.Throwable 
     at java.lang.Exception 
     at com.sforce.ws.ConnectionException 
     at com.sforce.ws.SoapFaultException 
     at com.sforce.soap.enterprise.fault.ApiFault 
     at public javax.xml.bind.JAXBElement com.sforce.soap.enterprise.fault.ObjectFactory.createFault(com.sforce.soap.enterprise.fault.ApiFault) 
     at com.sforce.soap.enterprise.fault.ObjectFactory 
com.sforce.ws.types.Time does not have a no-arg default constructor. 
    this problem is related to the following location: 
     at com.sforce.ws.types.Time 
     at public com.sforce.ws.types.Time com.sforce.soap.enterprise.sobject.BusinessHours.getFridayEndTime() 
     at com.sforce.soap.enterprise.sobject.BusinessHours 
     at public com.sforce.soap.enterprise.sobject.BusinessHours com.sforce.soap.enterprise.sobject.ObjectFactory.createBusinessHours() 
     at com.sforce.soap.enterprise.sobject.ObjectFactory 

    at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:66) 
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:422) 
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:270) 
    at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:103) 
    at com.sun.xml.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:89) 
    at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:126) 
    at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:125) 
    ... 16 more 



1. Login 
2. Get Accounts 
3. Update Accounts 
4. Get Server Timestamp 
5. Exit 
Enter a menu option: 

마지막 라인에 즉시 전후의 출력을 포함하여, 여기

private void initPort() 
{ 
    try 
    { 
     URL wsdlLocation = this.getClass().getClassLoader().getResource("META-INF/enterprise.wsdl"); 
     if (wsdlLocation == null) 
     { 
      WebServiceException webServiceException = new WebServiceException("enterprise.wsdl not found!"); 
      ExceptionToolkit.display("Web Service Exception can't find enterprise.wsdl", webServiceException); 
      throw webServiceException; 
     } 
     else {System.out.println("\nFOUND enterprise.wsdl!!!\n\n");} 

     QName qName = new QName("urn:enterprise.soap.sforce.com", "SforceService"); 
     SforceService sforceService = new SforceService(wsdlLocation, qName); 
     System.out.println("\nsforceService INITIALIZED. About to get Soap.\n\n"); 
     Soap soap = (sforceService).getSoap(); 
     System.out.println("\nWe have soap.\n\n"); 
     setPort (soap); 
    } 
    catch (WebServiceException webServiceException) 
    { 
     ExceptionToolkit.display("Web Service Exception creating salesface port", webServiceException); 
     return; 
    } 
} 

오류이다 : 여기

는 persistantly 실패있어서 현재 코드 스택 내 자신의 코드를 말합니다 :

at hu.flux.salesforce.LoginToolkit.initPort(LoginToolkit.java:78) 

System.out.println stat 소스의 ements는 이것이 실행이 끝나는 것임을 확인합니다. 이 줄을 구체적 :이 궁극적으로 JAXBContext에를 만들 수 없습니다 자바를 떠나 보안 제한을 초월 할 수없는 이유

Soap soap = (sforceService).getSoap(); 

사람은 방법을 알고 나 있는가?

+0

정당한 문제를 downvoting ... 매우 도움이됩니다. : -/ –

답변

1

의 긴 목록이있다 작업 중 ... 첫 튜토리얼과 JAX WS 퀵 스타트에서 파생 된 코드로 작업을 시작했습니다. 도움이된다면, 여기 내 전체 LoginToolkit 클래스가 있습니다. (죄송합니다. 내 시간이나 출력에 대해 돈을받지 않을 때 논평하는 것에 대해 게으르다.)

/** 
* 
*/ 
package hu.flux.salesforce; 

import java.net.URL; 
import java.util.Collections; 
import java.util.HashMap; 
import java.util.List; 
import java.util.Map; 

import javax.xml.bind.JAXBContext; 
import javax.xml.bind.JAXBException; 
import javax.xml.namespace.QName; 
import javax.xml.ws.BindingProvider; 
import javax.xml.ws.WebServiceException; 
import javax.xml.ws.handler.MessageContext; 

import hu.flux.exceptions.ExceptionToolkit; 
import hu.flux.input.PromptUser; 

import com.sforce.soap.enterprise.InvalidIdFault; 
import com.sforce.soap.enterprise.LoginResult; 
import com.sforce.soap.enterprise.SessionHeader; 
import com.sforce.soap.enterprise.SforceService; 
import com.sforce.soap.enterprise.Soap; 
import com.sun.xml.bind.api.JAXBRIContext; 
import com.sun.xml.ws.api.message.Headers; 
import com.sun.xml.ws.developer.WSBindingProvider; 

/** 
* @author Brian Kessler 
* 
*/ 
public class LoginToolkit { 

    private Soap binding = null; 
    private LoginResult loginResult = null;; 

    public void setBinding(Soap binding) { this.binding = binding; } 
    public Soap getBinding() { return binding; } 

    public void setLoginResult(LoginResult loginResult) { this.loginResult = loginResult; } 
    public LoginResult getLoginResult() { return loginResult; } 

    /** 
    * 
    */ 
    public LoginToolkit() { doLogin(); } 

    private boolean doLogin() 
    { 
     //String userName = getUserInput("Enter user name: ").trim(); 
     //String password = getUserInput("Enter password: ").trim(); 
     String userName = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
     String password = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
     binding = bindEnterpriseWSDL(); 

     System.out.println("LOGGING IN NOW...."); 
     try { loginResult = binding.login (userName, password); } 
     catch (InvalidIdFault invalidIdFault) { return loginExceptionCaught("invalid id fault", invalidIdFault); } 
     catch (com.sforce.soap.enterprise.LoginFault loginFault) { return loginExceptionCaught("login fault", loginFault); } 
     catch (com.sforce.soap.enterprise.UnexpectedErrorFault unexpectedErrorFault) { return loginExceptionCaught("unexpected error fault", unexpectedErrorFault); } 

     // Check if the password has expired 
     return (loginResult.isPasswordExpired()) ? passwordExpired() : bindSession(); 
    } 

    private Soap bindEnterpriseWSDL() 
    { 
     try 
     { 
      URL wsdlLocation = this.getClass().getClassLoader().getResource("META-INF/enterprise.wsdl"); 
      if (wsdlLocation == null) 
      { 
       WebServiceException webServiceException = new WebServiceException("enterprise.wsdl not found!"); 
       ExceptionToolkit.display ("Web Service Exception could not find enterprise.wsdl.", webServiceException); 
       throw new WebServiceException(webServiceException); 
      } 
      else { System.out.println ("\n\n\nenterprise.wsdl WAS found!\n\n\n");} 

      QName qName = new QName("urn:enterprise.soap.sforce.com", "SforceService"); 
      SforceService sforceService = new SforceService(wsdlLocation, qName); 
      Soap soap = sforceService.getSoap(); 
      return soap; 
     } 
     catch (WebServiceException webServiceException) 
     { 
      ExceptionToolkit.display ("Web Service Exception creating salesface port.", webServiceException); 
      throw new WebServiceException(webServiceException); 
     } 
    } 


    private WSBindingProvider enableGzip(BindingProvider bindingProvider) 
    { 
     //Enable GZip compression 
     Map<String, List<String>> httpHeaders = new HashMap<String, List<String>>(); 
     httpHeaders.put("Content-Encoding", Collections.singletonList("gzip")); 
     httpHeaders.put("Accept-Encoding", Collections.singletonList("gzip")); 
     Map<String, Object> reqContext = bindingProvider.getRequestContext(); 
     reqContext.put(MessageContext.HTTP_REQUEST_HEADERS, httpHeaders); 
     return (WSBindingProvider) bindingProvider; 
    } 

    private boolean passwordExpired() 
    { 
     System.out.println("An error has occured. Your password has expired."); 
     return false; 
    } 

    private boolean bindSession() 
    { 
     //binding._setProperty(Soap BindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl()); 
     WSBindingProvider bindingProvider = ((WSBindingProvider) binding); 
     bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl()); 
     bindingProvider = enableGzip (bindingProvider); 

     // Create a new session header object and add the session id from the login return object 
     SessionHeader sessionHeader = new SessionHeader(); 
     sessionHeader.setSessionId(loginResult.getSessionId()); 
     bindingProvider = setJAXBContext (bindingProvider, sessionHeader); 


     reportLoginSuccess(); 

     return true; // return true to indicate that we are logged in, pointed at the right url and have our security token in place. 
    } 

    private WSBindingProvider setJAXBContext (WSBindingProvider bindingProvider, SessionHeader sessionHeader) 
    { 
     JAXBContext jc; 
     try { jc = JAXBContext.newInstance("com.sforce.soap.enterprise"); } 
     catch (JAXBException jaxbException) 
     { 
      ExceptionToolkit.display ("Error creating JAXBContext instance.", jaxbException); 
      throw new WebServiceException(jaxbException); 
     } 

     bindingProvider.setOutboundHeaders(Headers.create((JAXBRIContext) jc, sessionHeader)); 
     return bindingProvider; 
    } 

    private void reportLoginSuccess() 
    { 
     System.out.println("Login was successfull."); 
     System.out.print("The returned session id is: "); 
     System.out.println(getLoginResult().getSessionId()); 
     System.out.print("Your logged in user id is: "); 
     System.out.println(getLoginResult().getUserId() + " \n\n"); 
    } 

    private boolean loginExceptionCaught(String label, Exception exception) 
    { 
     ExceptionToolkit.display ("A " + label + " has occured.", exception); 
     return false; 
    } 

    public boolean checkLogin() 
    { 
     // check to see if we are already logged in 
     if (this.getLoginResult() == null) 
     { 
      System.out.println("Run the login sample before the others.\n"); 
      PromptUser.getUserInput("Hit enter to continue: "); 
      System.out.println("\n"); 
      return false; 
     } 
     return true; 
    } 

    /** 
    * @param args 
    */ 
    public static void main(String[] args) {} 

} 
0

계약서에 java.lang.Exception 또는 StackTraceElement 하위 클래스가있는 웹 서비스를 만드는 것처럼 보입니다. 너는 그렇게 할 수 없다. 예외를 처리하는 유일한 방법은 오류를 사용하는 것입니다.

이 모든 것을 Salesforce 외부에서 만들었습니까?

코드가 수동으로 JAXB 컨텍스트를 초기화하는 데 어려움을 겪고 있지만 JAXB 호출을 JAXB 호출로 전달하지 않으므로 스택이 새로운 JAXB 컨텍스트를 만들고 문제를 일으키게됩니다. 당신이 같이 바인딩 제공 업체에 전달할 기억나요 ... 당신이 JAX-WS를 사용하려면

try { 
     jc = JAXBContext.newInstance("com.salesforce.sei"); 
     bindingProvider.setOutboundHeaders(Headers.create((JAXBRIContext) jc, sh)); 
    } catch (JAXBException e) { 
     System.out.println("Error creating JAXBContext instance " + e.getMessage()); 
     return false; 
    } 
+0

이 코드에서 하위 클래스를 사용하지 않습니다. 내가하고있는 튜토리얼은 SalesForce로 자바를 사용하는 것에 관한 것이므로 Salesforce를 현명한 방법으로 사용할 수 있는지 잘 모르겠습니다. –

+0

나는 WSDL에 액세스하거나 SOAP 객체를 생성 할 때 어떤 종류의 제한이있는 것처럼 보이기 때문에 예외가 잘 처리된다고 생각한다. –

+0

JAX-B 및 StackTraceElement 용 google을 사용하면 내가 말하는 것을 볼 수 있습니다. 예 : http://forums.java.net/node/670152 – bmargulies

0

에서, Jax-WS/salesforce quickstart를 참조 드디어 로그인이 java samples for salesfoce on the wiki

+0

빠른 시작을 살펴 봤는데 ... 샘플 패키지 밖에서 코드를 적용하는 방법을 알아 내려고했지만 ... 분명히 뭔가 간과하거나 오해했습니다. –

+0

다음과 같은 별도의 빠른 시작이 있습니다. jax-ws, 나는 그것에 연결되어있다. – superfell

+0

바로이 코드가 작동하도록 참조로 사용하려고하는 빠른 시작 코드입니다. 그 존재를 지적 해 주셔서 고맙습니다. 그러나 제 문제는 더 구체적입니다. –