Results 1 to 8 of 8
  1. #1
    aajay is offline Member
    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Default javastring problem

    I'm getting string as
    String url = request.getRequestURL().toString();
    and url String could be either one of following three
    e.g 1) http://www.abctest.com
    2) http://wwwcte.abctest.com
    3) http://mydev.abctest.com

    I'm need split the url as

    String[] urlpref = url.split(".");
    String test = urlpref[0];

    to get the first part of url before "."
    and compare it with "www"

    if(test.indexof("www")>-1)
    { go to page url start with www}
    else
    {go to page url start other then www}

    but it is giving error
    I'm very new to java can any one help me to get the first part of the string before "."
    and help me compare that part with "WWW"

    thanks,

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,578
    Rep Power
    25

    Default

    it is giving error
    Please copy and paste the full text of the error message here.
    try debugging your code by printing out the values in the array so you can see what is happening.

  3. #3
    aajay is offline Member
    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Default

    <%@ page contentType="text/html; charset=utf-8" %>

    <%@ page import="com.actuate.reportcast.utils.*" %>
    <%@ page import="com.actuate.activeportal.beans.*" %>
    <%@ page import="com.actuate.activeportal.idapiadapter.*" %>
    <%@ page import="com.actuate.schemas.*" %>
    <%@ page import="com.actuate.activeportal.utils.*" %>
    <%@ page import="org.apache.axis.client.*" %>
    <%@ page import="org.apache.axis.Message" %>
    <%@ page import="org.apache.axis.MessageContext" %>
    <%@ page import="org.apache.axis.attachments.AttachmentPart " %>
    <%@ page import="java.io.*" %>
    <%@ page import="java.net.*" %>
    <%@ page import="javax.xml.parsers.*" %>
    <%@ page import="org.w3c.dom.*" %>
    <%@ page import="org.apache.xerces.parsers.DOMParser " %>
    <%@ page import="javax.xml.transform.*" %>
    <%@ page import="javax.xml.transform.stream.*" %>
    <%@ page import = "org.apache.xpath.*" %>
    <%@page import="com.wachovia.beans.*"%>
    <%@ page import="java.util.*" %>
    <%@page import="java.sql.*"%>
    <%@page import="oracle.jdbc.driver.*"%>
    <%@page import="oracle.sql.*"%>
    <%@page import="javax.servlet.ServletContext.*"%>
    <%@page import="javax.servlet.ServletRequest.*"%>
    <%@page import="javax.servlet.http.HttpServletRequest.*"%>
    <%@page import="com.actuate.reportcast.exceptions.Authenti cationException.*"%>

    <%@ taglib uri="/common" prefix="common" %>

    <%@ page import="com.actuate.reportcast.utils.StaticFuncs" %>

    <%-- GATHER AUTHENTICATION CREDENTIALS AT THE TOP OF ALL LEVEL 0 PAGES --%>
    <%@ include file="/iportal/activePortal/authenticate.jsp" %>

    <% if (sAuthID == null) return; %>

    <%-- TAG LIBRARIES ------------------------------------------------------- --%>
    <%@ taglib uri="/struts-bean" prefix="bean" %>
    <%@ taglib uri="/struts-html" prefix="html" %>
    <%@ taglib uri="/struts-logic" prefix="logic" %>
    <%@ taglib uri="/i18n" prefix="i18n" %>
    <%@ taglib uri="/viewer" prefix="viewer" %>
    <%@ taglib uri="/common" prefix="common" %>


    <%-- DECLARE ANY RESOURCE BUNDLES USED IN THIS PAGE --%>
    <i18n:bundle baseName="com.actuate.reportcast.resources.rc.View er" id="bdlViewer" locale="<%= lLocale %>"/>
    <%
    String XMLfile = null;
    String XSLfile = null;
    String AuthType = null;
    String objectId = paramBean.getParameter("id");
    //out.println(objectId);
    String connectionHandle = paramBean.getParameter("connectionhandle");
    //out.println(connectionHandle);
    String serverURL = sServerURL;
    //out.println(serverURL);
    String volume = sVolume;
    //out.println(volume);
    //out.println(sAuthID);
    //String ServerName = request.getServerName();
    int ServerPort = request.getServerPort();
    out.println("uri=" + ServerPort);
    //out.println("SP=" + ServerName);



    %>

    <%
    // Get the person_id from the header
    String person_id = request.getHeader("proxy-remote-user");

    // Get the info for web.xml
    ServletContext context = getServletContext();

    String HOST_NAME = context.getInitParameter("HOST_NAME");
    String PORT = context.getInitParameter("PORT");
    String SERVICE_NAME = context.getInitParameter("SERVICE_NAME");
    String USER = context.getInitParameter("USER");
    String PASSWORD = context.getInitParameter("PASSWORD");
    String ENVIRONMENT_URL = context.getInitParameter("ENVIRONMENT_URL");
    String ENVIRONMENT_URL_EXTERNAL = context.getInitParameter("ENVIRONMENT_URL_EXTERNAL ");

    try {

    IdapiProxyPool thePool = IdapiProxyPool.getInstance();
    //IdapiProxy prox = thePool.getProxyObject(serverURL);
    //Changed to make it work in ver-8.0
    IdapiProxy prox = (IdapiProxy) thePool.getProxyObject(serverURL);

    ActuateAPIEx actuateAPI = prox.getActuateAPI();
    ActuateSoapPort wsdlProxy = actuateAPI.getActuateSoapPort(new java.net.URL(serverURL));
    actuateAPI.setTargetVolume(volume);
    actuateAPI.setAuthId(sAuthID);

    // Get XML Content
    com.actuate.schemas.GetContent getContentmsg = new com.actuate.schemas.GetContent();
    com.actuate.schemas.ObjectIdentifier obj = new com.actuate.schemas.ObjectIdentifier();
    obj.setId(objectId); //make sure to check in viewnavigation that is the same id
    com.actuate.schemas.ViewParameter type = new com.actuate.schemas.ViewParameter();
    type.setFormat("XMLData");
    type.setUserAgent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Q312461; .NET CLR 1.0.3705)");
    com.actuate.schemas.ComponentType comp = new com.actuate.schemas.ComponentType();
    comp.setId("0");
    getContentmsg.setObject(obj);
    getContentmsg.setViewParameter(type);
    getContentmsg.setComponent(comp);
    getContentmsg.setDownloadEmbedded(new Boolean(false));

    //connectionHandle is Soap Header for GetContent request (required for transient reports)
    actuateAPI.setConnectionHandle(connectionHandle);

    com.actuate.schemas.GetContentResponse getContentresp = wsdlProxy.getContent(getContentmsg);
    Call call = actuateAPI.getCall();
    MessageContext messageContext = call.getMessageContext();
    Message message = messageContext.getResponseMessage();


    // show the first attachment
    Iterator iterator = message.getAttachments();
    if (iterator.hasNext()) {
    AttachmentPart attachmentPart = (AttachmentPart) iterator.next();
    XMLfile = attachmentPart.getDataHandler().getName();
    attachmentPart.getDataHandler().getOutputStream();
    String attachmentttype = attachmentPart.getContentType();
    //out.print("file is located at: " + XMLfile);
    //out.print(attachmentPart.getDataHandler().getConte nt());
    }
    else //no attachments were received
    {
    out.println("Error while receiving the report attachment");
    }

    ServletContext sc = getServletConfig().getServletContext();
    String path = sc.getRealPath("/");
    out.println(path);

    //Stream the XML and XSL and produce output
    StreamSource xml = new StreamSource(XMLfile);
    StreamSource xsl = new StreamSource(path + "/wfa/jsp/MailMerge.xsl");

    java.io.File resultFile = java.io.File.createTempFile("Streams", ".xml");
    Result result = new StreamResult(resultFile);

    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer(xsl);
    transformer.transform(xml,result);
    out.print("file is located at: " + resultFile);
    out.print("The file length is " + resultFile.length());

    //Open the test file and get the bytes
    byte[] reportBytes = new byte[(int)resultFile.length()];
    FileInputStream fr = new FileInputStream(resultFile);

    while(fr.read(reportBytes) != -1)
    {
    fr.read(reportBytes);
    }

    String userId = "123456";

    //BEGIN DATABASE INSERT CODE
    Connection conn = null;
    java.sql.Statement stmt = null;
    java.sql.ResultSet rs = null;

    Timestamp ts = new Timestamp(System.currentTimeMillis());
    Calendar dt = Calendar.getInstance();
    String requestId = Integer.toString(dt.get(Calendar.YEAR)) + Integer.toString(dt.get(Calendar.MONTH)) + Integer.toString(dt.get(Calendar.DAY_OF_MONTH)) + Integer.toString(dt.get(Calendar.HOUR_OF_DAY)) + Integer.toString(dt.get(Calendar.MINUTE)) + Integer.toString(dt.get(Calendar.SECOND)) + Integer.toString(dt.get(Calendar.MILLISECOND)) + userId;


    long fileLength = reportBytes.length;


    String connectionString = "jdbc:oracle:thin:@(DESCRIPTION=" +
    "(ADDRESS_LIST=" +
    "(ADDRESS=(PROTOCOL=TCP)" +
    "(HOST=" + HOST_NAME + ")" +
    "(PORT=" + PORT + ")" +
    ")" +
    ")" +
    "(CONNECT_DATA=" +
    "(SERVICE_NAME=" + SERVICE_NAME + ")" +
    "(SERVER=DEDICATED)" +
    ")" +
    ")";


    String insertSql = "INSERT INTO AC_REPORT_XML (REQUEST_ID, XML_TXT, XML_BYTE_CNT, REQUEST_DTM,USER_ID) VALUES ('" + requestId + "', EMPTY_BLOB(), " + fileLength + ", { ts '" + ts + "'}, '"+ person_id +"')";
    String updateSql = "SELECT xml_txt FROM ac_report_xml WHERE request_id='" + requestId + "' FOR UPDATE";
    try {
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    conn = DriverManager.getConnection(connectionString, USER ,PASSWORD);
    conn.setAutoCommit(false);

    stmt = conn.createStatement();
    stmt.execute(insertSql);

    // Select the BLOB
    rs = stmt.executeQuery(updateSql);
    if (rs.next()) {
    BLOB blob = ((OracleResultSet)rs).getBLOB(1);
    // Create an OutputStram object to write the BLOB as a stream
    OutputStream ostream = blob.getBinaryOutputStream();
    ostream.write(reportBytes);

    //Close the inputstream and outputstream
    ostream.close();
    }

    conn.commit();

    }
    catch (Exception ex){
    out.println(ex);
    ex.printStackTrace();
    requestId = null;
    }
    finally{
    try{
    if(rs != null) rs.close();
    if(stmt != null) stmt.close();
    if(conn != null) conn.close();
    }
    catch (Exception e){
    e.printStackTrace();

    }
    }

    //END DATABASE INSERT CODE

    //check if the request is secure


    if (!request.isSecure())
    {
    AuthType = "http://";
    }

    else {
    AuthType = "https://";
    }


    if (requestId != null && requestId != "")
    {
    //Read the Request URL
    //Added by -Jay Talasila May 2010
    //Redirect to External URL functionality is added - New Variable ENVIRONMENT_URL_EXTERNAL is created in Web.xml
    //This variable is specific to evnironment

    String url = request.getRequestURL().toString();

    //String delimiter = ".";
    alert (url);

    //String[] urlprefx = url.split(".");


    //String test = urlprefx[0];

    //String abc = urlprefx[0];


    //if(test.indexOf("www")>-1)
    if(url.indexOf("//www.")>-1)

    {
    response.sendRedirect(AuthType + ENVIRONMENT_URL_EXTERNAL + "/mailmerge/TemplateList.aspx?requestId=" + requestId);
    }
    else
    {

    // Changed it as part of upgrade to 9SP3 as the APS is unable to process the prior URLs.
    // response.sendRedirect(AuthType + ENVIRONMENT_NAME_EXTERNAL + "/mailmerge/TemplateList.aspx?requestId=" + requestId);

    response.sendRedirect(AuthType + ENVIRONMENT_URL + "/mailmerge/TemplateList.aspx?requestId=" + requestId);


    //response.sendRedirect("https://mydev.advisor-connection.com/mailmerge/TemplateList.aspx?requestId=" + requestId);
    // out.println(AuthType + ENVIRONMENT_URL + "/mailmerge/TemplateList.aspx?requestId=" + requestId);
    }
    }

    } // end of big try
    catch (Exception e) {

    String sErrorMsg = e.getMessage();

    sErrorMsg = sErrorMsg.replace('\n', ' ');
    sErrorMsg = sErrorMsg.replace('"', ' ');
    sErrorMsg = sErrorMsg.replace('=', '-');

    String sURLError = StaticFuncs.jsEncode(request.getContextPath()) + "/wfa/jsp/displayerror.jsp?errorcode=MailMerge&errormsg=" + sErrorMsg;
    response.sendRedirect(sURLError);

    }

    File file = new File(XMLfile);
    try {
    // Create file if it does not exist
    boolean success = file.createNewFile();
    if (success) {
    // File did not exist and was created
    } else {
    // File already exists
    }
    } catch (IOException e) {
    }
    file.delete();

    %>

  4. #4
    aajay is offline Member
    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Default

    I have copy entire jsp file please look at actual code
    String url = request.getRequestURL().toString();

    String delimiter = ".";


    String[] urlprefx = url.split(".");


    String test = urlprefx[0];




    if(test.indexOf("www")>-1)

    I need your advise

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,662
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by aajay View Post
    String[] urlprefx = url.split(".");
    Split uses a regular expression to split on; the single dot "." means "any character" i regular expression lingo; you have to escape it as in "\\."; it's all in the API documentation which you probably haven't read because no one does; you're no exception to the rule ...

    kind regards,

    Jos

  6. #6
    aajay is offline Member
    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Default

    Thanks jos you save my day
    I appriciated your help

  7. #7
    aajay is offline Member
    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Default

    Hi jos please help me where I can find API documentation

    thanks

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,662
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by aajay View Post
    Hi jos please help me where I can find API documentation

    thanks
    A few seconds of googling would've helped you faster: API Documentation.

    kind regards,

    Jos

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •