Package org.apache.soap.transport.http

Examples of org.apache.soap.transport.http.SOAPHTTPConnection


            Envelope msgEnv = Envelope.unmarshall(rdoc);
            // create a new message
            Message msg = new Message();
            result.sampleStart();
            SOAPHTTPConnection spconn = null;
            // if a blank HeaderManager exists, try to
            // get the SOAPHTTPConnection. After the first
            // request, there should be a connection object
            // stored with the cookie header info.
            if (this.getHeaderManager() != null && this.getHeaderManager().getSOAPHeader() != null) {
                spconn = (SOAPHTTPConnection) this.getHeaderManager().getSOAPHeader();
            } else {
                spconn = new SOAPHTTPConnection();
            }

            spconn.setTimeout(getTimeoutAsInt());

            // set the auth. thanks to KiYun Roe for contributing the patch
            // I cleaned up the patch slightly. 5-26-05
            if (getAuthManager() != null) {
                if (getAuthManager().getAuthForURL(getUrl()) != null) {
                    AuthManager authmanager = getAuthManager();
                    Authorization auth = authmanager.getAuthForURL(getUrl());
                    spconn.setUserName(auth.getUser());
                    spconn.setPassword(auth.getPass());
                } else {
                    log.warn("the URL for the auth was null." + " Username and password not set");
                }
            }
            // check the proxy
            String phost = "";
            int pport = 0;
            // if use proxy is set, we try to pick up the
            // proxy host and port from either the text
            // fields or from JMeterUtil if they were passed
            // from command line
            if (this.getUseProxy()) {
                if (this.getProxyHost().length() > 0 && this.getProxyPort() > 0) {
                    phost = this.getProxyHost();
                    pport = this.getProxyPort();
                } else {
                    if (System.getProperty("http.proxyHost") != null || System.getProperty("http.proxyPort") != null) {
                        phost = System.getProperty("http.proxyHost");
                        pport = Integer.parseInt(System.getProperty("http.proxyPort"));
                    }
                }
                // if for some reason the host is blank and the port is
                // zero, the sampler will fail silently
                if (phost.length() > 0 && pport > 0) {
                    spconn.setProxyHost(phost);
                    spconn.setProxyPort(pport);
                    if (PROXY_USER.length()>0 && PROXY_PASS.length()>0){
                        spconn.setProxyUserName(PROXY_USER);
                        spconn.setProxyPassword(PROXY_PASS);
                    }
                }
            }
            // by default we maintain the session.
            spconn.setMaintainSession(true);
            msg.setSOAPTransport(spconn);
            msg.send(this.getUrl(), this.getSoapAction(), msgEnv);
            @SuppressWarnings("unchecked") // API uses raw types
            final Map<String, String> headers = spconn.getHeaders();
            result.setResponseHeaders(convertSoapHeaders(headers));

            if (this.getHeaderManager() != null) {
                this.getHeaderManager().setSOAPHeader(spconn);
            }

            BufferedReader br = null;
            if (spconn.receive() != null) {
                br = spconn.receive();
                SOAPContext sc = spconn.getResponseSOAPContext();
                // Set details from the actual response
                // Needs to be done before response can be stored
                final String contentType = sc.getContentType();
                result.setContentType(contentType);
                result.setEncodingAndType(contentType);
                int length=0;
                if (getReadResponse()) {
                    StringWriter sw = new StringWriter();
                    length=IOUtils.copy(br, sw);
                    result.sampleEnd();
                    result.setResponseData(sw.toString().getBytes(result.getDataEncodingWithDefault()));
                } else {
                    // by not reading the response
                    // for real, it improves the
                    // performance on slow clients
                    length=br.read();
                    result.sampleEnd();
                    result.setResponseData(JMeterUtils.getResString("read_response_message"), null); //$NON-NLS-1$
                }
                // It is not possible to access the actual HTTP response code, so we assume no data means failure
                if (length > 0){
                    result.setSuccessful(true);
                    result.setResponseCodeOK();
                    result.setResponseMessageOK();
                } else {
                    result.setSuccessful(false);
                    result.setResponseCode("999");
                    result.setResponseMessage("Empty response");
                }
            } else {
                result.sampleEnd();
                result.setSuccessful(false);
                final String contentType = spconn.getResponseSOAPContext().getContentType();
                result.setContentType(contentType);
                result.setEncodingAndType(contentType);
                result.setResponseData(spconn.getResponseSOAPContext().toString().getBytes(result.getDataEncodingWithDefault()));
            }
            if (br != null) {
                br.close();
            }
            // reponse code doesn't really apply, since
