Example usage for java.lang IllegalArgumentException toString

List of usage examples for java.lang IllegalArgumentException toString

Introduction

In this page you can find the example usage for java.lang IllegalArgumentException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.snda.mymarket.providers.downloads.DownloadTask.java

/**
 * Send the request to the server, handling any I/O exceptions.
 *//*from w w  w. j a v  a  2s .c  om*/
private HttpResponse sendRequest(State state, HttpStack client, HttpGet request) throws StopRequest {
    try {
        return client.performRequest(request);
    } catch (IllegalArgumentException ex) {
        throw new StopRequest(Downloads.STATUS_HTTP_DATA_ERROR,
                "while trying to execute request: " + ex.toString(), ex);
    } catch (IOException ex) {
        logNetworkState();
        throw new StopRequest(getFinalStatusForHttpError(state),
                "while trying to execute request: " + ex.toString(), ex);
    }
}

From source file:org.apache.jmeter.protocol.http.sampler.WebServiceSampler.java

/**
 * Sample the URL using Apache SOAP driver. Implementation note for myself
 * and those that are curious. Current logic marks the end after the
 * response has been read. If read response is set to false, the buffered
 * reader will read, but do nothing with it. Essentially, the stream from
 * the server goes into the ether.//from   w w  w .  j  a va  2 s . c om
 */
@Override
public SampleResult sample() {
    SampleResult result = new SampleResult();
    result.setSuccessful(false); // Assume it will fail
    result.setResponseCode("000"); // ditto $NON-NLS-1$
    result.setSampleLabel(getName());
    try {
        result.setURL(this.getUrl());
        org.w3c.dom.Element rdoc = createDocument();
        if (rdoc == null) {
            throw new SOAPException("Could not create document", null);
        }
        // set the response defaults
        result.setDataEncoding(ENCODING);
        result.setContentType("text/xml"); // $NON-NLS-1$
        result.setDataType(SampleResult.TEXT);
        result.setSamplerData(fileContents);// WARNING - could be large

        Envelope msgEnv = Envelope.unmarshall(rdoc);
        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);
                }
            }
        }

        HeaderManager headerManager = this.getHeaderManager();
        Hashtable<String, String> reqHeaders = null;
        if (headerManager != null) {
            int size = headerManager.getHeaders().size();
            reqHeaders = new Hashtable<String, String>(size);
            for (int i = 0; i < size; i++) {
                Header header = headerManager.get(i);
                reqHeaders.put(header.getName(), header.getValue());
            }
        }
        spconn.setMaintainSession(getMaintainSession());
        spconn.send(this.getUrl(), this.getSoapAction(), reqHeaders, msgEnv, null, new SOAPContext());

        @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
        // the soap driver doesn't provide a
        // response code
    } catch (IllegalArgumentException exception) {
        String message = exception.getMessage();
        log.warn(message);
        result.setResponseMessage(message);
    } catch (SAXException exception) {
        log.warn(exception.toString());
        result.setResponseMessage(exception.getMessage());
    } catch (SOAPException exception) {
        log.warn(exception.toString());
        result.setResponseMessage(exception.getMessage());
    } catch (MalformedURLException exception) {
        String message = exception.getMessage();
        log.warn(message);
        result.setResponseMessage(message);
    } catch (IOException exception) {
        String message = exception.getMessage();
        log.warn(message);
        result.setResponseMessage(message);
    } catch (NoClassDefFoundError error) {
        log.error("Missing class: ", error);
        result.setResponseMessage(error.toString());
    } catch (Exception exception) {
        if ("javax.mail.MessagingException".equals(exception.getClass().getName())) {
            log.warn(exception.toString());
            result.setResponseMessage(exception.getMessage());
        } else {
            log.error("Problem processing the SOAP request", exception);
            result.setResponseMessage(exception.toString());
        }
    } finally {
        // Make sure the sample start time and sample end time are recorded
        // in order not to confuse the statistics calculation methods: if
        //  an error occurs and an exception is thrown it is possible that
        // the result.sampleStart() or result.sampleEnd() won't be called
        if (result.getStartTime() == 0) {
            result.sampleStart();
        }
        if (result.getEndTime() == 0) {
            result.sampleEnd();
        }
    }
    return result;
}

From source file:com.simplelife.seeds.android.utils.downloadprocess.DownloadThread.java

/**
 * Send the request to the server, handling any I/O exceptions.
 *///w ww  . ja  v  a2  s.  c  o  m
private HttpResponse sendRequest(State state, AndroidHttpClient client, HttpPost request) throws StopRequest {
    try {
        return client.execute(request);
    } catch (IllegalArgumentException ex) {
        throw new StopRequest(Downloads.STATUS_HTTP_DATA_ERROR,
                "while trying to execute request: " + ex.toString(), ex);
    } catch (IOException ex) {
        logNetworkState();
        throw new StopRequest(getFinalStatusForHttpError(state),
                "while trying to execute request: " + ex.toString(), ex);
    }
}

From source file:cn.keyshare.download.core.DownloadThread.java

/**
  * Send the request to the server, handling any I/O exceptions.
  *///from  www.  ja  v a2s.com
 private HttpResponse sendRequest(State state, AndroidHttpClient client, HttpGet request) throws StopRequest {
     try {
         return client.execute(request);
     } catch (IllegalArgumentException ex) {
         throw new StopRequest(Downloads.STATUS_HTTP_DATA_ERROR,
                 "while trying to execute request: " + ex.toString(), ex);
     } catch (IOException ex) {
         logNetworkState();
         throw new StopRequest(getFinalStatusForHttpError(state),
                 "while trying to execute request: " + ex.toString(), ex);
     }
 }

From source file:com.novell.ldap.SPMLConnection.java

public void modify(String dn, LDAPModification[] mods, LDAPConstraints consts) throws LDAPException {
    LDAPControl[] controls = consts != null ? consts.getControls() : null;

    ModifyRequest modreq = new ModifyRequest();

    DN dnVal = new DN(dn);

    RDN rdn = (RDN) dnVal.getRDNs().get(0);
    Identifier id = new Identifier();

    try {/*  ww  w .  ja  va 2 s  . c om*/
        id.setType(this.getIdentifierType(rdn.getType()));
    } catch (IllegalArgumentException e1) {
        throw new LDAPException("Could not determine type", 53, e1.toString(), e1);
    } catch (IllegalAccessException e1) {
        throw new LDAPException("Could not determine type", 53, e1.toString(), e1);
    }

    modreq.setIdentifier(id);

    id.setId(rdn.getValue());

    Modification mod = null;

    for (int i = 0, m = mods.length; i < m; i++) {
        mod = new Modification();
        mod.setName(mods[i].getAttribute().getName());
        ArrayList list = new ArrayList();
        Enumeration evals = mods[i].getAttribute().getStringValues();
        while (evals.hasMoreElements()) {
            list.add(evals.nextElement());
        }
        mod.setValue(list);

        int op = mods[i].getOp();
        switch (op) {
        case LDAPModification.ADD:
            mod.setOperation("add");
            break;
        case LDAPModification.REPLACE:
            mod.setOperation("replace");
            break;
        case LDAPModification.DELETE:
            mod.setOperation("delete");
            break;
        }

        modreq.addModification(mod);

    }

    try {
        ModifyResponse resp = (ModifyResponse) con.request(modreq);

        if (!resp.getResult().equals("urn:oasis:names:tc:SPML:1:0#success")) {
            throw new LDAPLocalException(resp.getErrorMessage(), 53);
        }
    } catch (SpmlException e) {
        throw new LDAPException(e.toString(), 53, e.toString());
    }
}

From source file:com.novell.ldap.SPMLConnection.java

public void add(LDAPEntry entry, LDAPConstraints cont) throws LDAPException {

    AddRequest add = new AddRequest();

    DN dn = new DN(entry.getDN());

    RDN rdn = (RDN) dn.getRDNs().get(0);
    Identifier id = new Identifier();

    try {//  ww  w. ja  va  2 s.  c  o m
        id.setType(this.getIdentifierType(rdn.getType()));
    } catch (IllegalArgumentException e1) {
        throw new LDAPException("Could not determine type", 53, e1.toString(), e1);
    } catch (IllegalAccessException e1) {
        throw new LDAPException("Could not determine type", 53, e1.toString(), e1);
    }

    id.setId(rdn.getValue());

    String objectClass = entry.getAttribute("objectClass").getStringValue();
    add.setObjectClass(objectClass);

    Iterator it = entry.getAttributeSet().iterator();

    HashMap map = new HashMap();

    while (it.hasNext()) {
        LDAPAttribute attrib = (LDAPAttribute) it.next();
        if (attrib.getName().toLowerCase().equals("objectclass")) {
            continue;
        }

        String[] vals = attrib.getStringValueArray();
        ArrayList list = new ArrayList();
        for (int i = 0, m = vals.length; i < m; i++) {
            list.add(vals[i]);
        }

        map.put(attrib.getName(), list);
    }

    add.setAttributes(map);
    add.setIdentifier(id);

    try {

        SpmlResponse resp = con.request(add);
        if (resp.getResult().equals("urn:oasis:names:tc:SPML:1:0#pending")) {
            String res = "";
            List attrs = resp.getOperationalAttributes();
            it = attrs.iterator();
            while (it.hasNext()) {
                Attribute attr = (Attribute) it.next();
                res += "[" + attr.getName() + "=" + attr.getValue() + "] ";
            }

            throw new LDAPLocalException(res, 0);

        } else if (!resp.getResult().equals("urn:oasis:names:tc:SPML:1:0#success")) {
            System.out.println("Response : " + resp.getResult());
            throw new LDAPLocalException(resp.getErrorMessage(), 53);
        }
    } catch (SpmlException e) {
        throw new LDAPException(e.toString(), 53, e.toString());
    }

}

From source file:com.novell.ldap.SPMLConnection.java

public LDAPSearchResults search(String base, int scope, String filter, String[] attrs, boolean typesOnly,
        LDAPSearchConstraints cons) throws LDAPException {
    LDAPControl[] controls = cons != null ? cons.getControls() : null;
    LDAPSearchRequest msg = new LDAPSearchRequest(base, scope, filter, attrs, 0, 0, 0, typesOnly, controls);

    SearchRequest req = new SearchRequest();
    if (base != null && base.trim().length() != 0) {
        //req.setSearchBase(base);

        DN dn = new DN(base);

        if (!base.toLowerCase().startsWith("ou") && !base.toLowerCase().startsWith("dc")
                && !base.toLowerCase().startsWith("o")) {
            if (scope == 0) {
                Identifier id = new Identifier();
                try {
                    id.setType(this.getIdentifierType(((RDN) dn.getRDNs().get(0)).getType()));
                } catch (IllegalArgumentException e1) {
                    throw new LDAPException("Could not determine type", 53, e1.toString(), e1);
                } catch (IllegalAccessException e1) {
                    throw new LDAPException("Could not determine type", 53, e1.toString(), e1);
                }/*from  w  w  w.  j a v a2 s  .c o  m*/
                id.setId(dn.explodeDN(true)[0]);

                req.setSearchBase(id);
            } else {
                req.setSearchBase(base);
            }
        } else if (scope == 0) {

            return new SPMLSearchResults(new ArrayList());
        }
    }

    if (filter != null && !filter.trim().equalsIgnoreCase("objectClass=*")
            && !filter.trim().equalsIgnoreCase("(objectClass=*)")) {
        RfcFilter rfcFilter = new RfcFilter(filter.trim());
        FilterTerm filterPart = new FilterTerm();
        System.out.println("part : " + filterPart.getOperation());
        this.stringFilter(rfcFilter.getFilterIterator(), filterPart);
        req.addFilterTerm(filterPart);
    }

    for (int i = 0, m = attrs.length; i < m; i++) {
        req.addAttribute(attrs[i]);
    }

    SearchResponse res;
    try {
        res = con.searchRequest(req);
    } catch (SpmlException e) {
        throw new LDAPException("Could not search", 53, e.toString());
    }

    return new SPMLSearchResults(res.getResults() != null ? res.getResults() : new ArrayList());

}

From source file:it.cnr.isti.thematrix.scripting.modules.MatrixFileInput.java

/**
 * Get next row and parse its fields into Symbol values. Should some way support caching a set of rows.
 * //from   w w w .j  a va  2  s.  c  o m
 * FIXME Actual parsing of the data fields should be in a different class and not inside here.
 */
