2015-07-22 45 views
0

我写了一个简单的SOAP端点基本上按照这里找到春天教程:https://spring.io/guides/gs/producing-web-service/春天SOAP端点 - 缓存的JAXBContext

下面是用于拦截请求类(假设库对象注入):

@Endpoint 
public class SampleEndpoint { 

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "SampleRequest") 
    public 
    @ResponsePayload 
    JAXBElement<SampleResponseType> sampleQuery(
     @RequestPayload JAXBElement<SampleRequestType> request) { 

    ObjectFactory factory = new ObjectFactory(); 
    SampleResponseType response = repository.query(request.getValue()); 
    JAXBElement<SampleResponseType> jaxbResponse = factory.createSampleResponse(response); 
    return jaxbResponse; 

    } 

} 

服务正常运行。我遇到的一个问题是性能问题,特别是在反编组时。平均来说,将对象解组为XML响应需要花费几秒钟。有没有一种方法来缓存/注入JaxbContext Spring在这个过程中用来改善这个时间?

下面是我用于此端点的Web服务配置文件。我试过交替SAAJ和公理的消息工厂之间却没有看到太大的业绩变化:

@EnableWs 
@Configuration 
public class WebServiceConfig extends WsConfigurerAdapter { 

@Bean 
public SaajSoapMessageFactory soap12MessageFactory() { 
    SaajSoapMessageFactory factory = new SaajSoapMessageFactory(); 
    factory.setSoapVersion(SoapVersion.SOAP_12); 
    return factory; 
} 

@Bean 
public AxiomSoapMessageFactory axiomSoapMessageFactory() { 
    AxiomSoapMessageFactory factory = new AxiomSoapMessageFactory(); 
    factory.setSoapVersion(SoapVersion.SOAP_12); 
    factory.setPayloadCaching(false); 
    return factory; 
} 

@Bean 
public ServletRegistrationBean dispatcherServlet(
     ApplicationContext applicationContext) { 
    MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 
    servlet.setApplicationContext(applicationContext); 
    servlet.setTransformWsdlLocations(true); 
    servlet.setMessageFactoryBeanName("soap12MessageFactory"); 
    return new ServletRegistrationBean(servlet, "/ws/*"); 
} 

@Bean(name = "wsdlname") 
public DefaultWsdl11Definition xcpdDefaultXcpdWsdl11Definition(XsdSchema 
    schema) { 
    DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition(); 
    wsdl11Definition.setCreateSoap11Binding(false); 
    wsdl11Definition.setCreateSoap12Binding(true); 
    wsdl11Definition.setPortTypeName("xcpdPort"); 
    wsdl11Definition.setLocationUri("/ws"); 
    wsdl11Definition 
      .setTargetNamespace("http://somenamespace.org/"); 
    wsdl11Definition.setSchema(schema); 
    return wsdl11Definition; 
} 

@Bean 
public XsdSchema schema() { 
    return new SimpleXsdSchema(
      new ClassPathResource(
        "schema.xsd")); 
} 
} 
+0

的'JAXBContext's是每种类型已经缓存,因此试图增加额外的缓存添加任何内容。 –

+0

迈克,你能否用你有证据表明性能问题与JAXBContext相关的证据更新你的问题? –

+0

其实前两天我们解决了这个问题。我现在正在发布解决方案。尽管现在服务的性能有了很大提高,但每个请求基本上都在一秒之内。 –

回答

0

我们前两天得到解决的问题。我们看到的第一个问题是客户端版本的JVM安装在服务器上。我安装了JVM的服务器版本,并更改​​了Tomcat以使用该实例。一些Web服务的性能显着提高。以前简单的请求需要三秒钟,现在他们需要250毫秒。然而,在测试我写的Spring服务时,我没有看到太多的改进。

要解决这最后一个问题,我增加了以下内容为Tomcat Java选项:

-Dcom.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.fastBoot=true 

重新启动Tomcat实例后,服务的响应时间,目前正在每一秒。以前的请求最多需要30秒才能完成。我们所使用的服务器JRE如下:

http://www.oracle.com/technetwork/java/javase/downloads/server-jre8-downloads-2133154.html