Search in sources :

Example 1 with Header

use of org.apache.cxf.headers.Header in project OpenAM by OpenRock.

the class OpenAMSessionTokenClientInterceptor method addToken.

/**
     * This method is called on the outbound client side, secure-request in JASPI terms. This method will add the
     * OpenAMSessionAssertion state to the message.
     * @param message the encapsulation of the soap request.
     */
@Override
protected void addToken(SoapMessage message) {
    OpenAMSessionAssertion openAMSessionAssertion = (OpenAMSessionAssertion) assertTokens(message);
    Header header = findSecurityHeader(message, true);
    final Element element = (Element) header.getObject();
    final Element openAMSessionAssertionElement = openAMSessionAssertion.getTokenElement();
    element.appendChild(element.getOwnerDocument().importNode(openAMSessionAssertionElement, true));
}
Also used : Header(org.apache.cxf.headers.Header) Element(org.w3c.dom.Element)

Example 2 with Header

use of org.apache.cxf.headers.Header in project tdi-studio-se by Talend.

the class NetsuiteManagement_CXF method initializeStub.

public void initializeStub() throws Exception {
    URL wsdl_locationUrl = this.getClass().getResource("/wsdl/netsuite.wsdl");
    QName serviceQname = new QName("urn:platform_2014_2.webservices.netsuite.com", "NetSuiteService");
    NetSuiteService service = new NetSuiteService(wsdl_locationUrl, serviceQname);
    NetSuitePortType port = service.getNetSuitePort();
    BindingProvider provider = (BindingProvider) port;
    Map<String, Object> requestContext = provider.getRequestContext();
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, _url);
    Preferences preferences = new Preferences();
    preferences.setDisableMandatoryCustomFieldValidation(Boolean.FALSE);
    preferences.setWarningAsError(Boolean.FALSE);
    preferences.setIgnoreReadOnlyFields(Boolean.TRUE);
    preferences.setDisableMandatoryCustomFieldValidation(Boolean.TRUE);
    SearchPreferences searchPreferences = new SearchPreferences();
    searchPreferences.setPageSize(this._pageSize);
    searchPreferences.setBodyFieldsOnly(Boolean.valueOf(false));
    RecordRef role = new RecordRef();
    role.setInternalId(this._role);
    Passport passport = new Passport();
    passport.setEmail(this._email);
    passport.setPassword(this._pwd);
    passport.setRole(role);
    passport.setAccount(this._account);
    // Get the webservices domain for your account
    GetDataCenterUrlsRequest dataCenterRequest = new GetDataCenterUrlsRequest();
    dataCenterRequest.setAccount(this._account);
    DataCenterUrls urls = null;
    GetDataCenterUrlsResponse reponse = port.getDataCenterUrls(dataCenterRequest);
    if (reponse != null && reponse.getGetDataCenterUrlsResult() != null) {
        urls = reponse.getGetDataCenterUrlsResult().getDataCenterUrls();
    }
    if (urls == null) {
        throw new Exception("Can't get a correct webservice domain! Please check your configuration or try to run again.");
    }
    String wsDomain = urls.getWebservicesDomain();
    String endpoint = wsDomain.concat(new URL(this._url).getPath());
    requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
    List<Header> list = (List<Header>) requestContext.get(Header.HEADER_LIST);
    if (list == null) {
        list = new ArrayList<Header>();
        requestContext.put(Header.HEADER_LIST, list);
    }
    Header searchPreferences_header = new Header(new QName("urn:messages_2014_2.platform.webservices.netsuite.com", "searchPreferences"), searchPreferences, new JAXBDataBinding(searchPreferences.getClass()));
    Header preferences_header = new Header(new QName("urn:messages_2014_2.platform.webservices.netsuite.com", "preferences"), preferences, new JAXBDataBinding(preferences.getClass()));
    list.add(searchPreferences_header);
    list.add(preferences_header);
    LoginRequest request = new LoginRequest();
    request.setPassport(passport);
    port.login(request);
    this._port = port;
    Arrays.asList(new String[] { "", "", "" });
}
Also used : GetDataCenterUrlsResponse(com.netsuite.webservices.platform.messages.GetDataCenterUrlsResponse) QName(javax.xml.namespace.QName) RecordRef(com.netsuite.webservices.platform.core.RecordRef) ListOrRecordRef(com.netsuite.webservices.platform.core.ListOrRecordRef) DataCenterUrls(com.netsuite.webservices.platform.core.DataCenterUrls) BindingProvider(javax.xml.ws.BindingProvider) LoginRequest(com.netsuite.webservices.platform.messages.LoginRequest) URL(java.net.URL) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) SOAPException(javax.xml.soap.SOAPException) ParseException(java.text.ParseException) JAXBException(javax.xml.bind.JAXBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedURLException(java.net.MalformedURLException) NetSuitePortType(com.netsuite.webservices.platform.NetSuitePortType) SearchPreferences(com.netsuite.webservices.platform.messages.SearchPreferences) Passport(com.netsuite.webservices.platform.core.Passport) Header(org.apache.cxf.headers.Header) NetSuiteService(com.netsuite.webservices.platform.NetSuiteService) GetDataCenterUrlsRequest(com.netsuite.webservices.platform.messages.GetDataCenterUrlsRequest) List(java.util.List) SearchCustomFieldList(com.netsuite.webservices.platform.core.SearchCustomFieldList) ArrayList(java.util.ArrayList) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) SearchPreferences(com.netsuite.webservices.platform.messages.SearchPreferences) Preferences(com.netsuite.webservices.platform.messages.Preferences)

