Search in sources :

Example 76 with Header

use of org.apache.cxf.headers.Header in project components by Talend.

the class NetSuiteClientService method setLoginHeaders.

/**
 * Set log-in specific SOAP headers for given port.
 *
 * @param port port
 * @throws NetSuiteException if an error occurs during performing of operation
 */
protected void setLoginHeaders(PortT port) throws NetSuiteException {
    if (!StringUtils.isEmpty(credentials.getApplicationId())) {
        Object applicationInfo = createNativeApplicationInfo(credentials);
        try {
            if (applicationInfo != null) {
                Header appInfoHeader = new Header(new QName(getPlatformMessageNamespaceUri(), "applicationInfo"), applicationInfo, new JAXBDataBinding(applicationInfo.getClass()));
                setHeader(port, appInfoHeader);
            }
        } catch (JAXBException e) {
            throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.INTERNAL_ERROR), "XML binding error", e);
        }
    }
}
Also used : NetSuiteErrorCode(org.talend.components.netsuite.NetSuiteErrorCode) Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding)

Example 77 with Header

use of org.apache.cxf.headers.Header in project components by Talend.

the class NetSuiteClientServiceTest method testConnectAndLogin.

/**
 * TODO Verify headers (applicationInfo etc.)
 */
@Test
public void testConnectAndLogin() throws Exception {
    final NetSuiteCredentials credentials = webServiceMockTestFixture.getCredentials();
    final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
    SessionResponse sessionResponse = new SessionResponse();
    sessionResponse.setStatus(createSuccessStatus());
    LoginResponse response = new LoginResponse();
    response.setSessionResponse(sessionResponse);
    when(port.login(argThat(new AssertMatcher<LoginRequest>() {

        @Override
        protected void doAssert(LoginRequest target) throws Exception {
            assertEquals(credentials.getEmail(), target.getPassport().getEmail());
            assertEquals(credentials.getPassword(), target.getPassport().getPassword());
            assertEquals(credentials.getRoleId(), target.getPassport().getRole().getInternalId());
            assertEquals(credentials.getAccount(), target.getPassport().getAccount());
            MessageContext messageContext = MessageContextHolder.get();
            assertNotNull(messageContext);
            List<Header> headers = (List<Header>) messageContext.get(Header.HEADER_LIST);
            assertNotNull(headers);
            Header appInfoHeader = NetSuiteWebServiceMockTestFixture.getHeader(headers, new QName(NetSuiteClientServiceImpl.NS_URI_PLATFORM_MESSAGES, "applicationInfo"));
            assertNotNull(appInfoHeader);
        }
    }))).thenReturn(response);
    NetSuiteClientService<?> clientService = webServiceMockTestFixture.getClientService();
    clientService.login();
    verify(port, times(1)).login(any(LoginRequest.class));
}
Also used : NetSuitePortType(com.netsuite.webservices.v2014_2.platform.NetSuitePortType) NetSuiteCredentials(org.talend.components.netsuite.client.NetSuiteCredentials) LoginResponse(com.netsuite.webservices.v2014_2.platform.messages.LoginResponse) Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) List(java.util.List) LoginRequest(com.netsuite.webservices.v2014_2.platform.messages.LoginRequest) MessageContext(javax.xml.ws.handler.MessageContext) SessionResponse(com.netsuite.webservices.v2014_2.platform.messages.SessionResponse) AssertMatcher(org.talend.components.netsuite.test.AssertMatcher) Test(org.junit.Test)

Example 78 with Header

use of org.apache.cxf.headers.Header in project winery by eclipse.

the class Headers method asMap.

public static Map<String, String> asMap(final WebServiceContext ctx) {
    Map<String, String> headers = new HashMap<>();
    for (Header h : asList(ctx)) {
        Element n = (Element) h.getObject();
        headers.put(n.getLocalName(), n.getTextContent());
    }
    return headers;
}
Also used : Header(org.apache.cxf.headers.Header) HashMap(java.util.HashMap) Element(org.w3c.dom.Element)

Aggregations

Header (org.apache.cxf.headers.Header)78 QName (javax.xml.namespace.QName)29 Element (org.w3c.dom.Element)27 ArrayList (java.util.ArrayList)25 JAXBException (javax.xml.bind.JAXBException)24 SoapHeader (org.apache.cxf.binding.soap.SoapHeader)18 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)17 Node (org.w3c.dom.Node)16 JAXBDataBinding (org.apache.cxf.jaxb.JAXBDataBinding)15 JAXBElement (javax.xml.bind.JAXBElement)14 List (java.util.List)13 OutofBandHeader (org.apache.cxf.outofband.header.OutofBandHeader)13 MessageContext (javax.xml.ws.handler.MessageContext)9 Test (org.junit.Test)9 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)8 SoapVersion (org.apache.cxf.binding.soap.SoapVersion)7 Message (org.apache.cxf.message.Message)7 HashMap (java.util.HashMap)6 Fault (org.apache.cxf.interceptor.Fault)6 Exchange (org.apache.cxf.message.Exchange)6