List of usage examples for org.apache.commons.httpclient ProtocolException ProtocolException
public ProtocolException(String paramString)
From source file:com.tasktop.c2c.server.ssh.server.commands.AbstractInteractiveProxyCommand.java
private void processData(MultiplexingInputStream input, PacketType packetType, int dataSize) throws IOException, CommandException { if (dataSize < 1) { throw new IllegalArgumentException(); }//w w w . java 2 s .c o m OutputStream target = null; switch (packetType) { case STDOUT: // stdout target = out; break; case STDERR: // stderr target = err; break; case EXIT_CODE: // exit code break; default: throw new ProtocolException("Expected indicator but got " + packetType); } if (target != null) { int bytesToRead = dataSize; byte[] buffer = new byte[Math.min(bufferSize, bytesToRead)]; int bytesRead = 0; while (bytesRead < bytesToRead) { int read = input.read(buffer, 0, Math.min(buffer.length, bytesToRead - bytesRead)); if (read < 1) { throw new IOException("Unexpected EOF"); } target.write(buffer, 0, read); bytesRead += read; } target.flush(); } else { int exitCode = input.readExitCode(); throw new CommandException(exitCode); } }
From source file:org.eclipse.ecr.core.storage.sql.net.MapperClient.java
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String methodName = method.getName(); // special cases if (Mapper.GET_IDENTIFICATION.equals(methodName)) { if (identification != null) { return identification; }/*from ww w .jav a2 s . c om*/ // else fall through (send to remote) } else if ("getTableSize".equals(methodName)) { return Integer.valueOf(getTableSize((String) args[0])); } else if ("createDatabase".equals(methodName)) { createDatabase(); return null; } // copying the transaction id implementation object that may not be // known by the class loader on server side. if (args != null) { for (int i = 0; i < args.length; i++) { if (args[i] instanceof Xid) { args[i] = new XidImpl((Xid) args[i]); } } } // send through network // this is decoded by NetServlet String postUrl = url; if (identification != null) { postUrl += '?' + MapperServlet.PARAM_RID + '=' + identification.repositoryId + '&' + MapperServlet.PARAM_MID + '=' + identification.mapperId; } else if (repositoryId != null) { postUrl += '?' + MapperServlet.PARAM_RID + '=' + repositoryId; } PostMethod m = new PostMethod(postUrl); m.setRequestHeader(httpPrincipalHeader); try { ObjectWriterRequestEntity writer = new ObjectWriterRequestEntity(); writer.add(methodName, args); m.setRequestEntity(writer); int status = httpClient.executeMethod(m); if (status != HttpStatus.SC_OK) { throw new ProtocolException(String.valueOf(status)); } String cs = m.getResponseCharSet(); if (cs != null && !cs.equals("ISO-8859-1")) { throw new RuntimeException("Bad encoding: " + cs); } Object res = new ObjectInputStream(m.getResponseBodyAsStream()).readObject(); if (res instanceof Throwable) { Throwable t = (Throwable) res; throw new StorageException("Remote exception: " + t, t); } else { return res; } } catch (StorageException e) { throw e; } catch (Exception e) { throw new StorageException(e); } finally { m.releaseConnection(); } }
From source file:org.mule.transport.http.RequestLine.java
public static RequestLine parseLine(final String l) throws HttpException { String method;/*from ww w . j a va 2 s . c om*/ String uri; String protocol; try { if (l == null) { throw new ProtocolException(HttpMessages.requestLineIsMalformed(l).getMessage()); } StringTokenizer st = new StringTokenizer(l, " "); method = st.nextToken(); uri = st.nextToken(); protocol = st.nextToken(); } catch (NoSuchElementException e) { throw new ProtocolException(HttpMessages.requestLineIsMalformed(l).getMessage()); } return new RequestLine(method, uri, protocol); }