How to output HTML from com.sun.HTTPExchange

My trival web server outputs output plain text. How do I output HTML?
Thanks,
Siegfried
package xml.webservicesDemo;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import com.sun.net.httpserver.HttpContext;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
public class WebApp implements HttpHandler {
     public static void main(String[] args) {
          try {
               HttpServer server = HttpServer.create(new InetSocketAddress(8123),0);
               HttpContext ctx = server.createContext("/apps/myapp/myNewApp",new WebApp());
               server.setExecutor(null);
               server.start();
          } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
     public void handle(HttpExchange t) throws IOException {
          InputStream is = t.getRequestBody();
          byte[] bBody = new byte[1000];
          int count = is.read(bBody);
          String sBody = bBody.toString();
          String response = "hello siegfried";
          t.sendResponseHeaders(200, response.length());
          OutputStream os = t.getResponseBody();
          os.write(response.getBytes());
          os.close();          
}

For that kind of work, I wouldn't recommend this class ( sorry, my other reply is to your first question ).
This is a SIMPLE http server. You would have to emulate an application server ( like Tomcat ) yourself if you want full-blown servlet / jsp functionality. You could define a simple jsp-ish domain specific language and parse it yourself, though.
That might be an interesting exercise, but not one that would appeal to me.

Similar Messages

  • How to output sound from Zen Neeon to speaker without using

    how to output sound from Zen Neeon to speaker directly?
    as far as i know, i can only play content in my mp3 player using speaker with usb cable connected to pc
    i just wonder how i play using "play" button in mp3 player and the sound will output to speaker directly?
    need extra line-in cable?

    my speaker system is subwoofer,but i not very sure it's 2. system.
    the cable from the speaker is slightly too big to connect to the player headphone jack. and no sound come out after i play.
    why?

  • Moving from com.sun.xml classes to the new xml support integrated in java

    So far, for our XML implementation, we have used the DocumentEx, ElementEx, etc. from com.sun.xml.
    We understand that xml is now supported by the java itself (javax.xml.parsers?) and we wish to update our code to use the newer API.
    Is there a simple mapping between the old DocumentEx and ElementEx and new classes in javax.xml? Can it really be simple to "get rid" of com.sun.xml?

    The combination of the:
    Oracle XML SQL Utility
    and
    Oracle XML Parser for PLSQL V2
    give you what you need.
    null

  • How to output HTML when called from a browser

    We are trying to replace a small web app with a bpel app so it has to return HTML. I keep getting XML of the HTML as output from this simple app. It doesn't interpret the html. The bpel uses a simple assign that puts an HTML string into the "body" message then passes it to the "reply".
    I have found out how to call this from the browser by changing "orabpel" in the url to "httpbinding" and then adding the "operation" onto the endpoint.
    from: http://server:7777/orabpel/default/ws1/1.0
      to: http://server:7777/httpbinding/default/ws1/processIs it possible to output html back to the browser and have the bpel look like a web page? Setting the mimetype of the output message type to "text/html" seems to have no effect at all.
    Here is my wsdl:
    <?xml version="1.0"?>
    <definitions name="HTTPGetService"
                 targetNamespace="http://services.otn.com"
                 xmlns:tns="http://services.otn.com"
                 xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"
                 xmlns="http://schemas.xmlsoap.org/wsdl/"
                 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                 xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
                 xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/">
        <message name="HTTPGetServiceRequestMessage">
            <part name="Region" type="xsd:string"/>
            <part name="EffectiveDate" type="xsd:string"/>
            <part name="EndDate" type="xsd:string"/>
            <part name="acc1" type="xsd:string"/>
            <part name="acc2" type="xsd:string"/>
        </message>
        <message name="HTTPGetServiceResponseMessage">
            <part name="body" type="xsd:string"/>
        </message>
        <!-- portType implemented by the HTTPGetService BPEL process -->
        <portType name="HTTPGetService">
            <operation name="process">
                <input message="tns:HTTPGetServiceRequestMessage"/>
                <output message="tns:HTTPGetServiceResponseMessage"/>
            </operation>
        </portType>
        <binding name="HTTPGet" type="tns:HTTPGetService">
            <http:binding verb="GET"/>
            <operation name="process">
                <http:operation location="/process"/>
                <input>
                    <http:urlEncoded/>
                </input>
                <output>
                    <http:urlEncoded/>
                    <mime:content type="text/html" part="body"/>
                </output>
            </operation>
        </binding>

    Hi,
    Open up admin console. Expand "Servers" node to view servers in domain.
    Right click on a server (or select Logging/ General tab) and select "view
    server log".
    Regards,
    Jon

  • How to display html from the jar

    Hiiiiiiiii
    How I can to display html from jar file

    Check out datagriditemrenderer for the datagrid column. Sample datagriditemrenderer code below:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Text xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:mx="library://ns.adobe.com/flex/mx"
      dataChange="updateHTML()">
      <fx:Script>
        <![CDATA[
          private function updateHTML():void
            htmlText = data.streetaddress + "\n" +
              data.city + ", " + data.state + "\n" +
              "<b>Phone:</b> " + data.phone + "\n" +
              "<b>Email:</b> " + data.email + "\n";
        ]]>
      </fx:Script>
    </mx:Text>

  • How to Serve HTML from a Proxy Service?

    I am trying to serve HTML from a proxy service.
    I set up a Messaging Service with request type = 'None' and response type = 'Text'; with Endpoint URL = '/OSB_Project/Proxy_Services/InfoPingerProxyService.html'.
    In my incoming request pipeline I set an html Transport Header action to define Content-Type = 'text/html'.
    In the response pipeline I replace the body with the html document contents...
    Trouble is, when I access the proxy (via a standard browser GET), I always produce an XML file with an <?xml...?> processing instruction:
    <?xml version="1.0" encoding="UTF-8"?>
    <html>
    Also: the browser always sees an XML response regardless, it seems.
    Any suggestions gratefully accepted.
    Cheers,
    Alph

    More on this.
    I made an "educated guess' that the path should be
    {code}./ctx:transport/ctx:response/tp:headers/http:Content-Type{code}
    But take a look at the following, you will see that the content type IS now text/html, but the XML processing instruction is still there...
    {code}
    :\BIN\wget-1.11.4-1-bin\bin>wget -d http://localhost:7001/Test_Project/ProxySe
    rvice1?q=1
    SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
    syswgetrc = C:\BIN\wget-1.11.4-1-bin/etc/wgetrc
    DEBUG output created by Wget 1.11.4 on Windows-MinGW.
    --2010-09-15 15:33:17-- http://localhost:7001/Test_Project/ProxyService1?q=1
    Resolving localhost... seconds 0.00, 127.0.0.1
    Caching localhost => 127.0.0.1
    Connecting to localhost|127.0.0.1|:7001... seconds 0.00, connected.
    Created socket 268.
    Releasing 0x0063a620 (new refcount 1).
    ---request begin---
    GET /Test_Project/ProxyService1?q=1 HTTP/1.0
    User-Agent: Wget/1.11.4
    Accept: */*
    Host: localhost:7001
    Connection: Keep-Alive
    ---request end---
    HTTP request sent, awaiting response...
    ---response begin---
    HTTP/1.1 200 OK
    Connection: Keep-Alive
    Date: Wed, 15 Sep 2010 05:33:17 GMT
    Content-Length: 61
    Content-Type: text/html; charset=utf-8
    X-Powered-By: Servlet/2.5 JSP/2.1
    ---response end---
    200 OK
    Registered socket 268 for persistent reuse.
    Length: 61 [text/html]
    Saving to: `ProxyService1@q=1'
    100%[=====================================> ] 61 --.-K/s in 0s
    2010-09-15 15:33:17 (1.23 MB/s) - `ProxyService1@q=1' saved [61/61]
    C:\BIN\wget-1.11.4-1-bin\bin>type "ProxyService1@q=1"
    <?xml version="1.0" encoding="UTF-8"?>
    <server>8088</server>
    C:\BIN\wget-1.11.4-1-bin\bin>
    {code}
    (I know that the actual CONTENT [ie "<server>8088</server"] is not really HTML at the moment...this is just intermediate testing content...)
    Back to the issue of how to get rid of that processing instruction...
    The proxy service is configured as a messaging service with request = none and response = text.
    Cheers,
    Alph

  • How to Output Nodes from XML web service to a FLV?

    Hi
    I've used AS3 to query a web service and obtain the resulting XML.  I need to parse the result down to just a few nodes for a given location.  I can tackle that separately.  I am wondering how I output the parsed XML to a flash video file (.flx)?  The video has place holders for the XML node values.  What do I need to do to place the XML results in the video?
    Thanks,
    Sid

    Andrei1 wrote:
    What is a content of XML nodes? I am not sure what you mean by "inserting nodes". Do you mean that you want to display some information over the video?
    And yes, encoders do take XMLs to inject metadata into video. But this is metadata only.
    OSML = Open Source Media Framework:
    http://www.opensourcemediaframework.com/
    By inserting nodes, I mean that the XML web service returns data for each city, which needs to be parsed to just high temp, low temp and current condition.  Those 3 values needed to be dispalyed over, or woven into, the video at each city location.  My thought was that AS3 could somehow recognize the 3 placeholders for each city and insert the high temp, low temp and condition icon into each placeholder.  However, when I import the FLV file into Flash, there are no elements into which I can infuse this data.

  • How to handle the exception com.sun.xml.internal.messaging.saaj.SOAPExcepn

    hi,
    I am accessing wsdl to get all the required data and the connection is establishing successfully thru java code but when i am calling the create user api the following exception is coming
    "com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: No NamespaceURI, SOAP requires faultcode content to be a QName"
    please tell me what is faultcode means and how to solve this exception

    Hi,
    Whenever there is any error inside the WebService or while it's processing ...it throws Exceptions ..We can handle these exception by our own to make the Exception details more readable.....For that we can create our own SOAPFault message...
    Please refer to the below Posts...
    1). If you are using JAXWS Style of WebService then : http://middlewaremagic.com/weblogic/?p=713
    2). If you are using JAXRPC Style of WebService then : http://middlewaremagic.com/weblogic/?p=721
    Thanks
    Jay SenSharma
    http://middlewaremagic.com/weblogic (Middleware magic Is Here)

  • ___Advice on how to print html from an applet___

    I have been working on this problem for a little while, but still can't find a good solution. I ask for any help/advice I can receive on this matter.
    Below is what I have already tried:
    1) Place the HTML within a JEditorPane and print the graphics object.
    * In order to do this I would have to display the HTML, which I do not want to do.
    * I have also tried placing the HTML within a JEditorPane and not display it, but I get no data from printing the graphics object.
    2) Print the View classes that contain the text by placing the html into a JEditorPane ex) JEditorPane.getUI().getRootView(jeditorPane).
    * This method is how the following article prints HTML: http://www.fawcette.com/javapro/2002_12/online/print_kgauthier_12_10_02/
    * This class prints each "leaf" view, which unfortunately will not print lists or table borders b/c they are contained in "branch" views. I have not been able to convert this class to print the branch views in a nice looking format.
    3) Use a DocFlavor of type "text/html" and send document to the printer.
    * Some printers can render html, but these are few and far between. Most printers I am dealing with do not accept type text/html.
    Below are some things I am thinking about trying:
    1) Convert the HTML to postscript and print the postscript.
    * I have no clue how to do this. I have searched the internet for code and found nothing but perl code (but I am using a java applet).
    2) Save the html file to users disk and open html file in new browser window. Then use javascript print function.
    * I really do not want to have to save files to the users disk just to print. This seems like the easiest way, but is also the least user-convient way.
    I would greatly appreciate any advice on printing HTML using java. Should I re-examine the methods I already tried? Can anyone give input on the methods I am planning to try? I would think this is a common problem, but I am having a hard time finding answers.
    Thanks for your interest and any help you can provide :)

    I tried the Java printing API in 1.4.2 but found it hopeless in terms of printing anything without using AWT.
    Also since the print service was going to be on Windows machine I used jawin (http://sf.net/projects/jawinproject/) to query the registry for the command to print a particular extension and then exec that command.

  • How to output jpg from g3110 scan

    New g3110 scanner.  How can I get jpg output of photos scanned?

    Hi,
    Based on the following specs, it should scan as jpg and many formats buy default:
        http://www8.hp.com/au/en/products/scanners/product-detail.html?oid=3723468#!tab%3Dspecs
    The following manual may help:
        https://multimedia.nscad.ns.ca/pdfs/scanner_hp_canjet_g3110.pdf
    Have you installed software and drivers to your computer yet ?
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • How to output value from stored procedure

    Hi folks, I need to output the OrderFK from a stored procedure not really sure how to achieve this any help or tips much appreciated.
    Sql code below
    USE [TyreSanner]
    GO
    /****** Object: StoredProcedure [dbo].[AddCustomerDetails] Script Date: 11/12/2014 20:56:34 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[AddCustomerDetails]
    /***********************Declare variables ***********************/
    /******tblCustomer******/
    @Forename nvarchar(50),
    @Surname nvarchar(50),
    @HouseNo nvarchar(50),
    @CustAddress nvarchar(50),
    @Town nvarchar(50),
    @Postcode nvarchar(50),
    @ContactNo nvarchar(50),
    @EmailAddress nvarchar(50),
    /******tblLink_OrderProduct******/
    @ProductQuantity int,
    @TotalProductSaleCost decimal,
    @ProductFK int,
    @FittingDate date,
    @FittingTime Time
    As
    DECLARE @CustomerFK int;
    DECLARE @OrderFK int;
    Begin TRANSACTION
    SET NOCOUNT ON
    INSERT INTO [TyreSanner].[dbo].[Customer](Forename, Surname, HouseNo, CustAddress, Town, Postcode, ContactNo, EmailAddress)
    VALUES (@Forename,@Surname,@HouseNo,@CustAddress,@Town,@Postcode,@ContactNo,@EmailAddress)
    Set @CustomerFK = SCOPE_IDENTITY()
    INSERT INTO [TyreSanner].[dbo].[Order] (CustomerFK)
    VALUES (@CustomerFK)
    SET @OrderFK = SCOPE_IDENTITY()
    INSERT INTO [TyreSanner].[dbo].[Link_OrderProduct](OrderFK, ProductFK, ProductQuantity, TotalProductSaleCost, FittingDate, FittingTime)
    VALUES
    (@OrderFK, @ProductFK, @ProductQuantity, @TotalProductSaleCost, @FittingDate, @FittingTime)
    COMMIT TRANSACTION

    Hi brucey54,
    There’re several ways to capture the value from a Stored Procedure. In you scenario, I would suggest 2 options, by an output parameter or by a table variable.
    By an output Parameter, you need to make a little bit modification on your code as below:
    USE [TyreSanner]
    GO
    ALTER PROCEDURE [dbo].[AddCustomerDetails]
    @Forename nvarchar(50),
    @FittingDate date,
    @FittingTime Time,
    @OrderFK int output
    As
    DECLARE @CustomerFK int;
    --DECLARE @OrderFK int;
    Run the following code, Then @OrderFKvalue holds the value you’d like.
    DECLARE @OrderFKvalue int;
    EXEC AddCustomerDetails(your parameters,@OrderFKvalue output)
    Anyway if you don’t like to add one more parameter, you can get the value by a table variable as well. Please append “SELECT @OrderFK;” to your Procedure as below:
    USE [TyreSanner]
    GO
    ALTER PROCEDURE [dbo].[AddCustomerDetails]
    SET @OrderFK = SCOPE_IDENTITY()
    INSERT INTO [TyreSanner].[dbo].[Link_OrderProduct](OrderFK, ProductFK, ProductQuantity, TotalProductSaleCost, FittingDate, FittingTime)
    VALUES
    (@OrderFK, @ProductFK, @ProductQuantity, @TotalProductSaleCost, @FittingDate, @FittingTime);
    SELECT @OrderFK;
    Then you can call the Stored Procedure as below:
    DECLARE @T TABLE (OrderFK INT);
    INSERT @T EXEC AddCustomerDetails(your parameters) ;
    SELECT OrderFK FROM @T;
    There’re more options to achieve your requirement, please see the below link:
    How to Share Data between Stored Procedures
    If you have any question, feel free to let me know.
    Best Regards,
    Eric Zhang

  • Does APEX re-write output HTML from an application process

    I have a process which has the following line
    htp.prn('<input type="hidden" name="F05" value="' || l_submitted_previously || '"/>');this however is outputting the following html
    <input name="F05" value="N" type="hidden">as you can see the parameters in the tag are not in the order I specified and also the closing slash is omitted.
    Can anyone explain this?

    APEX 3.2.1.00.12
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    Unfortunately I doh't know the web server architecture
    Firefox v13
    Custom theme
    Custom templates
    Hidden item
    I don't think the last 4 items listed above will have a bearing on this because it's a dynamically produced item created by an application process. I have pasted the entire code for the process in case that helps.
    DECLARE
         l_year_passed number := wwv_flow.g_x01;
         l_expenditure_value number;
         l_submitted_previously varchar2(1) := 'N';
    BEGIN
         SELECT DECODE(COUNT(*),0,'N','Y')
         INTO l_submitted_previously
         FROM F_EXPENDITURE
         WHERE FINANCIAL_YEAR_KEY = l_year_passed;
        for rec in (SELECT *
                    FROM l_service_group
                    WHERE service_designated_year<=l_year_passed
                    AND service_designated_year>0
                    order by NON_SERVICE_GROUP_FLAG, SERVICE_GROUP_SHORT_NAME)
         loop
         BEGIN
              SELECT EXPENDITURE_VALUE
              INTO l_expenditure_value
              FROM F_EXPENDITURE
              WHERE FINANCIAL_YEAR_KEY = l_year_passed
              AND SERVICE_GROUP_KEY = rec.SERVICE_GROUP_KEY;
              EXCEPTION
              WHEN NO_DATA_FOUND THEN
              l_expenditure_value := NULL;
         END;
              htp.prn('<tr><td><label for="F01_' || rec.SERVICE_GROUP_KEY || '"><span class="t13RequiredLabel"><img src="/i/requiredicon_status2.gif" alt="">' || rec.SERVICE_GROUP_SHORT_NAME || '</span></label></td><td><input type="text" name="F01" id="F01_' || rec.SERVICE_GROUP_KEY || '" value="'||l_expenditure_value||'"/><input type="hidden" name="F02" id="F02_' || rec.SERVICE_GROUP_KEY || '" value="' || rec.SERVICE_GROUP_KEY || '"/></td></tr>');
         end loop;
         if l_year_passed = 0 then
              htp.p('<p>Please select a financial year</p>');
         end if;
         htp.prn('<input type="hidden" name="F05" value="' || l_submitted_previously || '"/>');
    END;

  • How extract the HTML from a mail

    Hi,
    How can I extract the HTML body of a Novell Groupwise mail item using the APIs. This HTML also need to have the embedded images, which can even be reffered from a local folder.
    A sample code in VB or a some references would help. Please advice.

    In 8.0, we expose the content-type and content-id
    of the attachments.
    The HTML message body attachments are grouped
    together as attachments. The text.htm attachment
    is first followed by any embedded graphics
    attachments. Each embedded graphic attachment
    will have an content-id value.
    The logic is to get the text.htm attachment and
    any following attachments that have a content-id
    until there is not an attachment or an attachment
    does not have an content-id.
    Preston
    >>> On Friday, February 12, 2010 at 8:06 AM,
    DamianPM<[email protected]> wrote:
    > Thanks.
    >
    > The embedded images in the HTML has the following within the img tag,
    > src="cid:[email protected]"
    >
    > The attachment collecection does not have a image004.jpg but has a
    > image.jpeg
    >
    > How can these images be linked or update the image tags so that it
    > picks the image from a local folder.
    >
    > The HTML preview of the email in NGW email application shows the
    > embedded images correctly.

  • How to output HTML code in methods without out.print

    Hi,
    I am trying to create a larger web-site with jsp. At first I tried to structure the page using include files. Since there is a limit for the length of if/else blocks, I now switched to using methods instead.
    The Problem I have is that there a larger HTML blocks I dont want to print with out.print because that would make the source unreadable.
    Unfortunately the <%= tag doesnt work in methods.
    Here a code sample:
    <%!
    public void processOrder()
    for(int i=1; i<10; i++)
    out.print("<table>");
    out.print("<tr>");
    out.print("<td>Your Order:<td>");
    %>
    Isnt there a way to use a tag like <%= ?
    Or are there other constructs then methods which can handle <%= ?
    With PHP it would be no problem. So I wonder why there should be no way to do it with jsp.

    I generally put dynamic output in a separate class file; you can then either instantiate the class in a scriptlet and call the appropriate method (which can either return a string or do all of your out.prints) or use a jsp:useBean tag.
    Given the following class:
    public class myHTML {
       public myHTML(){}
       public String renderTable(){
          String s = "";
          s += "<TABLE>\n";
          s += "<TR><TD>some content</TD></TR>\n";
          s += "</TABLE>\n";
          return s;
    }You can then do either of the following in your JSP page:
    1.<%
       myHTML mh = new myHTML;
       out.print(mh.renderTable());
    %>2.<jsp:useBean id="somename" class="somepkg.myHTML" scope="request">
    <%=somename.renderTable()%>
    </jsp:useBean>Either will work, and all of the redundant out.print or String concat lines are moved out of the JSP.

  • How to generate HTML from XML and XSL?

    Hi all,
    I am new to XML.
    Can I somehow see the HTML-Output of the XML-File, when I have the XSL-File too, but don't use any XML-Editor (XMLSpy) and FOP? I do not want use any additional tools - only the database tools.
    What I need for this?
    Do I need the XSLT-File too?
    I am waiting for your answers, when possible with examples please.
    Regards
    Leonid Pavlov

    Please post on the General XML forum.

Maybe you are looking for

  • Authorisation of FBL1N

    Hello SAP Guru, We have a  separate Purchase dept. for Raw Material, Engg. Stores, Packing Material etc. We want to give authorization of FBL1N (Vendor Line Item display) to each purchase department. We have given separate Vendor code for Raw materia

  • Daily I receive a question for updating my Firefox (s.6.17 MacOs), but when I agree the result is Or no contact with the update-server

    Daily I receive a message for updating my Firefox (3.6.17 MacOs 10.6.8) but when I agree, it takes quite a long time and then OR a message: no contact with the update-server OR something like: Sorry we cannot find xxxxx(?!). QUESTION: HOW TO UPDATE?

  • Capturing JButton event in a JList

    All, I have a JList that renders each list item with some special formatting of a JLabel and a Jbutton. The button is an 'OK' button that must be acknowledged. When the OK button is acknowledged it should be deleted from the list model. I am having t

  • PS CS3/CS4/CS5 and Snaplab UP-CR10L color calibration question

    Sorry for the bad screen name, but after getting 20-30 (name in use) messages, I decided to go for RANDOM characters, and IT WORKED!! Anyway, here is my inquiry..... I have all three PS versions mentioned above, on an Intel Mac, and recently picked u

  • Apple USB Modem 56K

    Hello Friends Now 2 days ago the update of Snow Leopard 10.6.3 released, but once again WITHOUT a 64-bit drivers for the original Apple USB 56K Modem. Can anyone say whether there's what is planned? I have often professionally faxes by modem to send