2016-09-06 8 views
0

各送信メッセージに対して、Salesforceは完全な自己完結型のWSDLを提供します。同じSpringサービスで複数のSFDC Outbound Message Receiverを実装する方法は?

1つ1つのSpringサービスを実装することは、クラスを生成するためにjaxws-maven-pluginを使用し、エンドポイントをバインドするために@Endpoint@PayloadRootなどを使用すると簡単です。

ただし、複数の発信メッセージは、異なる構造およびタイプ階層に対して同じQN(たとえば、http://soap.sforce.com/2005/09/outbound:notificationsまたはurn:sobject.enterprise.soap.sforce.com:sObject)を共有します。

私はhow to map the same XML names to different handlers based on URL pathを知っています。

私はバインディングファイルで生成されたクラスのために別のパッケージを使用する方法を知っている:生成されたコードからJaxb2Marshallerを初期化しようとしたときしかし、それはまだXMLの競合を処理することはできません

<?xml version="1.0" encoding="UTF-8"?> 
<jaxws:bindings 
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" 
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    wsdlLocation="../wsdl/SFDC_Contact_Outbound_Msg.wsdl" 
    version="2.0"> 

    <jaxb:bindings node="//xs:schema[@targetNamespace='http://soap.sforce.com/2005/09/outbound']"> 
    <jaxb:schemaBindings> 
     <jaxb:package name="com.sforce.soap.outbound.contact"/> 
    </jaxb:schemaBindings> 
    </jaxb:bindings> 

    <jaxb:bindings node="//xs:schema[@targetNamespace='urn:sobject.enterprise.soap.sforce.com']"> 
    <jaxb:schemaBindings> 
     <jaxb:package name="com.sforce.soap.enterprise.sobject.contact"/> 
    </jaxb:schemaBindings> 
    </jaxb:bindings> 

</jaxws:bindings> 

[WARN] [main] 09:40:45.687 AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: 
    Error creating bean with name 'marshaller' defined in class path resource [WebServiceConfig.class]: 
    Invocation of init method failed; nested exception is org.springframework.oxm.UncategorizedMappingException: 
    Unknown JAXB exception; nested exception is com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 6 counts of IllegalAnnotationExceptions 
    Two classes have the same XML type name "{urn:sobject.enterprise.soap.sforce.com}sObject". Use @XmlType.name and @XmlType.namespace to assign different names to them. 
    ... 

SDFCによって生成されたWSDLが変更されたときに、新しいファイルを削除する以外の手順を追加したくありません。

ソースWSDLを変更せずにpackage-info.javaの名前空間を変更する方法はありますか?

DefaultMethodEndpointAdapterにすべて追加できる個々のマーシャラーを簡単に作成できます(つまり、別々の@Beanメソッドはありません)。

これらの送信メッセージ受信者をすべて実装する別の方法はありますか?

答えて

0

名前空間を変更する方法はありますか?

もしあなたがそうしたのであれば、実際のメッセージの名前空間と一致しないので、アンマーシャルできません。

パッケージごとに別々のマーシャラーを簡単に作成する方法はありますか?

さて、ここではの方法です。

@PostConstruct 
public void marshallers() throws IOException { 
    List<String> types = Arrays.stream(applicationContext.getResources("classpath:com/sforce/soap/outbound/*")) 
     .map(Resource::getFilename) 
     .collect(Collectors.toList()); 

    for (String type : types) { 
    String beanName = "marshallingPayloadMethodProcessor_" + type; 
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); 
    marshaller.setPackagesToScan(
     "com.sforce.soap.outbound." + type, 
     "com.sforce.soap.enterprise.sobject." + type 
    ); 

    try { 
     marshaller.afterPropertiesSet(); 
    } catch (Exception ex) { 
     throw new BeanInitializationException("Could not initialize bean " + beanName, ex); 
    } 

    MarshallingPayloadMethodProcessor processor = new MarshallingPayloadMethodProcessor(marshaller); 
    beanFactory.registerSingleton(beanName, processor); 
    } 

この上の注意点のカップル:

  • jarファイルを経由して展開した場合、クラスパスのディレクトリが存在しないので、パッケージ名を取得する別の方法が必要になります。
  • registerSingletonは、いくつかのアプリケーションコンテキストを壊しているように見えます。無関係なBeanはもう見つからなくなります。なぜこのことが分かりませんか?
関連する問題