@Override
public void next() {
    int i = 0;

    // these vars are here just for reporting
    String report_val = null;
    int report_i = -2;

    while (hasMore())
        try {
            List<String> columns = inputCSV.next();
            List<Symbol<?>> attrs = this.attributes();
            int nHead = attrs.size();
            for (i = 0; i < nHead; i++) {
                Symbol<?> s = attrs.get(i);
                String val = columns.get(i);
                report_val = val;
                report_i = i; // for reporting
                if (val.isEmpty()) {
                    s.setValue(null);
                } else
                    switch (s.type) {
                    case INT: {
                        s.setValue(Integer.parseInt(val));
                        break;
                    }
                    case FLOAT: {
                        s.setValue(Float.parseFloat(val));
                        break;
                    }
                    case BOOLEAN: {
                        try {
                            int parsedIntValue = Integer.parseInt(val);
                            if (parsedIntValue == 0)
                                s.setValue(false);
                            else
                                s.setValue(true);
                        } catch (NumberFormatException ex) {
                            s.setValue(Boolean.parseBoolean(val));
                        }
                        break;
                    }
                    case STRING: {
                        s.setValue(val);
                        break;
                    }
                    case DATE: {
                        s.setValue(DateUtil.parse(val));
                        break;
                    }
                    }
            }
            return; // for ended without any exception
        }
        /***
         * here we should catch any parsing exception and report them to the user in useful way; we
         * interact with the input routine so that the whole row is marked as bad.
         */
        catch (IllegalArgumentException e) {
            // catches NumberFormatE from int/float as well as exceptions form DateUtil
            LogST.logP(1, "MatrixFileInput : discarding input line, caught exception while parsing field " + i
                    + " " + attributes().get(i).toString());
            //            LogST.logException(e); // only in logs!
            LogST.logP(2, "Exception caught: " + e.toString());

            // currently we mostly do the same for temporary and permanent files
            if (fileIsTemporary == false)
                LogST.errorParsing(this.name, this.inputFilename, report_val, inputCSV.getRowCursor() + "",
                        i + " = " + this.inputSchema.attributes().get(i).name,
                        attributes().get(i).type.toString());
            else
                LogST.errorParsing(this.name, "temporary file"/*this.inputFilename*/, report_val,
                        inputCSV.getRowCursor() + "", i + " = " + this.inputSchema.attributes().get(i).name,
                        attributes().get(i).type.toString());

            // this will re-execute the while body, discarding the current line
            continue;
        }

    /**
     * if we get out of the while it means either next() was called on exhausted input, or at least one input line
     * was discarded because of parsing errors; 
     * 
     * FIXME should throw a specific exception!
     */
    LogST.logP(0, "MatrixFileInput : empty input line, caught exception while parsing ");
}

From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java

/**
 * This is used for the arrow of a directed and for one of the
 * arrows for non-directed edges//from w w  w. jav a2s.  co m
 * Get a transform to place the arrow shape on the passed edge at the
 * point where it intersects the passed shape
 * @param edgeShape
 * @param vertexShape
 * @return
 */
public AffineTransform getArrowTransform(Line2D edgeShape, Shape vertexShape) {
    float dx = (float) (edgeShape.getX1() - edgeShape.getX2());
    float dy = (float) (edgeShape.getY1() - edgeShape.getY2());
    // iterate over the line until the edge shape will place the
    // arrowhead closer than 'arrowGap' to the vertex shape boundary
    while ((dx * dx + dy * dy) > arrow_placement_tolerance) {
        try {
            edgeShape = getLastOutsideSegment(edgeShape, vertexShape);
        } catch (IllegalArgumentException e) {
            System.err.println(e.toString());
            return null;
        }
        dx = (float) (edgeShape.getX1() - edgeShape.getX2());
        dy = (float) (edgeShape.getY1() - edgeShape.getY2());
    }
    double atheta = Math.atan2(dx, dy) + Math.PI / 2;
    AffineTransform at = AffineTransform.getTranslateInstance(edgeShape.getX1(), edgeShape.getY1());
    at.rotate(-atheta);
    return at;
}

From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java

/**
 * This is used for the reverse-arrow of a non-directed edge
 * get a transform to place the arrow shape on the passed edge at the
 * point where it intersects the passed shape
 * @param edgeShape//from   w w  w .  jav  a2  s. co  m
 * @param vertexShape
 * @return
 */
protected AffineTransform getReverseArrowTransform(Line2D edgeShape, Shape vertexShape) {
    float dx = (float) (edgeShape.getX1() - edgeShape.getX2());
    float dy = (float) (edgeShape.getY1() - edgeShape.getY2());
    // iterate over the line until the edge shape will place the
    // arrowhead closer than 'arrowGap' to the vertex shape boundary
    while ((dx * dx + dy * dy) > arrow_placement_tolerance) {
        try {
            edgeShape = getFirstOutsideSegment(edgeShape, vertexShape);
        } catch (IllegalArgumentException e) {
            System.err.println(e.toString());
            return null;
        }
        dx = (float) (edgeShape.getX1() - edgeShape.getX2());
        dy = (float) (edgeShape.getY1() - edgeShape.getY2());
    }
    // calculate the angle for the arrowhead
    double atheta = Math.atan2(dx, dy) - Math.PI / 2;
    AffineTransform at = AffineTransform.getTranslateInstance(edgeShape.getX1(), edgeShape.getY1());
    at.rotate(-atheta);
    return at;
}