⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commonshttpmessagesender.java

📁 Xfire文件 用于开发web service 的一个开源工具 很好用的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            {                return;            }                        // Setup the proxy settings            String proxyHost = (String) context.getContextualProperty(HTTP_PROXY_HOST);            if (proxyHost == null)            {                proxyHost = System.getProperty(HTTP_PROXY_HOST);            }                        if (proxyHost != null)            {                 String portS = (String) context.getContextualProperty(HTTP_PROXY_PORT);                if (portS == null)                {                    portS = System.getProperty(HTTP_PROXY_PORT);                }                int port = 80;                if (portS != null)                    port = Integer.parseInt(portS);                client.getHostConfiguration().setProxy(proxyHost, port);                                String proxyUser = (String) context.getContextualProperty(HTTP_PROXY_USER);                String proxyPass = (String) context.getContextualProperty(HTTP_PROXY_PASS);                if( proxyUser != null && proxyPass != null )                 	getHttpState().setProxyCredentials(AuthScope.ANY,getCredentials(proxyUser, proxyPass));            }        }    }    private boolean isNonProxyHost( String strURI, MessageContext context )     {    	if (!useProxyUtils) {    		return false;    	}    	    	if (!isJDK5andAbove()) {    		useProxyUtils = false;    		return false;    	}    	    	Class clazz;    	String className = (String) context.getContextualProperty(PROXY_UTILS_CLASS);    	if( className == null ){    		className = DEFAULT_PROXY_UTILS_CLASS;    	}    	// TODO : make this clazz static		try {			clazz = Class.forName(className);			Object proxyUtils = clazz.newInstance();	    	//Method 	    	Method method = clazz.getDeclaredMethod("isNonProxyHost", new Class[]{String.class});	    	Boolean result = (Boolean) method.invoke(proxyUtils,new Object[]{strURI});	    	return result.booleanValue();		} catch (Exception  e) {			// Don't care what happend, we can't check for proxy			log.debug("Could not load ProxyUtils class: "+ className);			return false;		}    }        boolean isJDK5andAbove()    {        String v = System.getProperty("java.class.version", "44.0");        return ("49.0".compareTo(v) <= 0);    }        static boolean isGzipRequestEnabled(MessageContext context)    {        if (isGzipEnabled(context)) return true;                Object gzipReqEnabled = context.getContextualProperty(GZIP_REQUEST_ENABLED);        return (gzipReqEnabled != null && gzipReqEnabled.toString().toLowerCase().equals("true"));    }        static boolean isGzipEnabled(MessageContext context)    {        Object gzipEnabled = context.getContextualProperty(GZIP_ENABLED);        return (gzipEnabled != null && gzipEnabled.toString().toLowerCase().equals("true"));    }        static boolean isGzipResponseEnabled(MessageContext context)    {        if (isGzipEnabled(context)) return true;                Object gzipResEnabled = context.getContextualProperty(GZIP_RESPONSE_ENABLED);        return (gzipResEnabled != null && gzipResEnabled.toString().toLowerCase().equals("true"));    }        public void send()        throws HttpException, IOException, XFireException    {        RequestEntity requestEntity;                /**         * Lots of HTTP servers don't handle chunking correctly, so its turned off by default.         */        boolean chunkingOn = Boolean.valueOf((String) getMessageContext()                .getContextualProperty(HttpTransport.CHUNKING_ENABLED)).booleanValue();        if (!chunkingOn)        {            requestEntity = getByteArrayRequestEntity();        }        else        {            requestEntity = new OutMessageRequestEntity(getMessage(), getMessageContext());        }                getMethod().setRequestEntity(requestEntity);                client.executeMethod(null, postMethod, state);    }    public int getStatusCode(){        return  postMethod.getStatusCode();    }    /**     * @return     */        public boolean hasResponse()    {        NameValuePair pair = postMethod.getResponseHeader("Content-Type");        if(pair == null) return false;                String ct = pair.getValue();                return ct != null && ct.length() > 0;    }        public HttpState getHttpState()    {        HttpState state = (HttpState) ((HttpChannel) getMessage().getChannel()).getProperty(HTTP_STATE);        if (state == null)         {            state = new HttpState();                        ((HttpChannel) getMessage().getChannel()).setProperty(HTTP_STATE, state);        }                return state;    }    private RequestEntity getByteArrayRequestEntity()        throws IOException, XFireException    {        OutMessage message = getMessage();        MessageContext context = getMessageContext();        ByteArrayOutputStream bos = new ByteArrayOutputStream();        OutputStream os = bos;        if (isGzipRequestEnabled(context))        {            os = new GZIPOutputStream(os);        }                Attachments atts = message.getAttachments();        if (atts != null)        {            atts.write(os);        }        else        {            HttpChannel.writeWithoutAttachments(context, message, os);        }                os.close();                return new ByteArrayRequestEntity(bos.toByteArray());    }        public InMessage getInMessage()        throws IOException    {        String ct = postMethod.getResponseHeader("Content-Type").getValue();        InputStream in = postMethod.getResponseBodyAsStream();        Header hce = postMethod.getResponseHeader("Content-Encoding");                if (hce != null && hce.getValue().equals(GZIP_CONTENT_ENCODING))        {            in = new GZIPInputStream(in);        }                if (ct.toLowerCase().indexOf("multipart/related") != -1)        {            Attachments atts = new StreamedAttachments(getMessageContext(),in, ct);            msgIs = atts.getSoapMessage().getDataHandler().getInputStream();                        InMessage msg = new InMessage(STAXUtils.createXMLStreamReader(msgIs, getEncoding(),getMessageContext()), getUri());            msg.setAttachments(atts);            return msg;        }        else        {            return new InMessage(STAXUtils.createXMLStreamReader(in, getEncoding(),getMessageContext()), getUri());        }    }    public PostMethod getMethod()    {        return this.postMethod;    }    public void close()        throws XFireException    {        if (msgIs != null)        {            try            {                msgIs.close();            }            catch (IOException e)            {                throw new XFireException("Could not close connection.", e);            }        }                if (source != null)        {            source.dispose();        }                if (postMethod != null)            postMethod.releaseConnection();    }    	private Credentials getCredentials(String username, String password){		 	         client.getParams().setAuthenticationPreemptive(true);	         	         int domainIndex = username.indexOf('\\');	         if (domainIndex > 0 && username.length() > domainIndex + 1) {		                     return new NTCredentials(	                    		 username.substring(domainIndex+1), 	                             password, 	                             "localhost", // TODO: resolve local host name 	                             username.substring(0, domainIndex));	                     	         } 	             	             return  new UsernamePasswordCredentials(username,password);	             	         	         	     	}	    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -