Example usage for javax.xml.ws.http HTTPBinding HTTP_BINDING

List of usage examples for javax.xml.ws.http HTTPBinding HTTP_BINDING

Introduction

In this page you can find the example usage for javax.xml.ws.http HTTPBinding HTTP_BINDING.

Prototype

String HTTP_BINDING

To view the source code for javax.xml.ws.http HTTPBinding HTTP_BINDING.

Click Source Link

Document

A constant representing the identity of the XML/HTTP binding.

Usage

From source file:com.wavemaker.runtime.ws.HTTPBindingSupport.java

@SuppressWarnings("unchecked")
private static <T extends Object> T getResponse(QName serviceQName, QName portQName, String endpointAddress,
        HTTPRequestMethod method, T postSource, BindingProperties bindingProperties, Class<T> type,
        Map<String, Object> headerParams) throws WebServiceException {

    Service service = Service.create(serviceQName);
    URI endpointURI;//ww  w  . j  a  v  a2s  .  c o  m
    try {
        if (bindingProperties != null) {
            // if BindingProperties had endpointAddress defined, then use
            // it instead of the endpointAddress passed in from arguments.
            String endAddress = bindingProperties.getEndpointAddress();
            if (endAddress != null) {
                endpointAddress = endAddress;
            }
        }
        endpointURI = new URI(endpointAddress);
    } catch (URISyntaxException e) {
        throw new WebServiceException(e);
    }

    String endpointPath = null;
    String endpointQueryString = null;
    if (endpointURI != null) {
        endpointPath = endpointURI.getRawPath();
        endpointQueryString = endpointURI.getRawQuery();
    }

    service.addPort(portQName, HTTPBinding.HTTP_BINDING, endpointAddress);

    Dispatch<T> d = service.createDispatch(portQName, type, Service.Mode.MESSAGE);

    Map<String, Object> requestContext = d.getRequestContext();
    requestContext.put(MessageContext.HTTP_REQUEST_METHOD, method.toString());
    requestContext.put(MessageContext.QUERY_STRING, endpointQueryString);
    requestContext.put(MessageContext.PATH_INFO, endpointPath);

    Map<String, List<String>> reqHeaders = null;
    if (bindingProperties != null) {
        String httpBasicAuthUsername = bindingProperties.getHttpBasicAuthUsername();
        if (httpBasicAuthUsername != null) {
            requestContext.put(BindingProvider.USERNAME_PROPERTY, httpBasicAuthUsername);
            String httpBasicAuthPassword = bindingProperties.getHttpBasicAuthPassword();
            requestContext.put(BindingProvider.PASSWORD_PROPERTY, httpBasicAuthPassword);
        }

        int connectionTimeout = bindingProperties.getConnectionTimeout();
        requestContext.put(JAXWSProperties.CONNECT_TIMEOUT, Integer.valueOf(connectionTimeout));

        int requestTimeout = bindingProperties.getRequestTimeout();
        requestContext.put(JAXWSProperties.REQUEST_TIMEOUT, Integer.valueOf(requestTimeout));

        Map<String, List<String>> httpHeaders = bindingProperties.getHttpHeaders();
        if (httpHeaders != null && !httpHeaders.isEmpty()) {
            reqHeaders = (Map<String, List<String>>) requestContext.get(MessageContext.HTTP_REQUEST_HEADERS);
            if (reqHeaders == null) {
                reqHeaders = new HashMap<String, List<String>>();
                requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, reqHeaders);
            }
            for (Entry<String, List<String>> entry : httpHeaders.entrySet()) {
                reqHeaders.put(entry.getKey(), entry.getValue());
            }
        }
    }

    // Parameters to pass in http header
    if (headerParams != null && headerParams.size() > 0) {
        if (null == reqHeaders) {
            reqHeaders = new HashMap<String, List<String>>();
        }
        Set<Entry<String, Object>> entries = headerParams.entrySet();
        for (Map.Entry<String, Object> entry : entries) {
            List<String> valList = new ArrayList<String>();
            valList.add((String) entry.getValue());
            reqHeaders.put(entry.getKey(), valList);
            requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, reqHeaders);
        }
    }

    logger.info("Invoking HTTP '" + method + "' request with URL: " + endpointAddress);

    T result = d.invoke(postSource);
    return result;
}

From source file:org.apache.axis2.jaxws.client.dispatch.BaseDispatch.java

