/* */ private Object nextMatch() /* */ { /* 85 */ while (this.iterator.hasNext()) { /* 86 */ MimeHeader mimeheader = (MimeHeader) this.iterator.next(); /* */ /* 88 */ if (this.names == null) { /* 89 */ return ((this.match) ? null : mimeheader); /* */ } /* */ /* 94 */ for (int i = 0; i < this.names.length; ++i) { /* 95 */ if (!(mimeheader.getName().equalsIgnoreCase(this.names[i]))) { /* */ continue; /* */ } /* */ /* 99 */ if (!(this.match)) break; /* 100 */ return mimeheader; /* */ } /* */ /* 106 */ label90: if (!(this.match)) { /* 107 */ return mimeheader; /* */ } /* */ } /* */ /* 111 */ return null; /* */ }
/* */ public void removeHeader(String name) /* */ { /* 311 */ for (int i = 0; i < this.headers.size(); ++i) { /* 312 */ MimeHeader mimeheader = (MimeHeader) this.headers.elementAt(i); /* */ /* 314 */ if (mimeheader.getName().equalsIgnoreCase(name)) /* 315 */ this.headers.removeElementAt(i--); /* */ } /* */ }
private MimePart transferMessageHeaders(MimePart newBody) { for (Iterator<MimeHeader> it = body.getMimeHeaderBlock().iterator(); it.hasNext(); ) { MimeHeader header = it.next(); String lcname = header.getName().toLowerCase(); if (!lcname.equals("content-type") && !lcname.equals("content-transfer-encoding")) { // FIXME: want to have the new body's old headers at the *end* of the resulting list, not at // the beginning newBody.addMimeHeader(header); it.remove(); } } return newBody; }
/* */ public void setHeader(String name, String value) /* */ { /* 239 */ boolean flag = false; /* */ /* 241 */ if ((name == null) || (name.equals(""))) { /* 242 */ throw new IllegalArgumentException("Illegal MimeHeader name"); /* */ } /* */ /* 246 */ for (int i = 0; i < this.headers.size(); ++i) { /* 247 */ MimeHeader mimeheader = (MimeHeader) this.headers.elementAt(i); /* */ /* 249 */ if (mimeheader.getName().equalsIgnoreCase(name)) { /* 250 */ if (!(flag)) { /* 251 */ this.headers.setElementAt(new MimeHeader(mimeheader.getName(), value), i); /* */ /* 254 */ flag = true; /* */ } else { /* 256 */ this.headers.removeElementAt(i--); /* */ } /* */ } /* */ } /* */ /* 261 */ if (!(flag)) /* 262 */ addHeader(name, value); /* */ }
/* */ public void addHeader(String name, String value) /* */ { /* 283 */ if ((name == null) || (name.equals(""))) { /* 284 */ throw new IllegalArgumentException("Illegal MimeHeader name"); /* */ } /* */ /* 288 */ int i = this.headers.size(); /* */ /* 290 */ for (int j = i - 1; j >= 0; --j) { /* 291 */ MimeHeader mimeheader = (MimeHeader) this.headers.elementAt(j); /* */ /* 293 */ if (mimeheader.getName().equalsIgnoreCase(name)) { /* 294 */ this.headers.insertElementAt(new MimeHeader(name, value), j + 1); /* */ /* 296 */ return; /* */ } /* */ } /* */ /* 300 */ this.headers.addElement(new MimeHeader(name, value)); /* */ }
/* */ public String[] getHeader(String name) /* */ { /* 198 */ Vector vector = new Vector(); /* */ /* 200 */ for (int i = 0; i < this.headers.size(); ++i) { /* 201 */ MimeHeader mimeheader = (MimeHeader) this.headers.elementAt(i); /* */ /* 203 */ if ((!(mimeheader.getName().equalsIgnoreCase(name))) || (mimeheader.getValue() == null)) /* */ continue; /* 205 */ vector.addElement(mimeheader.getValue()); /* */ } /* */ /* 209 */ if (vector.size() == 0) { /* 210 */ return null; /* */ } /* 212 */ String[] as = new String[vector.size()]; /* */ /* 214 */ vector.copyInto(as); /* */ /* 216 */ return as; /* */ }
SOAPMessage post(SOAPMessage message, URL endPoint) throws SOAPException { boolean isFailure = false; URL url = null; HttpURLConnection httpConnection = null; int responseCode = 0; try { if (endPoint.getProtocol().equals("https")) // if(!setHttps) initHttps(); // Process the URL JaxmURI uri = new JaxmURI(endPoint.toString()); String userInfo = uri.getUserinfo(); url = endPoint; if (dL > 0) d("uri: " + userInfo + " " + url + " " + uri); // TBD // Will deal with https later. if (!url.getProtocol().equalsIgnoreCase("http") && !url.getProtocol().equalsIgnoreCase("https")) { log.severe("SAAJ0052.p2p.protocol.mustbe.http.or.https"); throw new IllegalArgumentException( "Protocol " + url.getProtocol() + " not supported in URL " + url); } httpConnection = (HttpURLConnection) createConnection(url); httpConnection.setRequestMethod("POST"); httpConnection.setDoOutput(true); httpConnection.setDoInput(true); httpConnection.setUseCaches(false); httpConnection.setInstanceFollowRedirects(true); if (message.saveRequired()) message.saveChanges(); MimeHeaders headers = message.getMimeHeaders(); Iterator it = headers.getAllHeaders(); boolean hasAuth = false; // true if we find explicit Auth header while (it.hasNext()) { MimeHeader header = (MimeHeader) it.next(); String[] values = headers.getHeader(header.getName()); if (values.length == 1) httpConnection.setRequestProperty(header.getName(), header.getValue()); else { StringBuffer concat = new StringBuffer(); int i = 0; while (i < values.length) { if (i != 0) concat.append(','); concat.append(values[i]); i++; } httpConnection.setRequestProperty(header.getName(), concat.toString()); } if ("Authorization".equals(header.getName())) { hasAuth = true; log.fine("SAAJ0091.p2p.https.auth.in.POST.true"); } } if (!hasAuth && userInfo != null) { initAuthUserInfo(httpConnection, userInfo); } OutputStream out = httpConnection.getOutputStream(); message.writeTo(out); out.flush(); out.close(); httpConnection.connect(); try { responseCode = httpConnection.getResponseCode(); // let HTTP_INTERNAL_ERROR (500) through because it is used for SOAP faults if (responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR) { isFailure = true; } // else if (responseCode != HttpURLConnection.HTTP_OK) // else if (!(responseCode >= HttpURLConnection.HTTP_OK && responseCode < 207)) else if ((responseCode / 100) != 2) { log.log( Level.SEVERE, "SAAJ0008.p2p.bad.response", new String[] {httpConnection.getResponseMessage()}); throw new SOAPExceptionImpl( "Bad response: (" + responseCode + httpConnection.getResponseMessage()); } } catch (IOException e) { // on JDK1.3.1_01, we end up here, but then getResponseCode() succeeds! responseCode = httpConnection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR) { isFailure = true; } else { throw e; } } } catch (SOAPException ex) { throw ex; } catch (Exception ex) { log.severe("SAAJ0009.p2p.msg.send.failed"); throw new SOAPExceptionImpl("Message send failed", ex); } SOAPMessage response = null; if (responseCode == HttpURLConnection.HTTP_OK || isFailure) { try { MimeHeaders headers = new MimeHeaders(); String key, value; // Header field 0 is the status line so we skip it. int i = 1; while (true) { key = httpConnection.getHeaderFieldKey(i); value = httpConnection.getHeaderField(i); if (key == null && value == null) break; if (key != null) { StringTokenizer values = new StringTokenizer(value, ","); while (values.hasMoreTokens()) headers.addHeader(key, values.nextToken().trim()); } i++; } InputStream httpIn = (isFailure ? httpConnection.getErrorStream() : httpConnection.getInputStream()); byte[] bytes = readFully(httpIn); int length = httpConnection.getContentLength() == -1 ? bytes.length : httpConnection.getContentLength(); // If no reply message is returned, // content-Length header field value is expected to be zero. if (length == 0) { response = null; log.warning("SAAJ0014.p2p.content.zero"); } else { ByteInputStream in = new ByteInputStream(bytes, length); response = messageFactory.createMessage(headers, in); } httpIn.close(); httpConnection.disconnect(); } catch (SOAPException ex) { throw ex; } catch (Exception ex) { log.log(Level.SEVERE, "SAAJ0010.p2p.cannot.read.resp", ex); throw new SOAPExceptionImpl("Unable to read response: " + ex.getMessage()); } } return response; }