Example 3 with Header

use of org.apache.cxf.headers.Header in project libresonic by Libresonic.

the class SonosService method getUsername.

private String getUsername() {
    MessageContext messageContext = context.getMessageContext();
    if (messageContext == null || !(messageContext instanceof WrappedMessageContext)) {
        LOG.error("Message context is null or not an instance of WrappedMessageContext.");
        return null;
    }
    Message message = ((WrappedMessageContext) messageContext).getWrappedMessage();
    List<Header> headers = CastUtils.cast((List<?>) message.get(Header.HEADER_LIST));
    if (headers != null) {
        for (Header h : headers) {
            Object o = h.getObject();
            // Unwrap the node using JAXB
            if (o instanceof Node) {
                JAXBContext jaxbContext;
                try {
                    // TODO: Check performance
                    jaxbContext = new JAXBDataBinding(Credentials.class).getContext();
                    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
                    o = unmarshaller.unmarshal((Node) o);
                } catch (JAXBException e) {
                    // failed to get the credentials object from the headers
                    LOG.error("JAXB error trying to unwrap credentials", e);
                }
            }
            if (o instanceof Credentials) {
                Credentials c = (Credentials) o;
                // Note: We're using the username as session ID.
                String username = c.getSessionId();
                if (username == null) {
                    LOG.debug("No session id in credentials object, get from login");
                    username = c.getLogin().getUsername();
                }
                return username;
            } else {
                LOG.error("No credentials object");
            }
        }
    } else {
        LOG.error("No headers found");
    }
    return null;
}
Also used : Message(org.apache.cxf.message.Message) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Header(org.apache.cxf.headers.Header) WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) MessageContext(javax.xml.ws.handler.MessageContext) WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 4 with Header

use of org.apache.cxf.headers.Header in project camel by apache.

the class SoapMessageHeaderFilter method filter.

public void filter(Direction direction, List<Header> headers) {
    // Treat both in and out direction the same
    if (headers == null) {
        return;
    }
    Iterator<Header> iterator = headers.iterator();
    while (iterator.hasNext()) {
        Header header = iterator.next();
        LOG.trace("Processing header: {}", header);
        if (!(header instanceof SoapHeader)) {
            LOG.trace("Skipped header: {} since it is not a SoapHeader", header);
            continue;
        }
        SoapHeader soapHeader = SoapHeader.class.cast(header);
        for (Iterator<SoapVersion> itv = SoapVersionFactory.getInstance().getVersions(); itv.hasNext(); ) {
            SoapVersion version = itv.next();
            if (soapHeader.getActor() != null && soapHeader.getActor().equals(version.getNextRole())) {
                // dropping headers if actor/role equals to {ns}/role|actor/next
                // cxf SoapHeader needs to have soap:header@relay attribute, 
                // then we can check for it here as well
                LOG.trace("Filtered header: {}", header);
                iterator.remove();
                break;
            }
        }
    }
}
Also used : SoapVersion(org.apache.cxf.binding.soap.SoapVersion) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) Header(org.apache.cxf.headers.Header) SoapHeader(org.apache.cxf.binding.soap.SoapHeader)

Example 5 with Header

use of org.apache.cxf.headers.Header in project camel by apache.

the class CxfMessageHeadersRelayTest method validateReturnedOutOfBandHeaderWithInsertion.

protected static void validateReturnedOutOfBandHeaderWithInsertion(Map<String, Object> responseContext, boolean expect) {
    List<OutofBandHeader> hdrToTest = new ArrayList<OutofBandHeader>();
    List<Header> oobHdr = CastUtils.cast((List<?>) responseContext.get(Header.HEADER_LIST));
    if (!expect) {
        if (oobHdr == null || (oobHdr != null && oobHdr.size() == 0)) {
            return;
        }
        fail("Should have got *no* out-of-band headers, but some were found");
    }
    if (oobHdr == null) {
        fail("Should have got List of out-of-band headers");
    }
    assertTrue("HeaderHolder list expected to conain 2 object received " + oobHdr.size(), oobHdr.size() == 2);
    for (Header hdr1 : oobHdr) {
        if (hdr1.getObject() instanceof Node) {
            try {
                JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(org.apache.cxf.outofband.header.ObjectFactory.class).createUnmarshaller().unmarshal((Node) hdr1.getObject());
                hdrToTest.add((OutofBandHeader) job.getValue());
            } catch (JAXBException ex) {
                ex.printStackTrace();
            }
        }
    }
    assertTrue("out-of-band header should not be null", hdrToTest.size() > 0);
    assertTrue("Expected out-of-band Header name testOobReturnHeaderName recevied :" + hdrToTest.get(0).getName(), "testOobReturnHeaderName".equals(hdrToTest.get(0).getName()));
    assertTrue("Expected out-of-band Header value testOobReturnHeaderValue recevied :" + hdrToTest.get(0).getValue(), "testOobReturnHeaderValue".equals(hdrToTest.get(0).getValue()));
    assertTrue("Expected out-of-band Header attribute testReturnHdrAttribute recevied :" + hdrToTest.get(0).getHdrAttribute(), "testReturnHdrAttribute".equals(hdrToTest.get(0).getHdrAttribute()));
    assertTrue("Expected out-of-band Header name New_testOobHeader recevied :" + hdrToTest.get(1).getName(), "New_testOobHeader".equals(hdrToTest.get(1).getName()));
    assertTrue("Expected out-of-band Header value New_testOobHeaderValue recevied :" + hdrToTest.get(1).getValue(), "New_testOobHeaderValue".equals(hdrToTest.get(1).getValue()));
    assertTrue("Expected out-of-band Header attribute testHdrAttribute recevied :" + hdrToTest.get(1).getHdrAttribute(), "testHdrAttribute".equals(hdrToTest.get(1).getHdrAttribute()));
}
Also used : SoapHeader(org.apache.cxf.binding.soap.SoapHeader) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) Header(org.apache.cxf.headers.Header) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) JAXBElement(javax.xml.bind.JAXBElement)

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