private boolean isValidInvocationParam(Object object) {
    String bindingId = endpointDesc.getClientBindingID();

    // If no bindingId was found, use the default.
    if (bindingId == null) {
        bindingId = SOAPBinding.SOAP11HTTP_BINDING;
    }//from   w  w  w.  ja  v a2 s  .  c o m

    // If it's not an HTTP_BINDING, then we can allow for null params,  
    // but only in PAYLOAD mode per JAX-WS Section 4.3.2.
    if (!bindingId.equals(HTTPBinding.HTTP_BINDING)) {
        if (mode.equals(Mode.MESSAGE) && object == null) {
            throw ExceptionFactory.makeWebServiceException(Messages.getMessage("dispatchNullParamMessageMode"));
        }
    } else {
        // In all cases (PAYLOAD and MESSAGE) we must throw a WebServiceException
        // if the parameter is null and request method is POST or PUT.
        if (object == null && isPOSTorPUTRequest()) {
            throw ExceptionFactory.makeWebServiceException(Messages.getMessage("dispatchNullParamHttpBinding"));
        }
    }

    if (object instanceof DOMSource) {
        DOMSource ds = (DOMSource) object;
        if (ds.getNode() == null && ds.getSystemId() == null) {
            throw ExceptionFactory.makeWebServiceException(Messages.getMessage("dispatchBadDOMSource"));
        }
    }

    // If we've gotten this far, then all is good.
    return true;
}

From source file:org.apache.axis2.jaxws.server.endpoint.Utils.java

@Deprecated
/**//from w ww. j a v a 2s  . com
 * Compares the version of the message in the MessageContext to what's expected
 * given the ServiceDescription.  The behavior is described in the SOAP 1.2
 * specification under Appendix 'A'.
 * 
 * @param mc
 * @param serviceDesc
 * @return
 */
public static boolean bindingTypesMatch(MessageContext mc, ServiceDescription serviceDesc) {
    Collection<EndpointDescription> eds = serviceDesc.getEndpointDescriptions_AsCollection();

    // Dispatch endpoints do not have SEIs, so watch out for null or empty array
    if ((eds != null) && (eds.size() > 0)) {
        Iterator<EndpointDescription> i = eds.iterator();
        if (i.hasNext()) {
            EndpointDescription ed = eds.iterator().next();

            Protocol protocol = mc.getMessage().getProtocol();
            String bindingType = ed.getBindingType();

            if (log.isDebugEnabled()) {
                log.debug("Checking for matching binding types.");
                log.debug("    message protocol: " + protocol);
                log.debug("        binding type: " + bindingType);
            }

            if (protocol.equals(Protocol.soap11)) {
                return (BindingUtils.isSOAP11Binding(bindingType));
            } else if (protocol.equals(Protocol.soap12)) {
                return (BindingUtils.isSOAP12Binding(bindingType));
            } else if (protocol.equals(Protocol.rest)) {
                return HTTPBinding.HTTP_BINDING.equalsIgnoreCase(bindingType);
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("There were no endpoint descriptions found, thus the binding match failed.");
            }
            return false;
        }
    }
    return true;
}

From source file:org.apache.axis2.jaxws.server.endpoint.Utils.java

/**
 * Compares the version of the message in the MessageContext to what's expected
 * given the ServiceDescription.  The behavior is described in the SOAP 1.2
 * specification under Appendix 'A'.//ww w  . j  a  v a 2s  .c  om
 * 
 * @param mc
 * @param serviceDesc
 * @return
 */
public static boolean bindingTypesMatch(MessageContext mc, EndpointDescription ed) {

    Protocol protocol = mc.getMessage().getProtocol();
    String bindingType = ed.getBindingType();

    if (log.isDebugEnabled()) {
        log.debug("Checking for matching binding types.");
        log.debug("    message protocol: " + protocol);
        log.debug("        binding type: " + bindingType);
    }

    if (protocol.equals(Protocol.soap11)) {
        return (BindingUtils.isSOAP11Binding(bindingType));
    } else if (protocol.equals(Protocol.soap12)) {
        return (BindingUtils.isSOAP12Binding(bindingType));
    } else if (protocol.equals(Protocol.rest)) {
        return HTTPBinding.HTTP_BINDING.equalsIgnoreCase(bindingType);
    }
    return true;
}

From source file:org.seedstack.seed.ws.internal.WSPlugin.java

private String getBindingIdForToken(String lexical) { // NOSONAR
    if ("##SOAP11_HTTP".equals(lexical)) {
        return SOAPBinding.SOAP11HTTP_BINDING;
    } else if ("##SOAP11_HTTP_MTOM".equals(lexical)) {
        return SOAPBinding.SOAP11HTTP_MTOM_BINDING;
    } else if ("##SOAP12_HTTP".equals(lexical)) {
        return SOAPBinding.SOAP12HTTP_BINDING;
    } else if ("##SOAP12_HTTP_MTOM".equals(lexical)) {
        return SOAPBinding.SOAP12HTTP_MTOM_BINDING;
    } else if ("##XML_HTTP".equals(lexical)) {
        return HTTPBinding.HTTP_BINDING;
    }/*from  w w w.ja  v  a  2  s  . c  o  m*/
    return lexical;
}