View Full Code Here


       throws SOAPException {
    call.setTargetObjectURI (ServerConstants.SERVICE_MANAGER_SERVICE_NAME);
    call.setMethodName (methodName);
    call.setEncodingStyleURI (Constants.NS_URI_SOAP_ENC);
    if (userName != null) {
      SOAPHTTPConnection hc = new SOAPHTTPConnection ();
      hc.setUserName (userName);
      hc.setPassword (password);
      call.setSOAPTransport (hc);
    }
    if (param != null) {
      params.removeAllElements ();
      params.addElement (param);
View Full Code Here

        if (serviceURL == null)
            serviceURL = DEFAULT_SERVICE_URL;
        URL url = new URL(serviceURL);

        // create the transport and set parameters
        SOAPHTTPConnection st = new SOAPHTTPConnection();
        if (proxyHost != null) {
            st.setProxyHost(proxyHost);
            st.setProxyPort(proxyPort);

            if (proxyUserName != null) {
                st.setProxyUserName(proxyUserName);
                st.setProxyPassword(proxyPassword);
            }
        }

        // build the call.
        Call call = new Call();
        call.setSOAPTransport(st);
        call.setTargetObjectURI("urn:xmethods-Temperature");
        call.setMethodName("getTemp");
        call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
        Vector params = new Vector();
        params.addElement(new Parameter("zipcode", String.class,
                                        zipcode, null));
        call.setParams(params);

        // invoke it
        System.err.println("Invoking weather service at: ");
        System.err.println("\t" + serviceURL);
        Response resp;
        try {
            // resp = call.invoke(url, null);

            /**
             * Elaborate work-around. xmethods does not like the "charset"
             * modifier on the Content-Type.
             * The work-around mostly consists of a manual implementation
             * of Call.invoke(), with instead of passing the request envelope
             * to the SOAPTransport, manually marshalling it and setting the
             * result as the root part of the request SOAPContext, with a
             * provided Content-Type "text/xml" instead of the default
             * "text/xml; charset=utf-8".
             */
            SOAPMappingRegistry smr = call.getSOAPMappingRegistry();
            SOAPContext reqCtx = call.getSOAPContext();
            DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder();

            Envelope callEnv = call.buildEnvelope();
            StringWriter payloadSW = new StringWriter();
            callEnv.marshall(payloadSW, smr, reqCtx);
            reqCtx.setRootPart(payloadSW.toString(),
                               Constants.HEADERVAL_CONTENT_TYPE);

            st.send(url, "", null, null, smr, reqCtx);

            SOAPContext respCtx = st.getResponseSOAPContext();
            String payloadStr = Call.getEnvelopeString(st);
            Document respDoc =
              xdb.parse(new InputSource(new StringReader(payloadStr)));
            Element payload = null;
            if (respDoc != null)
View Full Code Here

        if (serviceURL == null)
            serviceURL = DEFAULT_SERVICE_URL;
        URL url = new URL(serviceURL);

        // create the transport and set parameters
        SOAPHTTPConnection st = new SOAPHTTPConnection();
        if (proxyHost != null) {
            st.setProxyHost(proxyHost);
            st.setProxyPort(proxyPort);
        }

        // build the call.
        Call call = new Call();
        call.setSOAPTransport(st);
        call.setTargetObjectURI("urn:lemurlabs-Fortune");
        if (getList)
            call.setMethodName("getDictionaryNameList");
        else if (dictionary != null) {
            call.setMethodName("getFortuneByDictionary");
            Vector params = new Vector();
            params.addElement(new Parameter("dictionary", String.class,
                                            dictionary, null));
            call.setParams(params);
        } else
            call.setMethodName("getAnyFortune");
        call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);

        // invoke it
        System.err.println("Invoking fortune service at: ");
        System.err.println("\t" + serviceURL);
        Response resp;
        try {
            // resp = call.invoke(url, null);

            /**
             * Elaborate work-around. lemurlabs does not like the "charset"
             * modifier on the Content-Type.
             * The work-around mostly consists of a manual implementation
             * of Call.invoke(), with instead of passing the request envelope
             * to the SOAPTransport, manually marshalling it and setting the
             * result as the root part of the request SOAPContext, with a
             * provided Content-Type "text/xml" instead of the default
             * "text/xml; charset=utf-8".
             */
            SOAPMappingRegistry smr = call.getSOAPMappingRegistry();
            SOAPContext reqCtx = call.getSOAPContext();
            DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder();

            Envelope callEnv = call.buildEnvelope();
            StringWriter payloadSW = new StringWriter();
            callEnv.marshall(payloadSW, smr, reqCtx);
            reqCtx.setRootPart(payloadSW.toString(),
                               Constants.HEADERVAL_CONTENT_TYPE);

            st.send(url, "", null, null, smr, reqCtx);

            SOAPContext respCtx = st.getResponseSOAPContext();
            String payloadStr = Call.getEnvelopeString(st);
            Document respDoc =
              xdb.parse(new InputSource(new StringReader(payloadStr)));
            Element payload = null;
            if (respDoc != null)
View Full Code Here

    StringDeserializer sd = new StringDeserializer ();
    smr.mapTypes (Constants.NS_URI_SOAP_ENC,
                  new QName ("", "Result"), null, null, sd);

    // create the transport and set parameters
    SOAPHTTPConnection st = new SOAPHTTPConnection();
    if (proxyHost != null) {
        st.setProxyHost(proxyHost);
        st.setProxyPort(proxyPort);
    }

    // build the call.
    Call call = new Call ();
    call.setSOAPTransport(st);
View Full Code Here

      org.w3c.dom.Element rdoc = createDocument();
            Envelope msgEnv = Envelope.unmarshall(rdoc);
            // create a new message
            Message msg = new Message();
            RESULT.sampleStart();
      SOAPHTTPConnection spconn = null;
      // if a blank HeaderManager exists, try to
      // get the SOAPHTTPConnection. After the first
      // request, there should be a connection object
      // stored with the cookie header info.
      if (this.getHeaderManager() != null &&
        this.getHeaderManager().getSOAPHeader() != null) {
        spconn = (SOAPHTTPConnection)this.getHeaderManager().
          getSOAPHeader();
      } else {
        spconn = new SOAPHTTPConnection();
      }
      // check the proxy
      String phost = "";
      int pport = 0;
      // if use proxy is set, we try to pick up the
      // proxy host and port from either the text
      // fields or from JMeterUtil if they were passed
      // from command line
      if (this.getUseProxy()){
        if (this.getProxyHost().length() > 0 &&  this.getProxyPort() > 0){
          phost = this.getProxyHost();
          pport = this.getProxyPort();
        } else {
          if (System.getProperty("http.proxyHost") != null ||
            System.getProperty("http.proxyPort") != null){
              phost = System.getProperty("http.proxyHost");
              pport = Integer.parseInt(
                System.getProperty("http.proxyPort"));
            }
        }
        // if for some reason the host is blank and the port is
        // zero, the sampler will fail silently
        if (phost.length() > 0 && pport > 0){
          spconn.setProxyHost(phost);
          spconn.setProxyPort(pport);
        }
      }
      // by default we maintain the session. 
      spconn.setMaintainSession(true);
      msg.setSOAPTransport(spconn);
            msg.send(this.getUrl(), this.getSoapAction(), msgEnv);

      if (this.getHeaderManager() != null){
        this.getHeaderManager().setSOAPHeader(spconn);
View Full Code Here

            // Port jms:address binding element
            jmsAddressPropVals = ja.getJMSPropertyValues();
            st = new SOAPJMSConnection(ja, port.getName());
        } else {
            // Port soap:address bindng element
            st = new SOAPHTTPConnection();
            // call.getSOAPTransport() is null...

            String s = sa.getLocationURI();
            try {
                url = new URL(s);
View Full Code Here

            // Port jms:address binding element
            jmsAddressPropVals = ja.getJMSPropertyValues();
            st = new SOAPJMSConnection(ja, port.getName());
        } else {
            // Port soap:address bindng element
            st = new SOAPHTTPConnection();
        }       
    }  
View Full Code Here

     * are the basic authentication user id and password.
     */
    private void addHTTPHeader(Call call, String name, String value) {
        SOAPTransport st = call.getSOAPTransport();
        if (st instanceof SOAPHTTPConnection) {
            SOAPHTTPConnection httpTransport = (SOAPHTTPConnection) st;
            if (name.equals(WSIFConstants.CONTEXT_HTTP_USER)) {
                httpTransport.setUserName(value);
            } else if (name.equals(WSIFConstants.CONTEXT_HTTP_PSWD)) {
                httpTransport.setPassword(value);
            }
        }
    }
View Full Code Here

     * system properties for a proxy server, we need to set
     * it up manually.
     */
    private void setSOAPProxy(SOAPTransport st) {
        if (st instanceof SOAPHTTPConnection) {
           SOAPHTTPConnection shttpc = (SOAPHTTPConnection) st;
           String proxyHost =
              (String) AccessController.doPrivileged(new PrivilegedAction() {
                 public Object run() {
                    return System.getProperty( HTTP_PROXY_HOST_PROPERTY );
                 }
              });
           String proxyPort =
              (String) AccessController.doPrivileged(new PrivilegedAction() {
                 public Object run() {
                    return System.getProperty( HTTP_PROXY_PORT_PROPERTY );
                 }
              });
           if ( proxyHost != null && proxyHost.length() > 0 ) {
              shttpc.setProxyHost( proxyHost );
              if ( proxyPort != null && proxyPort.length() > 0 ) {
                 try {
                   int port = Integer.parseInt( proxyPort );
                    shttpc.setProxyPort( port );
                 } catch (NumberFormatException ex) {
                    Trc.ignoredException(ex);
                 }
              }
           }
View Full Code Here

TOP

Related Classes of org.apache.soap.transport.http.SOAPHTTPConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.