Non-http servlet without headers

I would like to create a servlet that does not respond to web requests, but to invocations by client sockets (on port 80).
It all goes well, but even if I use a simple Servlet implementation, the web server wraps the response into a http response, and adds headers, which is unnecessary at all times. How can I avoid this?
I use JBoss/Tomcat for container.

Hi,
          import java.io.*;
          import javax.servlet.*;
          public class Helloservlet extends GenericServlet {
          public void service(ServletRequest req,ServletResponse res) throws
          ServletException,IOException {
          res.SetcontentType("text/html");
          PrintWriter pw = new PrintWriter();
          pw.println("<b>HelloWorld"); pw.close();
          The above example code for GenericServlet that is not specific to the http.
          Regards
          Anilkumar kari

Similar Messages

  • Non-HTTP servlet

              I need to support concurrent access from multiple clients using a non-HTTP protocol
              over socket connection. One way is to write my socket server and create a new
              thread for each request. But WLS forbids user-created threads from calling into
              WLS components such as EJB. So I would like to write a non-HTTP servlet so that
              the WLS servlet container will create a new thread calling into the servlet and
              have the servlet calling EJBs on this WLS created thread. But is there a way to
              plug a subclass of GenericServelt into WLS?
              Thanks,
              T Tse
              

    I don't think there is a way to use non-HTTP servlet's, but still you can use WLS
              execute queue and execute threads, for example:
              ServerSocket serverSocket = new ServerSocket(...);
              for(;;) {
              new MyThread(new RequestHandler(serverSocket.accept())).start();
              class RequestHandler implements Runnable {
              Socket socket;
              public RequestHandler(Socket socket) {
              this.socket = socket;
              public void run() {
              // to see if this is executing on a WebLogic execute thread
              new Exception().printStackTrace();
              try {
              socket.close();
              } catch(Throwable whatever) {}
              class MyThread implements Schedulable, Triggerable {
              boolean done = false;
              Runnable runnable = null;
              Object sync = new Object();
              ScheduledTriggerDef std;
              public void join() throws InterruptedException {
              synchronized(sync) {
              if(!done) {
              sync.wait();
              public void run() {
                   if(runnable != null) {
                   runnable.run();
              public MyThread() {
              public MyThread(Runnable runnable) {
                   this.runnable = runnable;
              public boolean start() {
                   boolean ok = false;
                   try {
                   T3ServicesDef t3 = (T3ServicesDef)(new InitialContext()).lookup("weblogic.common.T3Services");
                   std = t3.time().getScheduledTrigger(this, this);
                   std.schedule();
                   ok = true;
                   } catch(NamingException ne) {
                   System.out.println(ne.getMessage());
                   } catch(TimeTriggerException tte) {
                   System.out.println(tte.getMessage());
                   return ok;
              public void trigger(Schedulable sched) {
                   try {
                   run();
                   } catch(Throwable t) {
                   System.out.println(t);
              synchronized(sync) {
              done = true;
              sync.notify();
              public long schedule(long time) {
                   return done ? 0 : 1;
              ttse <[email protected]> wrote:
              > I need to support concurrent access from multiple clients using a non-HTTP protocol
              > over socket connection. One way is to write my socket server and create a new
              > thread for each request. But WLS forbids user-created threads from calling into
              > WLS components such as EJB. So I would like to write a non-HTTP servlet so that
              > the WLS servlet container will create a new thread calling into the servlet and
              > have the servlet calling EJBs on this WLS created thread. But is there a way to
              > plug a subclass of GenericServelt into WLS?
              > Thanks,
              > T Tse
              Dimitri
              

  • Non-http servlet engine?

    Hi, I'm new to servlet development and I'm not sure this question has been answered here before. So I apologize if it has.
    Basically I want to have an integrated server that can accept both http and non-http requests. So my initial thought was to write an HttpServlet and a GenericServlet. Then I googled for clues on how to implement that and found from the JavaRanch website http://faq.javaranch.com/java/ServletsFaq#otherProtocols that this task could be a daunting one because that'd imply that I have to write a new servlet engine.
    So my question is, is this true in your expert opinion? And, if the custom non-http protocol has a similar syntax as http (e.g. RTSP), is it possible to just extend the http servlet engine to support it? And would that be doable without much effort?
    Thanks,
    Liang.

    Would you actually need the entire servlet system for the new protocol? For your typical simple request/reply protocol you'd normally:
    Create a server socket.
    When a connection arrives, start a thread to service it.
    In the service thread, read and parse request.
    Send reply.
    Close socket, exit thread.
    A servlet system adds a bunch of stuff to that: a layer that allows you to configure pluggable request handlers; methdod-specific functions (POST -> doPost()); a ServletRequest object; etc. Are those things relevant to the new protocol? Do you have requests with URL-like things in the header, allowing routing requests to different servlets? Do you plan to have lots of servlets for the protocol (one servlet -> no much point in XML-configurable request routing)?
    I'd hope that I wouldn't need to implement a configurable request routing infrastructure. It's a lot of work if it's not really needed. Just write a socket server. If you have an associated web server (e.g. HTML pages from which the user starts RTSP requests) you can even run the socket server inside the servlet container if that helps.

  • Non-HTTP(S) Servlets

    I'd like to use servlets to provide services over a non-HTTP protocol (e.g. FTP, NNTP, SMTP, etc.). The existence of the Servlet -> GenericServlet -> HTTPServlet hierarchy suggests this is supposed to be possible but I'm not sure how to do it. The main problem I see is getting my servlet container to know what protocol (IP port) I want to use.
    So, are non-HTTP servlets supposed provide their own logic to set up a socket listener in the Servlet.init() method, manage their own thread pool, and dispatch requests to servlet instances as they are received? Or, is there some service provider API I can use to plug a non-HTTP service into my servlet container?
    BTW, I'd like to do this in a J2EE v1.3 server.
    Thanks, Dave

    I'd like to use servlets to provide services over a
    non-HTTP protocol (e.g. FTP, NNTP, SMTP, etc.)My first reaction would be "don't".
    In an HTTP request, there is a bunch of headers, which the servlet container uses to decide which servlet it will invoke. There are no such headers in e.g. FTP. Even if you manage to subclass Servlet to FTPServlet, the web server doesn't know how that FTP requests should be routed to that servlet.
    The piece of code that listens to port 80 etc really wants to see "GET", "POST" etc plus an URL on the first line of incoming data. That code won't respond well to seeing SMTP's "HELO".
    That being said, you can put such protocols in a web server or app server. Write a thread that creates a server socket for the appropriate port and then sits in accept(). When a connection comes in, it starts a new per-client thread which talks SMTP or whatever over the incoming socket. Pretty basic client/server socket programming.
    Also, to me, the servlet model appears inappropriate for FTP et al: a servlet services one request, then exits. FTP, NNTP and SMTP are all more like a discussion than request-reply.
    In theory, it would be possible to fashion e.g. an SMTP server as a sort of a servlet. Instead of doGet() and such perhaps you'd have doHELO(), doMAIL_FROM(), doDATA() etc. But that seems overly complicated... Seems easier to me to do simply:
        while (true)
            read socket input a line at a time;
            if (in data mode) {
                check for end-of-message;
                append to string buffer;
            } else {
                tokenize it;
                obey the incoming command;
        }Maybe if you really want to use the servlet model, write a Servlet-like class that has a doCommand() method and make the "obey the incoming command" bit above call that. I'm not sure how much that buys, though. There are enough small differences in things like command tokenizing to make code reuse in the various protocol "servlets" difficult.
    Btw, FTP in particular is an incredibly messy protocol. Implement that one only if you absolutely must, and even then crib some existing public domain implementation as a base. Active/passive, separate command/data channels, a wide range of buggy FTP clients, security difficult to get right, ... ouch...

  • Using Servlet for non HTTP purpose

    Hi,
    I have a requirement where I require tomcat to serve a non http request. Is there a way?

    The HTTP protocol begins with a line like:
    GET /some/thing HTTP/1.0
    Tomcat uses the "/some/thing" to find out to which servlet to give the request.
    If your protocol doesn't have that line, Tomcat is going to have a hard time knowing what to do with the request.
    You could write a thread that opens a ServerSocket, accepts incoming requests, and hands them off to a servlet-like system (perhaps even subclasses of Servlet). You could even run that thread within Tomcat. If you want/can restrict yourself to Tomcat, you may even be able to use parts of Tomcat's internals (the Service/Connector/Engine infrastructure or whatnot.) Whether this is a good approach depends on all kinds of details.

  • Get the url to current servlet without the servletname

    Hello all,
    I have done this using String methods but was wondering if there was a built in Servlet method that would return the URL of the web-app...
    Lets say I have a servlet at http://mydn:8080/myWebProject/MyServletName
    now if I do the following :
    request.getRequestURL().toString()It returns http://mydn:8080/myWebProject/MyServletName
    What I need is : http://mydn:8080/myWebProject/
    So I parse this using String manipulation.
    Is there a way to do this within the servlet without String manipulation?
    I tried:
    request.getContextPath();
    request.getPathInfo();
    request.getPathTranslated();
    request.getServletPath()None give me what I need.
    I know this seems petty.
    TIA!

    Try this code.
    data :lc_webdynprourl type ref to CL_WD_UTILITIES.
    data :lv_url type string.
    create object lc_webdynprourl.
    CALL METHOD CL_WD_UTILITIES=>CONSTRUCT_WD_URL
      EXPORTING
        APPLICATION_NAME               = 'Test'   "Your web dynpro applicaiton name
       IN_HOST                       =
       IN_PORT                       =
       IN_PROTOCOL                   =
       IN_PARAMETERS                 =
       IN_CLIENT                     =
       IN_FORWARD_ACCESSIBILITY_FLAG =
         NAMESPACE                     = 'sap'
      IMPORTING
       OUT_HOST                      =
       OUT_PORT                      =
       OUT_PROTOCOL                  =
       OUT_LOCAL_URL                 =
         OUT_ABSOLUTE_URL              = lv_url.
    Good luck,
    Krishna

  • SSO for SAP and Non-SAP applications without Enterprise Portal

    Dear all,
    Is it possible to implement SSO for both SAP and non-SAP applications without involvement of EP at all?
    I have gone through this link.
    <a href="http://help.sap.com/saphelp_nw04s/helpdata/en/e5/4344b6d24a05408ca4faa94554e851/frameset.htm">http://help.sap.com/saphelp_nw04s/helpdata/en/e5/4344b6d24a05408ca4faa94554e851/frameset.htm</a>
    But I still i am not able to get the precise answer on how to enable SSO for both  SAP and non-SAP applications without EP.
    We have decided not to implement EP in first phase of SAP implementation. But we need to enable SSO for other SAP and Non-SAP applications.
    A detailed description on how to deal this kind of scenarios will be helpful.
    Thanks.

    A client of our's uses <b>SAP Enterprise Portal</b>, and is using the SAP SSO, which is implemented with tickets, and requires the use of SAPSECULIB.  My company provides an application for this client, and our application in hosted in our data center for the client, as a Software as a Service application, obviously across the internet.  Our client, which owns a SAP license, has asked that we support the SAP SSO as a non-SAP SSO application.  The client user's SSO ticket will be created from SAP EP, and then passed across the internet to our application, and we are to use that SSO ticket as an authentication ticket to our application.  I beleive I know how to do this work technically, having reviewed the SAP document named: "Dynamic Library for Verifying SSO Tickets in Third-Party Software"   Specification   Version 2.00  December 2005.
    My question is, does my company have the right to use the SAPSECULIB?  Where is the official download and <b>license</b> download, that indicates we can download this library, and use it to support a SAP customer?  We do not own a SAP license.  Thank you for your help.  I have searched many places in SAP support.<b></b>

  • Using JTA enabled connection in a JSP/servlet without transaction

    Can we use a JTA enabled connection in a JSP/servlet without any transaction?
    Thanks

    This might be helpful.
    http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/transactions/transactions6.html

  • Can't save non http bookmarks in firefox

    Can't save non http bookmarks in firefox
    Amongst standard website favourites saved on my IE toolbar i have several html documents/pages of my own making. These obviously begin with a non-http address.
    Examples are pages that contain an array of favourite webcams on a single page, or a page that opens up several related sports sites each in their own tab, or a stormchasing swathe of tabbed windows covering live video chase, weather radar, emergency service scanners etc. etc.
    An address would take the format on the lines of
    "C:\Documents and Settings\USERNAME\My Documents\Football Results and Tables\UK.html"
    Firefox insists on adding 'http' before the C:\ (plus unlike IE it also adds the %20 for spaces.)
    Can anyone help to to get FF to accept a favourite that is not a website.

    I just verified that it still works for me in Firefox 18.0, using the "star" in the Location Bar.
    '''Try the Firefox SafeMode''' to see how it works there. <br />
    ''A troubleshooting mode, which disables most Add-ons.'' <br />
    [https://support.mozilla.org/en-US/kb/troubleshoot-firefox-issues-using-safe-mode#w_safe-mode-window_2 Troubleshoot Firefox issues using Firefox SafeMode]
    When in Safe Mode... <br />
    * The status of plug-ins is not affected.
    * Custom preferences are not affected.
    * All extensions are disabled.
    * The default theme is used, without a persona.
    * userChrome.css and userContent.css are ignored.
    * The default toolbar layout is used.
    * The JIT Javascript compiler is disabled.
    * Hardware acceleration is disabled.
    * You can open the Firefox 15.0+ SafeMode by holding the '''Shft''' key when you use the Firefox desktop or Start menu shortcut.
    * Or use the Help menu item, click on '''Restart with Add-ons Disabled...''' while Firefox is running.
    ''To exit the Firefox Safe Mode, just close Firefox and wait a few seconds before using the Firefox shortcut (without the Shft key) to open it again.''
    '''''If it is good in the Firefox SafeMode''''', your problem is probably caused by an extension, and you need to figure out which one. <br />
    http://support.mozilla.com/en-US/kb/troubleshooting+extensions+and+themes
    ''When you figure out what is causing that, please let us know. It might help other user's who have that problem.''

  • How to run the servlet without getting message window?

    while running servlet,i got a message window that 'Do you want to save:val?'how to rectify this problem while running servlet.
    Actually i saved the servlet files as HTTP and Generic.java respectively.
    In web.xml file,the content is as follows
    <servlet>
    <init-param>
         <param-name>title</param-name>
         <param-value>GenericServlet Example</param-value>
         </init-param>
         <init-param>
    <param-name>heading</param-name>
    <param-value>Servlet Program</param-value>
    </init-param>
    <servlet-name>G</servlet-name>
    <servlet-class>Generic</servlet-class>
    </servlet>
    <servlet>
    <servlet-name>H</servlet-name>
    <servlet-class>HTTP</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>G</servlet-name>
    <url-pattern>/generic</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>H</servlet-name>
    <url-pattern>/http</url-pattern>
    </servlet-mapping>
    ======================================================
    The html file is as follows
    <html>
    <body>
    <form action="generic" method="get">
    User Name<input type=text name=t1><br>
    Password<input type=password name=t2><br>
    <input type="submit" value="GenericServlet Output">
    </form>
    <form action="val" method="get">
    User Name<input type=text name=t3><br>
    Password<input type=password name=t4><br>
    <input type="submit" value="HttpServlet Output">
    </form>
    </body>
    </html>
    ======================================================
    I executed the servlet as http://localhost:8080/stalin/sample.html
    and clicked the sumit button in the html page.
    During that time i got a problem but not getting the output.The problem is I got a message window?
    can anyone help me clarify my doubt plz

    That would occur if either the content type in the header is wrong (e.g. it is not text nor image, those content types with which the useragent used is associated), or if you have set content disposition in the header to attachment instead of inline.
    So, doublecheck the headers.

  • Maintain ViewObject state in non ADF servlet

    Hi,
    I am using a plain non ADF servlet to do few operations as explained in (Access Adf Binding Context in Servlet I am getting the page defs and iterators properly, but in an inconsistent state. When I get the current row off the viewObject from the iterator present in the page def, I am getting entirely different row rather that the one setup just before I invoke the servlet.....
    Can anyone please help me to find the way to get the proper state of the viewObject in the plain servlet.....

    AS long as you don't set up the right context in your servlet you can access the iterators, but you do so in an other context (like you were an other user). Follow http://www.oracle.com/technetwork/indexes/samplecode/jdeveloper-adf-sample-522118.html and look for the sample
    Sharing ADF context with a Servlet     2011-04-27     This code demonstrates how a Servlet within an application can share the same data control context (frame) as the underlying UI pages and Task Flows within that application. This approach is useful when you are creating integrated applications where servlets are leveraged to add functionality to the application such as AJAX calls or email generation.which shows how to pass the context to your servlet.
    Timo

  • Any way to invoke a servlet without using "action=" in HTML

    Hello,
    Is there any way to invoke a servlet without using "action=" attribute of Form tag in the HTML form.
    I.e. if I need to run the servlet from a hyperlink, how could it be possible?
    Or If I need to run a servlet from a "window.Open()" method using java script, how could it be possible?
    The error I am facing...
    HTTP Status 405 - HTTP method GET is not supported by this URL
    type Status report
    message HTTP method GET is not supported by this URL
    description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).
    Thanks,
    Sandeep

    Maybe your URL needs to use POST.

  • How to configure IIS webserver with weblogic so that I can invoke servlets without the .wlforward extension

    How to configure IIS webserver with weblogic so that I can
    invoke servlets without the .wlforward extension
    As per the documentation iisforward.dll is registered as a filter and .wlforward
    has also been
    included as a special file type. However this requires me to key-in ".wlforward"
    after my servlet name.
    What I want is something like this
    http://iis/MyServlet
    Please help me find a solution to this
    Thanks,
    Rishi

    I am able to invoke the servlet without the wlforward extension now.
    However, now I am required to add /weblogic before the servlet
    name otherwise it does not execute the pathtrim property.
    I have tried with the pathprepend thing also.
    Can we get rid of the /weblogic part also. I just want to execute
    my servlet as http://iis/myServlet.
    Your help in this regard is greatly appreciated...
    Thanks..
    "Rishi" <[email protected]> wrote:
    >
    Thanks for the reply Kumar.
    I did follow the instructions as given in the Weblogic documentation
    The documentation said to add iisforward.dll as a filter service
    and register .wlforward as a special
    file type to be handled by iisproxy.dll. For this,
    while configuring the IIS server in the Home Directory tab
    I added an extension ".wlforward" and the executable as
    iisproxy.dll. Is this the way it should have been done...
    I also modified the iisproxy.ini file as per the documentation.
    I have added the WLForwardPath property and set it to /weblogic.
    My server works fine when I give the url as
    http://iis/myServlet.wlforward
    but it does not work for
    http://iis/myServlet and this is the way i'd want it to work.
    Please tell me if I am missing something on the configuration part
    and if there is something special that needs to be done. I shall
    be grateful to you.
    Kumar Allamraju <[email protected]> wrote:
    http://e-docs.bea.com/wls/docs61/adminguide/isapi.html#101184
    Rishi wrote:
    How to configure IIS webserver with weblogic so that I can
    invoke servlets without the .wlforward extension
    As per the documentation iisforward.dll is registered as a filter
    and
    .wlforward
    has also been
    included as a special file type. However this requires me to key-in".wlforward"
    after my servlet name.
    What I want is something like this
    http://iis/MyServlet
    Please help me find a solution to this
    Thanks,
    Rishi

  • How to run java servlet without using Web.xml?

    How to run servlet without using Web.xml? From a book, I know that web.xml descriptor is optional, but the book doesn't tell us how to run java servelet without web.xm descriptor. So how to do that? Thanks a lot.

    How to run servlet without using Web.xml?But Tomcat now uses a web.xml for its global server-wide configuration.
    If you'd like to invoke a servlet with:
    http://host/servlet/ServletName
    you have to enable the invoker servlet.
    [from an HTML]
      <FORM METHOD="POST" ACTION="/servlet/HGrepSearchSJ">
    [from resin.conf of Resin Web Server 2.1.12]
      <!--
         - The "invoker" servlet invokes servlet classes from the URL.
         - /examples/basic/servlet/HelloServlet will start the HelloServlet
         - class.  In general, the invoker should only be used
         - for development, not on a deployment server, because it might
         - leave open security holes.
        -->
      <servlet-mapping url-pattern='/servlet/*' servlet-name='invoker'/>
    [from TOMCAT5.0.19/conf/web.xml, a global server-wide web.xml file]
      <!-- The "invoker" servlet, which executes anonymous servlet classes      -->
      <!-- that have not been defined in a web.xml file.  Traditionally, this   -->
      <!-- servlet is mapped to URL pattern "/servlet/*", but you can map it    -->
      <!-- to other patterns as well.  The extra path info portion of such a    -->
      <!-- request must be the fully qualified class name of a Java class that  -->
      <!-- implements Servlet (or extends HttpServlet), or the servlet name     -->
      <!-- of an existing servlet definition.     This servlet supports the     -->
      <!-- following initialization parameters (default values are in square    -->
      <!-- brackets):                                                           -->
      <!--                                                                      -->
      <!--   debug               Debugging detail level for messages logged     -->
      <!--                       by this servlet.  [0]                          -->
        <servlet>
            <servlet-name>invoker</servlet-name>
            <servlet-class>
              org.apache.catalina.servlets.InvokerServlet
            </servlet-class>
            <init-param>
                <param-name>debug</param-name>
                <param-value>0</param-value>
            </init-param>
            <load-on-startup>2</load-on-startup>
        </servlet>
    ---comment out below----------------------------------------------------------
        <!-- The mapping for the invoker servlet -->
    <!--
        <servlet-mapping>
            <servlet-name>invoker</servlet-name>
            <url-pattern>/servlet/*</url-pattern>
        </servlet-mapping>
    -->

  • Calling non standard servlet methods

    How can we call the non standard servlet methods like OPTIONS, HEAD, TRACE, etc.? Like to call the GET method of the servlet located on server xyz from some HTML page, we write the HTML form as follows :
    <form name="frmname" action="http://xyz.com/servlet/MyServlet" "method=get">
    So what should we write to call the other methods?
    Ankit.

    You can't do it directly from HTML, you need to open a connection over HTTP and then send the appropriate HTTP request. Not all web servers support these methods.

Maybe you are looking for

  • Opening .CR2 files in Photoshop CS2

    I am trying to see if it possible to open .CR2 RAW files in Photoshop CS2, which brings up the message " Could not complete our request because it is not eh right kind of document" I have tried updating the Raw Plug in line with Adobe's website and p

  • How to use cell editors in JTree?

    Hi, I have a component where I am placing JTable in JTree node.The table cells should be editable. I was unable to do that. I am giving code for 2 classes below,which I used. To test this compile the classes seperately. /**************************Tab

  • Changes in BSEG -  XOPVW

    HI Experts I want to CHECK (Tick) Open Item Management Check-mark in FS00 (Bank GL) for the entries which have already been entered J/v's . For that I found a table BSEG and the field is XOPVW. If I done this directly in Table will affect to any othe

  • PS CS4 Currupt Trial Download

    I have tried unsuccessfully to extract the trial download of PS CS4 extended. I have downloaded both files from adobe.com, but upon lauching the adobe extractor, the progress bar reaches 100% and displays the error "An error ocurred please check you

  • Safari randomly keeps crashing

    I've attached a report file for anyone who can understand it, happens seemingly randomly Process: Safari [624] Path: /Applications/Safari.app/Contents/MacOS/Safari Identifier: com.apple.Safari Version: 5.0 (6533.16) Build Info: WebBrowser-75331600~5