2014-09-02 125 views
2

我已經生成使用JABX一個WSDL域類和實施了以下客戶:的Spring Web服務請求與空URI和無效的Marshaller

@Service 
public class AccountEndpoint extends WebServiceGatewaySupport { 

    private static final Logger logger = Logger.getLogger(String.valueOf(AccountEndpoint.class)); 

    public AccountEndpoint() { 
    } 

    public GetAccountResponse getAccount(long accountAgency, long accountNumber) { 
     GetAccountRequest request = new GetAccountRequest(); 
     request.setAccountAgency(accountAgency); 
     request.setAccountNumber(accountNumber); 

     GetAccountResponse response = (GetAccountResponse) 
       getWebServiceTemplate().marshalSendAndReceive(request); 

     return response; 
    } 
} 

我將其配置是這樣的:

@Configuration 
@ComponentScan(basePackages = {"org.myco.mypro.core"}) 
public class WebServiceConfig { 

    @Bean 
    public Jaxb2Marshaller marshaller() throws Exception { 
     Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); 
     marshaller.setContextPath("org.myco.mypro.webservices"); 
     return marshaller; 
    } 

    @Bean 
    public AccountEndpoint accountEndpoint(Jaxb2Marshaller marshaller) { 
     AccountEndpoint client = new AccountEndpoint(); 
     client.setDefaultUri("http://localhost:11000/ws"); 
     client.setMarshaller(marshaller); 
     client.setUnmarshaller(marshaller); 
     return client; 
    } 
} 

和測試:

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(classes = WebServiceConfig.class) 
public class AccountEndpointTest extends TestCase { 

    @Autowired 
    private AccountEndpoint accountEndpoint; 

    public void setUp() throws Exception { 
     super.setUp(); 
    } 

    @Test 
    public void testGetAccount() throws Exception { 

     accountEndpoint.setDefaultUri("http://localhost:11000/ws"); 
     Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); 
     marshaller.setContextPath("org.myco.mypro.webservices"); 
     accountEndpoint.setMarshaller(marshaller); 
     accountEndpoint.setUnmarshaller(marshaller); 

     GetAccountResponse response = accountEndpoint.getAccount(12, 16); 

     assertNotNull(response); 
    } 
} 

如果我沒有設置URI我得到:java.lang.IllegalArgumentException: 'uri' must not be empty;

如果我不設置編組我得到:IllegalStateException: No marshaller registered. Check configuration of WebServiceTemplate.

這就像在WebServiceConfig的配置不工作,儘管豆類自動裝配Autowired不爲空。

我真的很感激任何幫助。謝謝。

+0

如果您仍在監控StackOverflow - 您最終的解決方案是什麼?你能發佈嗎?謝謝 – sairn 2015-06-24 15:14:25

回答

2

您應該從AccountEndpoint中取出@Service註釋。 這個bean是在配置類中創建的。