List of usage examples for org.apache.commons.httpclient URI getEscapedURI
public String getEscapedURI()
From source file:org.glite.slcs.shibclient.ShibbolethClient.java
/** * Gets the Shibboleth session needed afterward. * <p>/* w w w. ja va2s.c om*/ * Supports Shib1 (SAML1) WAFY and direct redirection to IdP, SAML2 direct * redirection to IdP, and SAML2 DS * * @param entryURL * @param idp * @return * @throws URIException * @throws HttpException * @throws IOException * @throws RemoteException */ private URI processSPEntry(String entryURL, IdentityProvider idp) throws URIException, HttpException, IOException, RemoteException, ServiceException { GetMethod getSPEntryMethod = new GetMethod(entryURL); LOG.info("GET SPEntryMethod: " + getSPEntryMethod.getURI()); // get only the first redirect, if any getSPEntryMethod.setFollowRedirects(false); int spEntryStatus = executeMethod(getSPEntryMethod); String spEntryStatusLine = getSPEntryMethod.getStatusLine().toString(); LOG.debug("spEntryStatusLine=" + spEntryStatusLine); URI loginResponseURI = getSPEntryMethod.getURI(); LOG.debug("loginResponseURI=" + loginResponseURI); if (spEntryStatus == 302) { Header locationHeader = getSPEntryMethod.getResponseHeader("Location"); String location = locationHeader.getValue(); LOG.debug("Redirect location=" + location); loginResponseURI = new URI(location, true); } LOG.trace("getSPEntryMethod.releaseConnection()"); getSPEntryMethod.releaseConnection(); String loginResponseURL = loginResponseURI.getEscapedURI(); LOG.debug("loginResponseURL=" + loginResponseURL); if (spEntryStatus == 200 && loginResponseURL.startsWith(entryURL)) { LOG.debug("SP entry response is the same, already authenticated?"); return loginResponseURI; } if (spEntryStatus != 302) { throw new RemoteException( "Unexpected SP response: " + spEntryStatusLine + " " + loginResponseURI + " for " + entryURL); } // checks if URL is Shib1 (SAML1) 'shire=' and 'target=' params (also // WAYF) if (loginResponseURL.indexOf("shire=") != -1 && loginResponseURL.indexOf("target=") != -1) { LOG.debug("loginResponseURL is Shib1 (SAML1, WAYF)"); return loginResponseURI; } // checks if URL is SAML2 'SAMLRequest=' (direct redirection to IdP) // params else if (loginResponseURL.indexOf("SAMLRequest=") != -1) { LOG.debug("loginResponseURL is SAML2 redirection to IdP"); return loginResponseURI; } // checks if URL is SAML2 'entityID=' and 'return=' (SAMLDS) else if (loginResponseURL.indexOf("entityID=") != -1 && loginResponseURL.indexOf("return=") != -1) { LOG.debug("loginResponseURL is SAML2 DiscoveryService"); // redirect to return url with entityID of the IdP loginResponseURI = processSPSAML2DS(loginResponseURI, idp); return loginResponseURI; } else { String error = "SP response URL is not Shib1, nor SAML2 protocol: " + loginResponseURL; LOG.error(error); throw new RemoteException(error); } }
From source file:org.glite.slcs.shibclient.ShibbolethClient.java
/** * @param idp// w ww . j a v a 2s .c o m * @param query * @throws URIException * @throws HttpException * @throws IOException * @throws AuthException * @throws RemoteException * @throws ServiceException */ private URI processIdPSSO(IdentityProvider idp, URI spResponseURI) throws URIException, HttpException, IOException, AuthException, RemoteException, ServiceException { String idpSSOURL = idp.getUrl(); LOG.debug("IdP SSO URL: " + idpSSOURL); String spResponseURL = spResponseURI.getEscapedURI(); LOG.debug("spResponseURL=" + spResponseURL); // check if the spResponseURL is not already the IdP SSO url if (spResponseURL.startsWith(idpSSOURL)) { idpSSOURL = spResponseURL; } else { // if not, build it // BUG FIX: Shib SP 2.0 send the ?service=... in the query String query = spResponseURI.getEscapedQuery(); LOG.debug("IdP SSO Query: " + query); if (query != null) { if (query.startsWith("service=")) { int i = query.indexOf("shire"); if (i > 0) { query = query.substring(i); LOG.debug( "IdP SSO Query contains the 'service=...' part, cutting up to 'shire=': " + query); } else { LOG.error( "IdP SSO Query contains the 'service=' parameter, but not the 'shire=' parameter: " + query); throw new RemoteException( "IdP SSO Query contains the 'service=' parameter, but not the 'shire=' parameter: " + query); } } // getIdpSSOMethod.setQueryString(query); idpSSOURL += "?" + query; } LOG.debug("IdP SSO URL (with query): " + idpSSOURL); } // create HttpMethod GetMethod getIdpSSOMethod = new GetMethod(idpSSOURL); URI idpSSOURI = getIdpSSOMethod.getURI(); // set credential for basic or ntlm int authType = idp.getAuthType(); LOG.debug("IdP authType: " + idp.getAuthTypeName()); if (authType == IdentityProvider.SSO_AUTHTYPE_BASIC || authType == IdentityProvider.SSO_AUTHTYPE_NTLM) { // enable BASIC or NTLM authN AuthScope scope = new AuthScope(idpSSOURI.getHost(), idpSSOURI.getPort(), idp.getAuthRealm()); LOG.info("Enable " + idp.getAuthTypeName() + " authentication: " + credentials_ + ", scope: " + scope); httpClient_.getState().setCredentials(scope, credentials_); getIdpSSOMethod.setDoAuthentication(true); } // execute the method LOG.info("GET IdpSSOMethod: " + idpSSOURI); int idpSSOResponseStatus = executeMethod(getIdpSSOMethod); String idpSSOResponseStatusLine = getIdpSSOMethod.getStatusLine().toString(); LOG.debug(idpSSOResponseStatusLine); URI idpSSOResponseURI = getIdpSSOMethod.getURI(); LOG.debug("idpSSOResponseURI=" + idpSSOResponseURI); String idpSSOResponseQuery = idpSSOResponseURI.getEscapedQuery(); LOG.debug("idpSSOResponseQuery=" + idpSSOResponseQuery); // XXX dumpHttpClientCookies(); LOG.debug("idpSSOResponseStatus=" + idpSSOResponseStatus); // BASIC or NTLM response handling if (idp.getAuthType() == IdentityProvider.SSO_AUTHTYPE_BASIC || idp.getAuthType() == IdentityProvider.SSO_AUTHTYPE_NTLM) { // !200 and same URL as before: if BASIC or NTLM failed on IdP LOG.debug("idpSSOURI=" + idpSSOURI); LOG.debug("idpSSOResponseURI=" + idpSSOResponseURI); if (idpSSOResponseStatus != 200 && idpSSOResponseURI.equals(idpSSOURI)) { LOG.trace("getIdpSSOMethod.releaseConnection()"); getIdpSSOMethod.releaseConnection(); LOG.error("BASIC or NTLM authentication was required for " + idpSSOURL); throw new AuthException( idp.getAuthTypeName() + " authentication failed: " + idpSSOResponseStatusLine + " URL: " + idpSSOResponseURI + " Credentials: " + this.credentials_); } else { // SAML/Artifact: idpSSOResponseURI is already SP login and the // XML <SLCSLoginResponse> is already there // XXX: resend to same IdP SSO page once again LOG.info("IdP BASIC or NTLM authN: resend again to the same IdP SSO URI: " + idpSSOURL); idpSSOResponseURI = new URI(idpSSOURL, false); } } // CAS sends 200 + Cookies and the login form directly else if (idpSSOResponseStatus == 200 && (idp.getAuthType() == IdentityProvider.SSO_AUTHTYPE_CAS || idp.getAuthType() == IdentityProvider.SSO_AUTHTYPE_FORM)) { LOG.debug("Process " + idp.getAuthTypeName() + " login form..."); // process CAS login form InputStream idpLoginForm = getIdpSSOMethod.getResponseBodyAsStream(); LOG.debug("idpSSOURI Query=" + idpSSOURI.getQuery()); idpSSOResponseURI = processIdPLoginForm(idp, idpSSOResponseURI, idpSSOURI.getQuery(), idpLoginForm); LOG.debug(idp.getAuthTypeName() + " idpSSOResponseURI=" + idpSSOResponseURI); } // FIXME: ETHZ use a new PubCookie // PUBCOOKIE sends 200 + onload form with hidden fields to post else if (idpSSOResponseStatus == 200 && idp.getAuthType() == IdentityProvider.SSO_AUTHTYPE_PUBCOOKIE) { // parse <form> and extract hidden fields, then post PostMethod postPubcookieFormMethod = null; InputStream pubcookieFormStream = getIdpSSOMethod.getResponseBodyAsStream(); Source source = new Source(pubcookieFormStream); List<Element> forms = source.findAllElements(Tag.FORM); for (Element form : forms) { String formAction = form.getAttributeValue("ACTION"); LOG.debug("PubCookie form action=" + formAction); if (!idp.getAuthUrl().equalsIgnoreCase(formAction)) { // TODO: ERROR throw new RemoteException( "form action: " + formAction + " doesn't match IdP authN url: " + idp.getAuthUrl()); } // create PubCookie POST postPubcookieFormMethod = new PostMethod(formAction); // add all HIDDEN fields to POST List<FormControl> formControls = form.findFormControls(); for (FormControl control : formControls) { FormControlType type = control.getFormControlType(); if (type.equals(FormControlType.HIDDEN)) { String name = control.getName(); Collection<String> values = control.getValues(); for (String value : values) { LOG.debug("add hidden: " + name + "=" + value); // add all hidden fields postPubcookieFormMethod.addParameter(name, value); } } } } // for all forms LOG.trace("getIdpSSOMethod.releaseConnection()"); getIdpSSOMethod.releaseConnection(); if (postPubcookieFormMethod == null) { // ERROR LOG.error("PubCookie form not found"); throw new RemoteException("PubCookie form not found"); } // LOG.debug("POST " + postPubcookieFormMethod.getURI()); int postPubcookieFormStatus = executeMethod(postPubcookieFormMethod); LOG.debug(postPubcookieFormMethod.getStatusLine()); // XXX dumpHttpClientCookies(); // process pubcookie login form InputStream loginFormStream = postPubcookieFormMethod.getResponseBodyAsStream(); idpSSOResponseURI = processIdPLoginForm(idp, idpSSOResponseURI, idpSSOURI.getQuery(), loginFormStream); LOG.debug("Pubcookie idpSSOResponseURI=" + idpSSOResponseURI); LOG.trace("postPubcookieFormMethod.releaseConnection()"); postPubcookieFormMethod.releaseConnection(); } else { // error handling InputStream htmlStream = getIdpSSOMethod.getResponseBodyAsStream(); String htmlBody = inputStreamToString(htmlStream); LOG.error("Unexpected IdP SSO reponse: URL: " + idpSSOResponseURI + " Status: " + idpSSOResponseStatusLine + " AuthType: " + idp.getAuthTypeName() + " HTML:\n" + htmlBody); LOG.debug("getIdpSSOMethod.releaseConnection()"); getIdpSSOMethod.releaseConnection(); throw new RemoteException("Unexprected IdP SSO reponse: URL: " + idpSSOResponseURI + " Status: " + idpSSOResponseStatusLine + ". Please see the log file."); } LOG.debug("getIdpSSOMethod.releaseConnection()"); getIdpSSOMethod.releaseConnection(); return idpSSOResponseURI; }
From source file:org.glite.slcs.shibclient.ShibbolethClient.java
/** * Parses and processes Pubcookie or CAS login form. * // ww w . j a v a2 s. c o m * @param idp * @param htmlForm * @throws IOException * @throws RemoteException * @throws ServiceException * @throws AuthException */ private URI processIdPLoginForm(IdentityProvider idp, URI ssoLoginURI, String ssoQuery, InputStream htmlForm) throws IOException, RemoteException, ServiceException, AuthException { LOG.info("Parse and process " + idp.getAuthTypeName() + " login form: " + ssoLoginURI); boolean formFound = false; URI idpLoginFormResponseURI = null; // Parse the FORM with Jericho HTML Parser Source source = new Source(htmlForm); List<Element> forms = source.findAllElements(Tag.FORM); for (Element form : forms) { String formName = form.getAttributeValue("NAME"); // BUG FIX: UniL use a CAS login form with NO NAME defined. // first try with the form ID as NAME, otherwise use an empty name. // the metadata should also define an empty name for this particular // form. LOG.debug("form name= " + formName); if (formName == null) { LOG.warn("form have no NAME, try form ID..."); String formId = form.getAttributeValue("ID"); if (formId == null) { LOG.warn("form have no NAME and no ID, using empty name..."); formName = ""; } else { formName = formId; } } if (formName.equals(idp.getAuthFormName())) { formFound = true; String formAction = form.getAttributeValue("ACTION"); LOG.debug("form action=" + formAction); if (formAction == null || formAction.equals("")) { // no form action to POST, use default from metadata formAction = ssoLoginURI.getEscapedURI(); LOG.info("default form action=" + formAction); } else { URI formActionURI = new URI(formAction, false); if (formActionURI.isRelativeURI()) { // action URL is not absolute like: // http://localhost/cas/login?... formActionURI = new URI(ssoLoginURI, formActionURI.getPathQuery(), true); } formAction = formActionURI.getEscapedURI(); LOG.info("corrected form action=" + formAction); } String formMethod = form.getAttributeValue("METHOD"); LOG.debug("form name=" + formName + " action=" + formAction + " method=" + formMethod); if (!formAction.equals("") && formMethod.equalsIgnoreCase("POST")) { PostMethod postLoginFormMethod = new PostMethod(formAction); // add all HIDDEN fields to POST List<FormControl> formControls = form.findFormControls(); for (FormControl control : formControls) { FormControlType type = control.getFormControlType(); if (type.equals(FormControlType.HIDDEN)) { String name = control.getName(); Collection<String> values = control.getValues(); for (String value : values) { LOG.debug("add hidden: " + name + "=" + value); // add all hidden fields postLoginFormMethod.addParameter(name, value); } } } // add username field postLoginFormMethod.addParameter(idp.getAuthFormUsername(), this.credentials_.getUserName()); // add the PASSWORD field postLoginFormMethod.addParameter(idp.getAuthFormPassword(), this.credentials_.getPassword()); // execute the login POST LOG.info("POST LoginFormMethod: " + postLoginFormMethod.getURI()); int formLoginResponseStatus = executeMethod(postLoginFormMethod); LOG.debug(postLoginFormMethod.getStatusLine()); // XXX dumpHttpClientCookies(); // CAS, or FORM can, send a 302 + Location header back if (formLoginResponseStatus == 302 && (idp.getAuthType() == IdentityProvider.SSO_AUTHTYPE_CAS || idp.getAuthType() == IdentityProvider.SSO_AUTHTYPE_FORM)) { LOG.debug("Process " + idp.getAuthTypeName() + " redirect response (302 + Location header)..."); Header location = postLoginFormMethod.getResponseHeader("Location"); if (location != null) { String locationURL = location.getValue(); LOG.debug("302 Location: " + locationURL); // CAS: if location path (/cas/login) is not the IdP // 1.3 // SSO path (/shibboleth-idp/SSO) or the IdP 2.X // /Authn/RemoteUser // handler, then it's a wrong login URI locationURI = new URI(locationURL, false); String locationPath = locationURI.getPath(); String idpSSOURL = idp.getUrl(); URI idpSSOURI = new URI(idpSSOURL, false); String idpSSOPath = idpSSOURI.getPath(); if (LOG.isDebugEnabled()) { LOG.debug("location path: " + locationPath); LOG.debug("location is the /Authn/RemoteUser hanlder? " + locationPath.endsWith("/Authn/RemoteUser")); LOG.debug("IdP SSO path: " + idpSSOPath); } if (!locationPath.equals(idpSSOPath) && !locationPath.endsWith("/Authn/RemoteUser")) { LOG.error("Redirect response is not the SSO (" + idpSSOURL + ") or the /Authn/RemoteUser handler: " + locationURL); throw new AuthException( idp.getAuthTypeName() + " Authentication failed: " + this.credentials_); } idpLoginFormResponseURI = new URI(locationURL, false); LOG.debug("(" + idp.getAuthTypeName() + ": 302 + Location) idpLoginFormReponseURI= " + idpLoginFormResponseURI); } else { LOG.error(idp.getAuthTypeName() + ": Status 302 but no redirect Location header"); throw new AuthException( idp.getAuthTypeName() + " Authentication failed: " + this.credentials_); } } // IdP 2.1 FORM authN send 200 and directly the SAMLResponse // form else if (formLoginResponseStatus == 200 && idp.getAuthType() == IdentityProvider.SSO_AUTHTYPE_FORM) { // BUG FIX: check for Browser/POST hidden form element // SAMLResponse for valid authentication LOG.debug("check for SAMLResponse hidden element"); boolean samlResponseFound = false; InputStream authnLoginResponse = postLoginFormMethod.getResponseBodyAsStream(); Source authnSource = new Source(authnLoginResponse); List<Element> browserPOSTForms = authnSource.findAllElements(Tag.FORM); for (Element browserPOSTForm : browserPOSTForms) { List<FormControl> browserPOSTFormControls = browserPOSTForm.findFormControls(); for (FormControl control : browserPOSTFormControls) { FormControlType type = control.getFormControlType(); if (type.equals(FormControlType.HIDDEN)) { String name = control.getName(); if (name.equals("SAMLResponse")) { LOG.debug("Hidden element found: " + control.getName()); samlResponseFound = true; } } } } if (!samlResponseFound) { LOG.error( idp.getAuthTypeName() + ": no Browser/POST SAMLResponse hidden element found"); throw new AuthException( idp.getAuthTypeName() + " Authentication failed: " + this.credentials_); } LOG.debug("Process FORM (200 + full Browser/POST profile) response..."); idpLoginFormResponseURI = new URI(idp.getUrl(), false); // re-set the original SSO query params idpLoginFormResponseURI.setQuery(ssoQuery); LOG.debug("(FORM: 200 + Browser/POST) idpLoginFormReponseURI= " + idpLoginFormResponseURI); } // Pubcookie send 200 + fucking HTML form relay with hidden // fields!!! // <form method=post // action="https://aai-login.ethz.ch/PubCookie.reply" // name=relay> // then reply a redirect 302 + Location header else if (formLoginResponseStatus == 200 && idp.getAuthType() == IdentityProvider.SSO_AUTHTYPE_PUBCOOKIE) { LOG.debug("Process Pubcookie (200 + relay FORM) response..."); InputStream pubcookieLoginResponse = postLoginFormMethod.getResponseBodyAsStream(); Source pubcookieSource = new Source(pubcookieLoginResponse); PostMethod postPubcookieRelayMethod = null; List<Element> relayForms = pubcookieSource.findAllElements(Tag.FORM); for (Element relayForm : relayForms) { String relayFormAction = relayForm.getAttributeValue("ACTION"); LOG.debug("Pubcookie relay form action= " + relayFormAction); if (relayFormAction == null) { LOG.error("Pubcookie relay form action not found."); throw new RemoteException("Pubcookie relay form action not found"); } // create PubCookie relay POST postPubcookieRelayMethod = new PostMethod(relayFormAction); // add all HIDDEN fields to POST List<FormControl> relayFormControls = relayForm.findFormControls(); for (FormControl control : relayFormControls) { FormControlType type = control.getFormControlType(); if (type.equals(FormControlType.HIDDEN)) { String name = control.getName(); Collection<String> values = control.getValues(); for (String value : values) { LOG.debug("add hidden: " + name + "=" + value); // add all hidden fields postPubcookieRelayMethod.addParameter(name, value); } } } // add hidden fields } // for all relay forms if (postPubcookieRelayMethod != null) { LOG.debug("POST postPubcookieRelayMethod: " + postPubcookieRelayMethod.getURI()); int pubcookieRelayStatus = executeMethod(postPubcookieRelayMethod); LOG.debug(postPubcookieRelayMethod.getStatusLine()); Header location = postPubcookieRelayMethod.getResponseHeader("Location"); LOG.debug("postPubcookieRelayMethod.releaseConnection()"); postPubcookieRelayMethod.releaseConnection(); if (location != null) { String locationURL = location.getValue(); LOG.debug("302 Location: " + locationURL); // parse Location idpLoginFormResponseURI = new URI(locationURL, false); LOG.debug("(PubCookie: 302 + Location header) idpLoginFormReponseURI= " + idpLoginFormResponseURI); } else { LOG.error("Pubcookie relay response 302 + Location header not found"); throw new AuthException( idp.getAuthTypeName() + " Authentication failed: " + this.credentials_); } } else { LOG.error("Pubcookie relay form not found"); throw new AuthException( idp.getAuthTypeName() + " Authentication failed: " + this.credentials_); } // XXX dumpHttpClientCookies(); } else { LOG.error("Unexpected response status: " + formLoginResponseStatus + " AuthType:" + idp.getAuthTypeName()); throw new AuthException( idp.getAuthTypeName() + " Authentication failed: " + this.credentials_); } LOG.debug("POSTLoginFormMethod.releaseConnection()"); postLoginFormMethod.releaseConnection(); } // end if form action is set and method is POST } // end if form name match metadata } // end for all forms if (!formFound) { LOG.error("FORM name=" + idp.getAuthFormName() + " not found"); throw new ServiceException("FORM name=" + idp.getAuthFormName() + " not found"); } return idpLoginFormResponseURI; }
From source file:org.silverpeas.openoffice.windows.FileWebDavAccessManager.java
/** * Push back file into remote location using webdav. * * @param tmpFilePath full path of local temp file * @param url remote url/*from w w w . ja v a 2s .c o m*/ * @throws HttpException * @throws IOException */ public void pushFile(String tmpFilePath, String url) throws HttpException, IOException { URI uri = getURI(url); WebdavManager webdav = new WebdavManager(uri.getHost(), userName, new String(password)); logger.log(Level.INFO, "{0}{1}{2}", new Object[] { MessageUtil.getMessage("info.webdav.put"), ' ', tmpFilePath }); webdav.putFile(uri, tmpFilePath, lockToken); logger.log(Level.INFO, "{0}{1}{2}", new Object[] { MessageUtil.getMessage("info.webdav.unlocking"), ' ', uri.getEscapedURI() }); // Let's unlock the file webdav.unlockFile(uri, lockToken); // delete temp file File file = new File(tmpFilePath); file.delete(); file.getParentFile().delete(); logger.log(Level.INFO, MessageUtil.getMessage("info.file.deleted")); logger.log(Level.INFO, MessageUtil.getMessage("info.ok")); }
From source file:org.zaproxy.zap.extension.ascanrules.TestSQLInjection.java
private boolean checkUnionErrors(RDBMS rdbms, HttpMessage msg, String response, URI uri, String parameter, String originalParam, String attack) { for (Pattern errorPattern : rdbms.getUnionErrorPatterns()) { if (isStop()) { return false; }//from www . ja v a 2s. com // if the "error message" occurs in the result of sending the modified query, but did // NOT occur in the original result of the original query // then we may may have a SQL Injection vulnerability String sqlUnionBodyUnstripped = msg.getResponseBody().toString(); String sqlUnionBodyStripped = stripOffOriginalAndAttackParam(sqlUnionBodyUnstripped, originalParam, attack); Matcher matcherOrig = errorPattern.matcher(response); Matcher matcherSQLUnion = errorPattern.matcher(sqlUnionBodyStripped); boolean patternInOrig = matcherOrig.find(); boolean patternInSQLUnion = matcherSQLUnion.find(); // if (! matchBodyPattern(getBaseMsg(), errorPattern, null) && matchBodyPattern(msg, // errorPattern, sb)) { if (!patternInOrig && patternInSQLUnion) { // Likely a UNION Based SQL Injection (by error message). Raise it String extraInfo = Constant.messages.getString(MESSAGE_PREFIX + "alert.unionbased.extrainfo", rdbms.getName(), errorPattern.toString()); bingo(Alert.RISK_HIGH, Alert.CONFIDENCE_MEDIUM, getName() + " - " + rdbms.getName(), getDescription(), uri.getEscapedURI(), parameter, attack, extraInfo, getSolution(), matcherSQLUnion.group(), msg); // log it, as the RDBMS may be useful to know later (in subsequent checks, when we // need to determine RDBMS specific behaviour, for instance) getKb().add(uri, "sql/" + rdbms.getName(), Boolean.TRUE); return true; } } return false; }
From source file:ru.org.linux.util.LorURI.java
/** * url ? ?\//w w w . ja va 2 s . c o m * @param messageDao ? ? * @param secure https * @return url ? ?? ? * @throws MessageNotFoundException ? ?? * @throws BadGroupException ? * @throws URIException ? url */ public String formatJump(TopicDao messageDao, boolean secure) throws MessageNotFoundException, URIException { if (messageUrl) { Topic message = messageDao.getById(messageId); Group group = null; try { group = messageDao.getGroup(message); } catch (BadGroupException e) { throw new RuntimeException("Invalid group id msgid=" + messageId, e); } String scheme; if (secure) { scheme = "https"; } else { scheme = "http"; } String host = mainURI.getHost(); int port = mainURI.getPort(); String path = group.getUrl() + messageId; String query = ""; if (commentUrl) { query = "cid=" + commentId; } URI jumpUri = new URI(scheme, null, host, port, path, query); return jumpUri.getEscapedURI(); } return ""; }
From source file:ru.org.linux.util.LorURL.java
/** * url ? ?\/*from w w w . j a v a 2 s . c o m*/ * @param messageDao ? ? * @param canonical ? URL ? * @return url ? ?? ? * @throws MessageNotFoundException ? ?? * @throws URIException ? url */ public String formatJump(TopicDao messageDao, URI canonical) throws MessageNotFoundException, URIException { if (_topic_id != -1) { Topic message = messageDao.getById(_topic_id); Group group = messageDao.getGroup(message); String scheme = canonical.getScheme(); String host = canonical.getHost(); int port = canonical.getPort(); String path = group.getUrl() + _topic_id; String query = ""; if (_comment_id != -1) { query = "cid=" + _comment_id; } URI jumpUri = new URI(scheme, null, host, port, path, query); return jumpUri.getEscapedURI(); } return ""; }